git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: bw/transport-protocol-policy

From
Jeff King <peff@peff.net>
Date
Dec 1, 2016, 19:20 UTC
Message-ID
<20161201192055.44mtvtacyhpbqbqu@sigill.intra.peff.net>
In-Reply-To
<20161201181415.GA54082@google.com>
On Thu, Dec 01, 2016 at 10:14:15AM -0800, Brandon Williams wrote:
Show 38 quoted lines
> >   1. The new policy config lets you say "only allow this protocol when
> >      the user specifies it". But when http.c calls is_transport_allowed(),
> >      the latter has no idea that we are asking it about potential
> >      redirects (which obviously do _not_ come from the user), and would
> >      erroneously allow them.
> > 
> >      I think this needs fixed before the topic is merged. It's not a
> >      regression, as it only comes into play if you use the new policy
> >      config. But it is a minor security hole in the new feature.
> 
> I agree and it should be an easy fix.  We can just add a parameter like
> so:
> 
> diff --git a/transport.c b/transport.c
> index 2c0ec76..d38d50f 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -723,7 +723,7 @@ static enum protocol_allow_config get_protocol_config(const char *type)
>  	return PROTOCOL_ALLOW_USER_ONLY;
>  }
>  
> -int is_transport_allowed(const char *type)
> +int is_transport_allowed(const char *type, int redirect)
>  {
>  	const struct string_list *whitelist = protocol_whitelist();
>  	if (whitelist)
> @@ -735,7 +735,7 @@ int is_transport_allowed(const char *type)
>  	case PROTOCOL_ALLOW_NEVER:
>  		return 0;
>  	case PROTOCOL_ALLOW_USER_ONLY:
> -		return git_env_bool("GIT_PROTOCOL_FROM_USER", 1);
> +		return git_env_bool("GIT_PROTOCOL_FROM_USER", !redirect);
>  	}
>  
>  	die("BUG: invalid protocol_allow_config type");
> 
> That way the libcurl code can say it is asking if it is ok to redirect
> to that protocol.

I wouldn't expect anyone to ever set GIT_PROTOCOL_FROM_USER=1, but it does behave in a funny way here, overriding the "redirect" flag. I think we'd want something more like:

  if (redirect < 0)
	redirect = git_env_bool("GIT_PROTOCOL_FROM_USER", 1);
and then pass in "-1" from transport_check_allowed().

I think that's sufficient to fix the topic as-is. However, the http redirect series adds an extra complication, because with http-alternates we resolve some of the redirects ourselves. So in those cases we'd want to restrict CURLOPT_PROTOCOLS as if they were redirects. We may need to set up two CURLOPT values: ones from the user and ones from redirects, and then feed them to CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS as appropriate depending on the request context.

> We should switch to warning all the time since this series adds in
> default whitelisted/blacklisted protocols anyways.
Yeah, good point. As a bonus it makes the code simpler.
-Peff
Previous: Brandon WilliamsNext: Brandon Williams
Message 31 of 34 in “What's cooking in git.git (Nov 2016, #06; Mon, 28)”
  1. Junio C HamanoNov 29, 2016
  2. Brandon WilliamsNov 29, 2016
  3. Jeff KingNov 29, 2016
  4. Jeff KingNov 29, 2016
  5. Brandon WilliamsNov 30, 2016
  6. Brandon WilliamsNov 30, 2016
  7. Jeff KingNov 30, 2016
  8. Jeff KingNov 30, 2016
  9. Brandon WilliamsNov 30, 2016
  10. Jeff KingNov 30, 2016
  11. Brandon WilliamsNov 30, 2016
  12. Jeff KingNov 30, 2016
  13. Jeff KingDec 1, 2016
  14. Brandon WilliamsDec 1, 2016
  15. Stefan BellerDec 1, 2016
  16. Brandon WilliamsDec 1, 2016
  17. Jeff KingDec 1, 2016
  18. Brandon WilliamsDec 1, 2016
  19. Stefan BellerNov 30, 2016
  20. Johannes SixtDec 1, 2016
  21. Jeff KingDec 1, 2016
  22. Jeff KingNov 29, 2016
  23. Junio C HamanoNov 29, 2016
  24. Jeff KingNov 29, 2016
  25. Stefan BellerNov 29, 2016
  26. Junio C HamanoNov 29, 2016
  27. Stefan BellerNov 29, 2016
  28. Stefan BellerNov 30, 2016
  29. bw/transport-protocol-policyJeff King, Dec 1, 2016
  30. Brandon WilliamsDec 1, 2016
  31. Jeff KingDec 1, 2016
  32. Brandon WilliamsDec 1, 2016
  33. Jeff KingDec 1, 2016
  34. Brandon WilliamsDec 1, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.