Skip to content

Commit 3be4cf0

Browse files
peffgitster
authored andcommitted
connect: reject dashed arguments for proxy commands
If you have a GIT_PROXY_COMMAND configured, we will run it with the host/port on the command-line. If a URL contains a mischievous host like "--foo", we don't know how the proxy command may handle it. It's likely to break, but it may also do something dangerous and unwanted (technically it could even do something useful, but that seems unlikely). We should err on the side of caution and reject this before we even run the command. The hostname check matches the one we do in a similar circumstance for ssh. The port check is not present for ssh, but there it's not necessary because the syntax is "-p <port>", and there's no ambiguity on the parsing side. It's not clear whether you can actually get a negative port to the proxy here or not. Doing: git fetch git://remote:-1234/repo.git keeps the "-1234" as part of the hostname, with the default port of 9418. But it's a good idea to keep this check close to the point of running the command to make it clear that there's no way to circumvent it (and at worst it serves as a belt-and-suspenders check). Signed-off-by: Jeff King <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2491f77 commit 3be4cf0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

connect.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
553553

554554
get_host_and_port(&host, &port);
555555

556+
if (looks_like_command_line_option(host))
557+
die("strange hostname '%s' blocked", host);
558+
if (looks_like_command_line_option(port))
559+
die("strange port '%s' blocked", port);
560+
556561
proxy = xmalloc(sizeof(*proxy));
557562
child_process_init(proxy);
558563
argv_array_push(&proxy->args, git_proxy_command);

t/t5532-fetch-proxy.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ test_expect_success 'fetch through proxy works' '
4040
test_cmp expect actual
4141
'
4242

43+
test_expect_success 'funny hostnames are rejected before running proxy' '
44+
test_must_fail git fetch git://-remote/repo.git 2>stderr &&
45+
! grep "proxying for" stderr
46+
'
47+
4348
test_done

0 commit comments

Comments
 (0)