Skip to content

Commit b258116

Browse files
bburkygitster
authored andcommitted
http: limit redirection depth
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f4113ca commit b258116

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ static CURL *get_curl_handle(void)
352352
}
353353

354354
curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
355+
curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20);
355356
#if LIBCURL_VERSION_NUM >= 0x071301
356357
curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
357358
#elif LIBCURL_VERSION_NUM >= 0x071101

t/lib-httpd/apache.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ RewriteRule ^/smart-redir-auth/(.*)$ /auth/smart/$1 [R=301]
121121
RewriteRule ^/smart-redir-limited/(.*)/info/refs$ /smart/$1/info/refs [R=301]
122122
RewriteRule ^/ftp-redir/(.*)$ ftp://localhost:1000/$1 [R=302]
123123

124+
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]
125+
RewriteRule ^/loop-redir/(.*)$ /loop-redir/x-$1 [R=302]
126+
124127
<IfDefine SSL>
125128
LoadModule ssl_module modules/mod_ssl.so
126129

t/t5812-proto-disable-http.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ test_expect_success 'curl redirects respect whitelist' '
2525
}
2626
'
2727

28+
test_expect_success 'curl limits redirects' '
29+
test_must_fail git clone "$HTTPD_URL/loop-redir/smart/repo.git"
30+
'
31+
2832
stop_httpd
2933
test_done

0 commit comments

Comments
 (0)