]> git.ipfire.org Git - thirdparty/git.git/commit
credential: optionally allow partial URLs in credential_from_url_gently()
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 24 Apr 2020 22:35:48 +0000 (22:35 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Apr 2020 22:53:41 +0000 (15:53 -0700)
commitf52b0cb4184362b2f88ebbf9ea20016914ce469d
tree7ef5cb5d34f1ba4b7a049cca796fe257683b57ba
parentaf6b65d45ef179ed52087e80cb089f6b2349f4ec
credential: optionally allow partial URLs in credential_from_url_gently()

Prior to the fixes for CVE-2020-11008, we were _very_ lenient in what we
required from a URL in order to parse it into a `struct credential`.
That led to serious vulnerabilities.

There was one call site, though, that really needed that leniency: when
parsing config settings a la `credential.dev.azure.com.useHTTPPath`.
Settings like this might be desired when users want to use, say, a given
user name on a given host, regardless of the protocol to be used.

In preparation for fixing that bug, let's refactor the code to
optionally allow for partial URLs. For the moment, this functionality is
only exposed via the now-renamed function `credential_from_url_1()`, but
it is not used. The intention is to make it easier to verify that this
commit does not change the existing behavior unless explicitly allowing
for partial URLs.

Please note that this patch does more than just reinstating a way to
imitate the behavior before those CVE-2020-11008 fixes: Before that, we
would simply ignore URLs without a protocol. In other words,
misleadingly, the following setting would be applied to _all_ URLs:

[credential "example.com"]
username = that-me

The obvious intention is to match the host name only. With this patch,
we allow precisely that: when parsing the URL with non-zero
`allow_partial_url`, we do not simply return success if there was no
protocol, but we simply leave the protocol unset and continue parsing
the URL.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
credential.c