Re: transfer.credentialsInUrl should warn about personal access tokens in user field #leftoverbits

5 messages, 5 authors, 2025-01-18 · open the first message on its own page

Re: transfer.credentialsInUrl should warn about personal access tokens in user field #leftoverbits

From: Junio C Hamano <hidden>
Date: 2025-01-10 21:32:46

M Hickford [off-list ref] writes:
It would be neat to warn similarly if the user includes a personal access token in the *user* field of the remote URL:

    git clone https://<pat>@github.com/...

This is a popular practice according to StackOverflow
https://stackoverflow.com/a/70320541/284795 (800k views).

GitHub personal access tokens are easily recognised by their
prefixes "ghp_" and "github_pat_"
Curious.  I do not think we have *any* code to special case such a
"token", so to Git itself, https://<pat>@github.com/... should look
as it (assuming <pat> does not have any colon in it) is trying to
access the site with <pat> as the username.

How do we _know_ that this request with <pat> do not need a
password?  I ask because I'd prefer not to see us hardcoding any
hosting-site specific heuristics in the code, and these users
apparently are doing fine without any such hardcoding.  If we can
reuse the mechanism that is letting them do so when deciding if we
should warn, it would be great.

Are users expected to configure their credential helpers know that
it is a <pat> (perhaps with authtype=Bearer)?

Sorry for not giving any answer and piling more questions on top.

Re: transfer.credentialsInUrl should warn about personal access tokens in user field #leftoverbits

From: brian m. carlson <hidden>
Date: 2025-01-10 22:06:20

On 2025-01-10 at 21:32:44, Junio C Hamano wrote:
M Hickford [off-list ref] writes:
quoted
It would be neat to warn similarly if the user includes a personal access token in the *user* field of the remote URL:

    git clone https://<pat>@github.com/...

This is a popular practice according to StackOverflow
https://stackoverflow.com/a/70320541/284795 (800k views).

GitHub personal access tokens are easily recognised by their
prefixes "ghp_" and "github_pat_"
There are also other prefixes as well.
Curious.  I do not think we have *any* code to special case such a
"token", so to Git itself, https://<pat>@github.com/... should look
as it (assuming <pat> does not have any colon in it) is trying to
access the site with <pat> as the username.
That is accurate.  GitHub has accepted a token in the username for some
time (at least since 2019, and probably longer) for reasons which are
unknown to me.  From a security perspective, I would recommend users not
do so, since many tools log the username and not the password[0], but
it's almost certainly too late to change it now.  I can mention it, but
even if there was a decision to drop that, it would require a long
deprecation period.
How do we _know_ that this request with <pat> do not need a
password?  I ask because I'd prefer not to see us hardcoding any
hosting-site specific heuristics in the code, and these users
apparently are doing fine without any such hardcoding.  If we can
reuse the mechanism that is letting them do so when deciding if we
should warn, it would be great.
I don't think in general we can know whether a credential is just a
plain username or a token without trying to guess based on the content.
For instance, before `http.emptyAuth`, it was common if one was using
Kerberos to put one's username in the URL because that triggered libcurl
to do authentication, whereas it would not if no credentials were
specified.  I still have that configured, and I bet a lot of others do
as well.

It's also common for people with both work and personal accounts on a
site to put the username in the URL so that the correct credentials are
looked up in the credential helper.  And all of that is fine and secure
since there are no actual secrets in the username in those cases.

So there are lots of legitimate reasons to place only a username there,
and we'd only be able to know if it's actually a token by hard-coding
patterns.  I would recommend that we not do that, since I can't
guarantee that the list of patterns won't expand in the future (it
already has before), and there are still some older hex-only patterns
which may be in use and which are much less obvious.
Are users expected to configure their credential helpers know that
it is a <pat> (perhaps with authtype=Bearer)?
No, this is Basic auth.  It's just that GitHub will look at either the
username or password field for the token.

[0] The two systems at GitHub which handle these credentials (the Git
service and the Git auth service) are designed to recognize tokens in
the username and obscure them instead of logging them.  Pretty much no
other tools on the Internet do that, though.
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA

RE: transfer.credentialsInUrl should warn about personal access tokens in user field #leftoverbits

From: <hidden>
Date: 2025-01-10 22:10:30

On January 10, 2025 4:33 PM, Junio C Hamano wrote:
M Hickford [off-list ref] writes:
quoted
It would be neat to warn similarly if the user includes a personal access token in
the *user* field of the remote URL:
quoted
    git clone https://<pat>@github.com/...

This is a popular practice according to StackOverflow
https://stackoverflow.com/a/70320541/284795 (800k views).

GitHub personal access tokens are easily recognised by their prefixes
"ghp_" and "github_pat_"
Curious.  I do not think we have *any* code to special case such a "token", so to Git
itself, https://<pat>@github.com/... should look as it (assuming <pat> does not
have any colon in it) is trying to access the site with <pat> as the username.

How do we _know_ that this request with <pat> do not need a password?  I ask
because I'd prefer not to see us hardcoding any hosting-site specific heuristics in the
code, and these users apparently are doing fine without any such hardcoding.  If we
can reuse the mechanism that is letting them do so when deciding if we should
warn, it would be great.

Are users expected to configure their credential helpers know that it is a <pat>
(perhaps with authtype=Bearer)?
This is why I implemented my own credential layer - sorry, cannot share,
but can describe if asked (maybe at a Git Merge? 😉 ). Git should not need to
know about GitHub specific access methods for HTTPS, where PAT is required
for git push. There is no password for PAT use, which makes it highly insecure
if persisted on disk - I do not know why GitHub went down that path, I guess
they did not want any potential CVEs associated with SSH-like passphrases.
PAT became a real annoyance for my community, so I had to do something quick
and adding my own credential manager seemed expedient (and works pretty
well - but if someone wants to do this, they must be very careful managing
access to the cached PAT's memory use). The primary use case in my situation
is not actually git push, but the creation of Pull Requests on GitHub from
scripts or a CLI since NonStop has no GUI adapter to access their website.
Sorry for not giving any answer and piling more questions on top.

RE: transfer.credentialsInUrl should warn about personal access tokens in user field #leftoverbits

From: Randall Becker <hidden>
Date: 2025-01-10 23:36:41

My email rsbecker@nexbridge.com is being blocked by gmail, so I cannot get to Derek.
Anyone know why? Have I been a bad boy somehow? Resending via another account.

On January 10, 2025 4:33 PM, Junio C Hamano wrote:
M Hickford [off-list ref] writes:
quoted
It would be neat to warn similarly if the user includes a personal access token in
the *user* field of the remote URL:
quoted
    git clone https://<pat>@github.com/...

This is a popular practice according to StackOverflow
https://stackoverflow.com/a/70320541/284795 (800k views).

GitHub personal access tokens are easily recognised by their prefixes
"ghp_" and "github_pat_"
Curious.  I do not think we have *any* code to special case such a "token", so to Git
itself, https://<pat>@github.com/... should look as it (assuming <pat> does not
have any colon in it) is trying to access the site with <pat> as the username.

How do we _know_ that this request with <pat> do not need a password?  I ask
because I'd prefer not to see us hardcoding any hosting-site specific heuristics in the
code, and these users apparently are doing fine without any such hardcoding.  If we
can reuse the mechanism that is letting them do so when deciding if we should
warn, it would be great.

Are users expected to configure their credential helpers know that it is a <pat>
(perhaps with authtype=Bearer)?
This is why I implemented my own credential layer - sorry, cannot share,
but can describe if asked (maybe at a Git Merge? 😉 ). Git should not need to
know about GitHub specific access methods for HTTPS, where PAT is required
for git push. There is no password for PAT use, which makes it highly insecure
if persisted on disk - I do not know why GitHub went down that path, I guess
they did not want any potential CVEs associated with SSH-like passphrases.
PAT became a real annoyance for my community, so I had to do something quick
and adding my own credential manager seemed expedient (and works pretty
well - but if someone wants to do this, they must be very careful managing
access to the cached PAT's memory use). The primary use case in my situation
is not actually git push, but the creation of Pull Requests on GitHub from
scripts or a CLI since NonStop has no GUI adapter to access their website.
Sorry for not giving any answer and piling more questions on top.

Re: transfer.credentialsInUrl should warn about personal access tokens in user field #leftoverbits

From: M Hickford <hidden>
Date: 2025-01-18 20:33:08

On 2025-01-10 22:06, brian m. carlson wrote:
No, this is Basic auth.  It's just that GitHub will look at either the
username or password field for the token.
Thanks Brian and Junio for the discussion. I understand your aversion to introducing GitHub-specific PAT detection logic.

The better solution would be for GitHub to stop accepting PAT in the username field. Hopefully that will happen one day. It's undocumented,
so its usage ought to diminish.

To speed that along, I've edited the offending StackOverflow answer https://stackoverflow.com/a/70320541/284795

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help