Description
The Git credential protocol is text-based over standard input/output, and consists of a series of lines of key-value pairs in the format key=value
. Git's documentation restricts the use of the NUL (\0
) character and newlines to form part of the keys1 or values.
When Git reads from standard input, it considers both LF and CRLF2 as newline characters for the credential protocol by virtue of calling strbuf_getline
that calls to strbuf_getdelim_strip_crlf
. Git also validates that a newline is not present in the value by checking for the presence of the line-feed character (LF, \n
), and errors if this is the case. This captures both LF and CRLF-type newlines.
Git Credential Manager uses the .NET standard library StreamReader
class to read the standard input stream line-by-line and parse the key=value
credential protocol format. The implementation of the ReadLineAsync
method considers LF, CRLF, and CR as valid line endings. This is means that .NET considers a single CR as a valid newline character, whereas Git does not.
This mismatch of newline treatment between Git and GCM means that an attacker can craft a malicious remote URL such as:
https://\rhost=targethost@badhost
..which will be interpreted by Git as:
protocol=https
host=badhost
username=\rhost=targethost
This will instead be parsed by GCM as if the following has been passed by Git:
protocol=https
host=badhost
username=
host=targethost
This results in the host
field being resolved to the targethost
value. GCM will then return a credential for targethost
to Git, which will then send this credential to the badhost
host.
Impact
When a user clones or otherwise interacts3 with a malicious repository that requires authentication, the attacker can capture credentials for another Git remote. The attack is also heightened when cloning from repositories with submodules when using the --recursive
clone option as the user is not able to inspect the submodule remote URLs beforehand.
Patches
git-ecosystem/git-credential-manager@749e287...99e2f7f
Workarounds
Only interacting with trusted remote repositories, and do not clone with --recursive
to allow inspection of any submodule URLs before cloning those submodules.
Fixed versions
This issue is fixed as of version 2.6.1.
References
Description
The Git credential protocol is text-based over standard input/output, and consists of a series of lines of key-value pairs in the format
key=value
. Git's documentation restricts the use of the NUL (\0
) character and newlines to form part of the keys1 or values.When Git reads from standard input, it considers both LF and CRLF2 as newline characters for the credential protocol by virtue of calling
strbuf_getline
that calls tostrbuf_getdelim_strip_crlf
. Git also validates that a newline is not present in the value by checking for the presence of the line-feed character (LF,\n
), and errors if this is the case. This captures both LF and CRLF-type newlines.Git Credential Manager uses the .NET standard library
StreamReader
class to read the standard input stream line-by-line and parse thekey=value
credential protocol format. The implementation of theReadLineAsync
method considers LF, CRLF, and CR as valid line endings. This is means that .NET considers a single CR as a valid newline character, whereas Git does not.This mismatch of newline treatment between Git and GCM means that an attacker can craft a malicious remote URL such as:
..which will be interpreted by Git as:
This will instead be parsed by GCM as if the following has been passed by Git:
This results in the
host
field being resolved to thetargethost
value. GCM will then return a credential fortargethost
to Git, which will then send this credential to thebadhost
host.Impact
When a user clones or otherwise interacts3 with a malicious repository that requires authentication, the attacker can capture credentials for another Git remote. The attack is also heightened when cloning from repositories with submodules when using the
--recursive
clone option as the user is not able to inspect the submodule remote URLs beforehand.Patches
git-ecosystem/git-credential-manager@749e287...99e2f7f
Workarounds
Only interacting with trusted remote repositories, and do not clone with
--recursive
to allow inspection of any submodule URLs before cloning those submodules.Fixed versions
This issue is fixed as of version 2.6.1.
References
Footnotes
The
=
character is also forbidden to form part of the key. ↩Carriage-return character (CR,
\r
), followed by a line-feed character. ↩Any remote operation such as
fetch
,ls-remote
, etc. ↩