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

Re: [PATCH] urlmatch: create fetch.credentialsInUrl config

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 24, 2022, 21:01 UTC
Message-ID
<220524.86ilpuvcqh.gmgdl@evledraar.gmail.com>
In-Reply-To
<0dc38d46-7c5a-5532-c843-ef3c8b6cfa28@github.com>
On Tue, May 24 2022, Derrick Stolee wrote:
Show 26 quoted lines
> On 5/24/2022 4:18 AM, Ævar Arnfjörð Bjarmason wrote:
>> 
>> On Mon, May 23 2022, Derrick Stolee via GitGitGadget wrote:
>> 
>>> +fetch.credentialsInUrl::
>>> +	A URL can contain plaintext credentials in the form
>>> +	`protocol://<user>:<password>@domain/path`. Using such URLs is not
>>> +	recommended as it exposes the password in multiple ways. The
>>> +	`fetch.credentialsInUrl` option provides instruction for how Git
>>> +	should react to seeing such a URL, with these values:
>> 
>> Re the previous discussion about this (in the v1 patch /
>> https://lore.kernel.org/git/pull.945.git.1619807844627.gitgitgadget@gmail.com/):
>> In what ways?
>> 
>> That's rhetorical, the point being: Let's adjust this documentation to
>> discuss exactly why this is thought to be bad, what we're mitigating for
>> the user etc., are there situations where running git like this is
>> perfectly fine & not thought to be an issue? E.g. no password manager
>> and you trust your FS permission? Let's cover those cases too.
>
> This documentation is not the proper place to tell the user "do this
> and you can trust your plaintext creds in the filesystem" because that
> is asking for problems. I'd rather leave a vague warning and let users
> go against the recommended behavior only after they have done sufficient
> work to be confident in taking on that risk.

I don't mean that we need to cover the full divergent views on different approaches to local password management, but not leave the user hanging with the rather scary "exposes the password in multiple ways".

I.e. if I read that for any software whose implementation I wasn't very familiar with I'd be very afraid, and in git's case for no reason.

Does in mean that git has some scary git-specific feature that would expose it. perhaps there's a local log that's unsecured where attempted URLs are logged, or perhaps we send the raw requested URL to the server so it can suggest alternatives for us. We do neither, but even a generally knowledgeable user won't know that about git in particular.

Whereas what I think you actually mean and are targeting here is better explained by:

    Git is careful to avoid exposing passwords in URLs on its own,
    e.g. they won't be logged in trace2 logs. This setting is intended
    for those who'd like to discourage (warn) or enforce (die) the use
    of the password helper infrastructure over hardcoded passwords.

All of which I *think* is correct, but maybe I've missed something you know about, as that "in multiple ways" is doing a lot of work.

I also wonder if this wouldn't be even more useful if we took some lessons from ssh's book. I.e. per "git config -l --show-origin" we know the original of all config. We could be even more useful (and more aggressive about warning about) cases where we have passwords in config files that we detect don't have restrictive permissions, as OpenSSH does with your private key.

Ditto perhaps when the origin is "command line", as we do nothing to hide that from the process list on shared systems (and that would be racy whatever we did).

Show 18 quoted lines
>>> ++
>>> +* `ignore` (default): Git will proceed with its activity without warning.
>>> +* `warn`: Git will write a warning message to `stderr` when parsing a URL
>>> +  with a plaintext credential.
>>> +* `die`: Git will write a failure message to `stderr` when parsing a URL
>>> +  with a plaintext credential.
>> 
>> You're implementing this with strcasecmp, so we also support DIE, DiE
>> etc. Let's not do that and use strcmp() instead.
>
> Sure.
>
>>> +static void detected_credentials_in_url(const char *url, size_t scheme_len)
>>> +{
>> 
>> Just generally: This is only 
>
> Did you intend to say more here?
Probably, but if I did I forgot about it, by now. Sorry.
Show 13 quoted lines
>>> +	char *value = NULL;
>> 
>> This init to NULL should be removedd, as we....
>> 
>>> +	const char *at_ptr;
>>> +	const char *colon_ptr;
>>> +	struct strbuf anonymized = STRBUF_INIT;
>> 
>> nit: Just call this "sb"? The's at least one line below over 79
>> characters that's within the bounds with a shorter variable name, and in
>> this case it's obvious what we're doing here...
>
> I will not change this name to be less descriptive.

Sure, just a suggestion. The other way is to just re-wrap that one line... :)

In the end I don't care, "just a nit", but just as one datapoint from reading this code: I find this varibale name in particular to be the polar opposite of descriptive, we're explicitly not anonymizing the URL in this function, since we're not stripping the username part.

Wouldn't descriptive be something more like uri_redacted_password or uri_no_password in this case?

Show 9 quoted lines
>>> +
>>> +	/* "ignore" is the default behavior. */
>>> +	if (git_config_get_string("fetch.credentialsinurl", &value) ||
>> 
>> ...initialize it here, and if we didn't the compiler would have a chance
>> to spot that if we were getting it wrong.
>
> We do not necessarily initialize it here. The compiler doesn't notice
> it and the free(value) below segfaults.
Yes, sorry I meant in combination with the *_tmp() variant below...
Show 26 quoted lines
>>> +	    !strcasecmp("ignore", value))
>>> +		goto cleanup;
>>> +
>>> +	at_ptr = strchr(url, '@');
>>> +	colon_ptr = strchr(url + scheme_len + 3, ':');
>>> +
>>> +	if (!colon_ptr)
>>> +		BUG("failed to find colon in url '%s' with scheme_len %"PRIuMAX,
>>> +		    url, (uintmax_t) scheme_len);
>>> +
>>> +	/* Include everything including the colon. */
>>> +	colon_ptr++;
>>> +	strbuf_add(&anonymized, url, colon_ptr - url);
>>> +
>>> +	while (colon_ptr < at_ptr) {
>>> +		strbuf_addch(&anonymized, '*');
>>> +		colon_ptr++;
>>> +	}
>> 
>> Could we share code with 88e9b1e3fcb (fetch-pack: redact packfile urls
>> in traces, 2021-11-10), or for consistency note this as <redacted>
>> instead of stripping it out, as we do for that related URL-part
>> redaction?
>
> I'm happy to replace the asterisks with <redacted>. Otherwise, I don't
> see anything we can do to share across these methods.

Yes, I just meant adding a "<redacted>". I briefly looked at whether it made sense to share the implementation, but I think probably not.

I didn't think of this at the time but your implementation also leaks the length of the password, which <redacted> will solve in any case.

Just for the implementation: It's slightly more wasteful, but in this case we don't care about performance, so perhaps a strbuf_splice() variant is easier here? I.e. add the full URL, find : and @, then strbuf_splice() it. It gets rid of much of the pointer juggling here & adding things incrementally.

> Specifically,
> the test in that commit seems to indicate that the redacted portion is
> only the packfile name (the $HTTPD_URL is not filtered).

By HTTPD_URL it means "the path", i.e. it's the equivalent of stripping CURLUPART_{PATH,QUERY,FRAGMENT}.

So a hypothetical shared implementation would just be a matter of searching for the '/' once we're past the (optional) '@', but better to leave it for now.

Show 15 quoted lines
>>> +	strbuf_addstr(&anonymized, at_ptr);
>> 
>> Maybe not worth it, but I wondered if we couldn't just use curl for
>> this, turns out it has an API for it:
>> https://curl.se/libcurl/c/libcurl-url.html
>> 
>> But it's too new for us to rely on unconditionally, but we could add
>> that to git-curl-compat.h and ifdef it, then we'll eventually drop this
>> custom code for ryling on the well-tested library.
>> 
>> I think doing that would be worth it, to show future authors that curl
>> can do this, so maybe we can start relying on that eventually...
>
> Since we can't rely on it, I'll leave that to another (you, perhaps?)
> to do that ifdef work. I don't think it's worth it right now.
Yeah, probably not.
Show 13 quoted lines
>>> +	if (!strcasecmp("warn", value))
>>> +		warning(_("URL '%s' uses plaintext credentials"), anonymized.buf);
>>> +	if (!strcasecmp("die", value))
>>> +		die(_("URL '%s' uses plaintext credentials"), anonymized.buf);
>>> +
>>> +cleanup:
>>> +	free(value);
>> 
>> I think you can also just use git_config_get_string_tmp() here and avoid
>> the alloc/free. That's safe as long as you're not calling other config
>> API in-between, which you're not.
>
> OK. And that also avoids the need for initialization you mentioned.
*nod*
Previous: Derrick StoleeNext: Derrick Stolee
Message 11 of 40 in “urlmatch: create fetch.credentialsInUrl config”
  1. urlmatch: create fetch.credentialsInUrl configDerrick Stolee via GitGitGadget, May 23, 2022
  2. Junio C HamanoMay 23, 2022
  3. Derrick StoleeMay 23, 2022
  4. Junio C HamanoMay 23, 2022
  5. Johannes SchindelinMay 24, 2022
  6. Derrick StoleeMay 24, 2022
  7. Junio C HamanoMay 23, 2022
  8. Johannes SchindelinMay 24, 2022
  9. Ævar Arnfjörð BjarmasonMay 24, 2022
  10. Derrick StoleeMay 24, 2022
  11. Ævar Arnfjörð BjarmasonMay 24, 2022
  12. Derrick StoleeMay 25, 2022
  13. Johannes SchindelinMay 24, 2022
  14. Derrick StoleeMay 24, 2022
  15. urlmatch: create fetch.credentialsInUrl configDerrick Stolee via GitGitGadget, May 27, 2022
  16. Ævar Arnfjörð BjarmasonMay 27, 2022
  17. Derrick StoleeMay 27, 2022
  18. Junio C HamanoMay 27, 2022
  19. Junio C HamanoMay 27, 2022
  20. Junio C HamanoMay 30, 2022
  21. Derrick StoleeMay 31, 2022
  22. 0/2 fetch: create fetch.credentialsInUrl configDerrick Stolee via GitGitGadget, Jun 1, 2022
  23. 1/2 remote: create fetch.credentialsInUrl configDerrick Stolee via GitGitGadget, Jun 1, 2022
  24. Ævar Arnfjörð BjarmasonJun 1, 2022
  25. Derrick StoleeJun 2, 2022
  26. 2/2 usage: add warn_once() helper for repeated warningsDerrick Stolee via GitGitGadget, Jun 1, 2022
  27. Ævar Arnfjörð BjarmasonJun 1, 2022
  28. Derrick StoleeJun 1, 2022
  29. Ævar Arnfjörð BjarmasonJun 1, 2022
  30. Derrick StoleeJun 2, 2022
  31. Junio C HamanoJun 1, 2022
  32. Derrick StoleeJun 2, 2022
  33. Junio C HamanoJun 2, 2022
  34. Junio C HamanoJun 1, 2022
  35. remote: create fetch.credentialsInUrl configDerrick Stolee via GitGitGadget, Jun 2, 2022
  36. Junio C HamanoJun 2, 2022
  37. Derrick StoleeJun 3, 2022
  38. Junio C HamanoJun 6, 2022
  39. remote: create fetch.credentialsInUrl configDerrick Stolee via GitGitGadget, Jun 6, 2022
  40. Junio C HamanoJun 6, 2022

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.