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

Re: [PATCH] urlmatch: do not allow passwords in URLs by default

From
Jeff King <peff@peff.net>
Date
Apr 30, 2021, 18:50 UTC
Message-ID
<YIxRbOh4j9eFxBF3@coredump.intra.peff.net>
In-Reply-To
<pull.945.git.1619807844627.gitgitgadget@gmail.com>
On Fri, Apr 30, 2021 at 06:37:24PM +0000, Derrick Stolee via GitGitGadget wrote:
Show 10 quoted lines
> From: Derrick Stolee <dstolee@microsoft.com>
> 
> Git allows URLs of the following pattern:
> 
>   https://username:password@domain/route
> 
> These URLs are then parsed to pull out the username and password for use
> when authenticating with the URL. Git is careful to anonymize the URL in
> status messages with transport_anonymize_url(), but it stores the URL as
> plaintext in the .git/config file. The password may leak in other ways.

I'm not really opposed to disallowing this entirely (with an escape hatch, as you have here), because it really is an awful practice for a lot of reasons. But another option we discussed previously was to allow the initial clone, but not store the password, which would result in the user being prompted for subsequent fetches:

  https://lore.kernel.org/git/20190519050724.GA26179@sigill.intra.peff.net/

I think that third patch there is just too gross. But with the first two, if you do have a credential helper configured, then:

  git clone https://user:pass@example.com/repo.git

would do what you want: clone with that user/pass, and then store the result in the credential helper.

Show 8 quoted lines
> @@ -191,6 +204,7 @@ static char *url_normalize_1(const char *url, struct url_info *out_info, char al
>  			}
>  			colon_ptr = strchr(norm.buf + scheme_len + 3, ':');
>  			if (colon_ptr) {
> +				die_if_username_password_not_allowed();
>  				passwd_off = (colon_ptr + 1) - norm.buf;
>  				passwd_len = norm.len - passwd_off;
>  				user_len = (passwd_off - 1) - (scheme_len + 3);

It's probably a bit nicer to just ignore the password, which will prompt the user. But then, it is nicer still to use it just the one time but not store it in the .git/config file. :)

-Peff
Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee
Message 2 of 10 in “urlmatch: do not allow passwords in URLs by default”
  1. urlmatch: do not allow passwords in URLs by defaultDerrick Stolee via GitGitGadget, Apr 30, 2021
  2. Jeff KingApr 30, 2021
  3. Derrick StoleeMay 3, 2021
  4. Jeff KingMay 3, 2021
  5. brian m. carlsonMay 1, 2021
  6. Christian CouderMay 1, 2021
  7. Junio C HamanoMay 3, 2021
  8. Ævar Arnfjörð BjarmasonMay 1, 2021
  9. Ævar Arnfjörð BjarmasonMay 1, 2021
  10. Robert CoupMay 3, 2021

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.