Skip to content

Commit 1ee9b1f

Browse files
committed
url: only allow @s in usernames for ssh urls
Enforce the RFC for other protocols; Google's questionable choices about malformed SSH protocols shouldn't impact our ability to properly parse HTTPS.
1 parent 373a3c9 commit 1ee9b1f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/util/net.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ static int url_parse_authority(
104104
const char **password_start, size_t *password_len,
105105
const char **host_start, size_t *host_len,
106106
const char **port_start, size_t *port_len,
107-
const char *authority_start, size_t len)
107+
const char *authority_start, size_t len,
108+
const char *scheme_start, size_t scheme_len)
108109
{
109110
const char *c, *hostport_end, *host_end = NULL,
110111
*userpass_end, *user_end = NULL;
@@ -194,6 +195,10 @@ static int url_parse_authority(
194195
return url_invalid("malformed hostname");
195196

196197
case USERPASS:
198+
if (*c == '@' &&
199+
strncasecmp(scheme_start, "ssh", scheme_len))
200+
return url_invalid("malformed hostname");
201+
197202
if (*c == ':') {
198203
*password_start = c + 1;
199204
*password_len = userpass_end - *password_start;
@@ -307,7 +312,8 @@ int git_net_url_parse(git_net_url *url, const char *given)
307312
&password_start,&password_len,
308313
&host_start, &host_len,
309314
&port_start, &port_len,
310-
authority_start, (c - authority_start))) < 0)
315+
authority_start, (c - authority_start),
316+
scheme_start, scheme_len)) < 0)
311317
goto done;
312318

313319
/* fall through */
@@ -365,7 +371,8 @@ int git_net_url_parse(git_net_url *url, const char *given)
365371
&password_start,&password_len,
366372
&host_start, &host_len,
367373
&port_start, &port_len,
368-
authority_start, (c - authority_start))) < 0)
374+
authority_start, (c - authority_start),
375+
scheme_start, scheme_len)) < 0)
369376
goto done;
370377
break;
371378
case PATH_START:

tests/util/url/parse.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ void test_url_parse__empty_path_with_empty_authority(void)
749749
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
750750
}
751751

752+
void test_url_parse__http_follows_the_rfc(void)
753+
{
754+
cl_git_fail(git_net_url_parse(&conndata, "https://[email protected]@source.developers.google.com:4433/p/my-project/r/my-repository"));
755+
}
756+
752757
void test_url_parse__ssh_from_terrible_google_rfc_violating_products(void)
753758
{
754759
cl_git_pass(git_net_url_parse(&conndata, "ssh://[email protected]@source.developers.google.com:2022/p/my-project/r/my-repository"));

0 commit comments

Comments
 (0)