Skip to content

Commit

Permalink
http: limit redirection depth
Browse files Browse the repository at this point in the history
By default, libcurl will follow circular http redirects
forever. Let's put a cap on this so that somebody who can
trigger an automated fetch of an arbitrary repository (e.g.,
for CI) cannot convince git to loop infinitely.

The value chosen is 20, which is the same default that
Firefox uses.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Blake Burkhart authored and Junio C Hamano committed Sep 25, 2015
1 parent f4113ca commit b258116
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ static CURL *get_curl_handle(void)
}

curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20);
#if LIBCURL_VERSION_NUM >= 0x071301
curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
#elif LIBCURL_VERSION_NUM >= 0x071101
Expand Down
3 changes: 3 additions & 0 deletions t/lib-httpd/apache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ RewriteRule ^/smart-redir-auth/(.*)$ /auth/smart/$1 [R=301]
RewriteRule ^/smart-redir-limited/(.*)/info/refs$ /smart/$1/info/refs [R=301]
RewriteRule ^/ftp-redir/(.*)$ ftp://localhost:1000/$1 [R=302]

RewriteRule ^/loop-redir/x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-(.*) /$1 [R=302]
RewriteRule ^/loop-redir/(.*)$ /loop-redir/x-$1 [R=302]

<IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so

Expand Down
4 changes: 4 additions & 0 deletions t/t5812-proto-disable-http.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ test_expect_success 'curl redirects respect whitelist' '
}
'

test_expect_success 'curl limits redirects' '
test_must_fail git clone "$HTTPD_URL/loop-redir/smart/repo.git"
'

stop_httpd
test_done

0 comments on commit b258116

Please sign in to comment.