Blame SOURCES/0004-http-limit-redirection-to-protocol-whitelist.patch

647f52
From 2d22150270739cd29d0ac6bc329e0a2e2910d7d9 Mon Sep 17 00:00:00 2001
647f52
From: Petr Stodulka <pstodulk@redhat.com>
647f52
Date: Fri, 23 Oct 2015 17:36:57 +0200
647f52
Subject: [PATCH 4/5] http-limit-redirection-to-protocol-whitelist
647f52
647f52
Previously, libcurl would follow redirection to any protocol
647f52
it was compiled for support with. This is desirable to allow
647f52
redirection from HTTP to HTTPS. However, it would even
647f52
successfully allow redirection from HTTP to SFTP, a protocol
647f52
that git does not otherwise support at all. Furthermore
647f52
git's new protocol-whitelisting could be bypassed by
647f52
following a redirect within the remote helper, as it was
647f52
only enforced at transport selection time.
647f52
647f52
This patch limits redirects within libcurl to HTTP, HTTPS,
647f52
FTP and FTPS. If there is a protocol-whitelist present, this
647f52
list is limited to those also allowed by the whitelist. As
647f52
redirection happens from within libcurl, it is impossible
647f52
for an HTTP redirect to a protocol implemented within
647f52
another remote helper.
647f52
647f52
When the curl version git was compiled with is too old to
647f52
support restrictions on protocol redirection, we warn the
647f52
user if GIT_ALLOW_PROTOCOL restrictions were requested. This
647f52
is a little inaccurate, as even without that variable in the
647f52
environment, we would still restrict SFTP, etc, and we do
647f52
not warn in that case. But anything else means we would
647f52
literally warn every time git accesses an http remote.
647f52
---
647f52
 http.c | 17 +++++++++++++++++
647f52
 1 file changed, 17 insertions(+)
647f52
647f52
diff --git a/http.c b/http.c
647f52
index 92aba59..235c2d5 100644
647f52
--- a/http.c
647f52
+++ b/http.c
647f52
@@ -6,6 +6,7 @@
647f52
 #include "credential.h"
647f52
 #include "version.h"
647f52
 #include "pkt-line.h"
647f52
+#include "transport.h"
647f52
 
647f52
 int active_requests;
647f52
 int http_is_verbose;
647f52
@@ -252,6 +253,7 @@ static int has_cert_password(void)
647f52
 static CURL *get_curl_handle(void)
647f52
 {
647f52
 	CURL *result = curl_easy_init();
647f52
+	long allowed_protocols = 0;
647f52
 
647f52
 	if (!curl_ssl_verify) {
647f52
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 0);
647f52
@@ -301,6 +303,21 @@ static CURL *get_curl_handle(void)
647f52
 #elif LIBCURL_VERSION_NUM >= 0x071101
647f52
 	curl_easy_setopt(result, CURLOPT_POST301, 1);
647f52
 #endif
647f52
+#if LIBCURL_VERSION_NUM >= 0x071304
647f52
+	if (is_transport_allowed("http"))
647f52
+		allowed_protocols |= CURLPROTO_HTTP;
647f52
+	if (is_transport_allowed("https"))
647f52
+		allowed_protocols |= CURLPROTO_HTTPS;
647f52
+	if (is_transport_allowed("ftp"))
647f52
+		allowed_protocols |= CURLPROTO_FTP;
647f52
+	if (is_transport_allowed("ftps"))
647f52
+		allowed_protocols |= CURLPROTO_FTPS;
647f52
+	curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS, allowed_protocols);
647f52
+#else
647f52
+	if (transport_restrict_protocols())
647f52
+		warning("protocol restrictions not applied to curl redirects because\n"
647f52
+			"your curl version is too old (>= 7.19.4)");
647f52
+#endif
647f52
 
647f52
 	if (getenv("GIT_CURL_VERBOSE"))
647f52
 		curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
647f52
-- 
647f52
2.1.0
647f52