credential: optionally allow partial URLs in credential_from_url_gently()
commit6828e5972b82f474cc14ca9cb9e01e897f205f4c
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 24 Apr 2020 11:49:51 +0000 (24 11:49 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Apr 2020 21:15:58 +0000 (24 14:15 -0700)
tree38eb01069759ad0d793cc1af5237781b0d3aa3bf
parent21920cbd9af489763a62ebb81e1ca188354f833e
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>
Reviewed-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
credential.c