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

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