summaryrefslogtreecommitdiff
path: root/credential.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2020-04-19 03:54:13 (GMT)
committerJonathan Nieder <jrnieder@gmail.com>2020-04-19 23:10:58 (GMT)
commitc44088ecc4b0722636e0a305f9608d3047197282 (patch)
treea971e4a0899abe18ccac120fb345502aaf628722 /credential.c
parentfe29a9b7b0236d3d45c254965580d6aff7fa8504 (diff)
downloadgit-c44088ecc4b0722636e0a305f9608d3047197282.zip
git-c44088ecc4b0722636e0a305f9608d3047197282.tar.gz
git-c44088ecc4b0722636e0a305f9608d3047197282.tar.bz2
credential: treat URL without scheme as invalid
libcurl permits making requests without a URL scheme specified. In this case, it guesses the URL from the hostname, so I can run git ls-remote http::ftp.example.com/path/to/repo and it would make an FTP request. Any user intentionally using such a URL is likely to have made a typo. Unfortunately, credential_from_url is not able to determine the host and protocol in order to determine appropriate credentials to send, and until "credential: refuse to operate when missing host or protocol", this resulted in another host's credentials being leaked to the named host. Teach credential_from_url_gently to consider such a URL to be invalid so that fsck can detect and block gitmodules files with such URLs, allowing server operators to avoid serving them to downstream users running older versions of Git. This also means that when such URLs are passed on the command line, Git will print a clearer error so affected users can switch to the simpler URL that explicitly specifies the host and protocol they intend. One subtlety: .gitmodules files can contain relative URLs, representing a URL relative to the URL they were cloned from. The relative URL resolver used for .gitmodules can follow ".." components out of the path part and past the host part of a URL, meaning that such a relative URL can be used to traverse from a https://foo.example.com/innocent superproject to a https::attacker.example.com/exploit submodule. Fortunately a leading ':' in the first path component after a series of leading './' and '../' components is unlikely to show up in other contexts, so we can catch this by detecting that pattern. Reported-by: Jeff King <peff@peff.net> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Jeff King <peff@peff.net>
Diffstat (limited to 'credential.c')
-rw-r--r--credential.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/credential.c b/credential.c
index 7d43359..aedb645 100644
--- a/credential.c
+++ b/credential.c
@@ -357,8 +357,11 @@ int credential_from_url_gently(struct credential *c, const char *url,
* (3) proto://<user>:<pass>@<host>/...
*/
proto_end = strstr(url, "://");
- if (!proto_end)
- return 0;
+ if (!proto_end) {
+ if (!quiet)
+ warning(_("url has no scheme: %s"), url);
+ return -1;
+ }
cp = proto_end + 3;
at = strchr(cp, '@');
colon = strchr(cp, ':');