]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http: limit redirection depth
authorBlake Burkhart <bburky@bburky.com>
Tue, 22 Sep 2015 22:06:20 +0000 (18:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 25 Sep 2015 22:32:28 +0000 (15:32 -0700)
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>
http.c
t/lib-httpd/apache.conf
t/t5812-proto-disable-http.sh

diff --git a/http.c b/http.c
index 5a57bccea9e762e144a0694128caa7eb45ab4b4d..00e3fc80e8161080549db26afd68e341989af453 100644 (file)
--- a/http.c
+++ b/http.c
@@ -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
index 68ef8adb8e2b6cded72c5ddbdcdac633e5ee2261..7d15e6d44c83f6b37297ae01a2998825e313b9b2 100644 (file)
@@ -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
 
index 6a4f81662d816eb1392ce48dda11911a54759565..0d105d54174e061b20707de808b284314f730667 100755 (executable)
@@ -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