Blame SOURCES/0060-curl-7.29.0-CVE-2018-1000007.patch

6311d4
From e6968d1d220891230bcca5340bfd364183ceaa31 Mon Sep 17 00:00:00 2001
6311d4
From: Daniel Stenberg <daniel@haxx.se>
6311d4
Date: Fri, 19 Jan 2018 13:19:25 +0100
6311d4
Subject: [PATCH] http: prevent custom Authorization headers in redirects
6311d4
6311d4
... unless CURLOPT_UNRESTRICTED_AUTH is set to allow them. This matches how
6311d4
curl already handles Authorization headers created internally.
6311d4
6311d4
Note: this changes behavior slightly, for the sake of reducing mistakes.
6311d4
6311d4
Added test 317 and 318 to verify.
6311d4
6311d4
Reported-by: Craig de Stigter
6311d4
Bug: https://curl.haxx.se/docs/adv_2018-b3bf.html
6311d4
6311d4
Upstream-commit: af32cd3859336ab963591ca0df9b1e33a7ee066b
6311d4
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
6311d4
---
6311d4
 docs/libcurl/curl_easy_setopt.3 | 10 +++++
6311d4
 lib/http.c                      | 10 ++++-
6311d4
 lib/url.c                       |  2 +-
6311d4
 lib/urldata.h                   |  2 +-
6311d4
 tests/data/Makefile.am          |  3 +-
6311d4
 tests/data/test317              | 94 ++++++++++++++++++++++++++++++++++++++++
6311d4
 tests/data/test318              | 95 +++++++++++++++++++++++++++++++++++++++++
6311d4
 7 files changed, 212 insertions(+), 4 deletions(-)
6311d4
 create mode 100644 tests/data/test317
6311d4
 create mode 100644 tests/data/test318
6311d4
6311d4
diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
6311d4
index 4ce8207..cbebfba 100644
6311d4
--- a/docs/libcurl/curl_easy_setopt.3
6311d4
+++ b/docs/libcurl/curl_easy_setopt.3
6311d4
@@ -67,6 +67,16 @@ this when you debug/report problems. Another neat option for debugging is the
6311d4
 A parameter set to 1 tells the library to include the header in the body
6311d4
 output. This is only relevant for protocols that actually have headers
6311d4
 preceding the data (like HTTP).
6311d4
+
6311d4
+Custom headers are sent in all requests done by the easy handles, which
6311d4
+implies that if you tell libcurl to follow redirects
6311d4
+(\fICURLOPT_FOLLOWLOCATION(3)\fP), the same set of custom headers will be sent
6311d4
+in the subsequent request. Redirects can of course go to other hosts and thus
6311d4
+those servers will get all the contents of your custom headers too.
6311d4
+
6311d4
+Starting in 7.58.0, libcurl will specifically prevent "Authorization:" headers
6311d4
+from being sent to other hosts than the first used one, unless specifically
6311d4
+permitted with the \fICURLOPT_UNRESTRICTED_AUTH(3)\fP option.
6311d4
 .IP CURLOPT_NOPROGRESS
6311d4
 Pass a long. If set to 1, it tells the library to shut off the progress meter
6311d4
 completely. It will also prevent the \fICURLOPT_PROGRESSFUNCTION\fP from
6311d4
diff --git a/lib/http.c b/lib/http.c
6311d4
index b73e58c..c15208d 100644
6311d4
--- a/lib/http.c
6311d4
+++ b/lib/http.c
6311d4
@@ -666,7 +666,7 @@ Curl_http_output_auth(struct connectdata *conn,
6311d4
   if(!data->state.this_is_a_follow ||
6311d4
      conn->bits.netrc ||
6311d4
      !data->state.first_host ||
6311d4
-     data->set.http_disable_hostname_check_before_authentication ||
6311d4
+     data->set.allow_auth_to_other_hosts ||
6311d4
      Curl_raw_equal(data->state.first_host, conn->host.name)) {
6311d4
     result = output_auth_headers(conn, authhost, request, path, FALSE);
6311d4
   }
6311d4
@@ -1550,6 +1550,14 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
6311d4
                    Connection: */
6311d4
                 checkprefix("Connection", headers->data))
6311d4
           ;
6311d4
+        else if(checkprefix("Authorization:", headers->data) &&
6311d4
+                /* be careful of sending this potentially sensitive header to
6311d4
+                   other hosts */
6311d4
+                (conn->data->state.this_is_a_follow &&
6311d4
+                 conn->data->state.first_host &&
6311d4
+                 !conn->data->set.allow_auth_to_other_hosts &&
6311d4
+                 !strequal(conn->data->state.first_host, conn->host.name)))
6311d4
+          ;
6311d4
         else {
6311d4
           CURLcode result = Curl_add_bufferf(req_buffer, "%s\r\n",
6311d4
                                              headers->data);
6311d4
diff --git a/lib/url.c b/lib/url.c
6311d4
index 71d4d8b..ba53131 100644
6311d4
--- a/lib/url.c
6311d4
+++ b/lib/url.c
6311d4
@@ -912,7 +912,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
6311d4
      * Send authentication (user+password) when following locations, even when
6311d4
      * hostname changed.
6311d4
      */
6311d4
-    data->set.http_disable_hostname_check_before_authentication =
6311d4
+    data->set.allow_auth_to_other_hosts =
6311d4
       (0 != va_arg(param, long))?TRUE:FALSE;
6311d4
     break;
6311d4
 
6311d4
diff --git a/lib/urldata.h b/lib/urldata.h
6311d4
index b4f18e7..1dd62ae 100644
6311d4
--- a/lib/urldata.h
6311d4
+++ b/lib/urldata.h
6311d4
@@ -1528,7 +1528,7 @@ struct UserDefined {
6311d4
   bool http_fail_on_error;  /* fail on HTTP error codes >= 300 */
6311d4
   bool http_follow_location; /* follow HTTP redirects */
6311d4
   bool http_transfer_encoding; /* request compressed HTTP transfer-encoding */
6311d4
-  bool http_disable_hostname_check_before_authentication;
6311d4
+  bool allow_auth_to_other_hosts;
6311d4
   bool include_header;   /* include received protocol headers in data output */
6311d4
   bool http_set_referer; /* is a custom referer used */
6311d4
   bool http_auto_referer; /* set "correct" referer when following location: */
6311d4
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
6311d4
index 3b31581..56cb286 100644
6311d4
--- a/tests/data/Makefile.am
6311d4
+++ b/tests/data/Makefile.am
6311d4
@@ -36,7 +36,8 @@ test276 test277 test278 test279 test280 test281 test282 test283 test284	\
6311d4
 test285 test286 test287 test288 test289 test290 test291 test292 test293	\
6311d4
 test294 test295 test296 test297 test298 test299 test300 test301 test302	\
6311d4
 test303 test304 test305 test306 test307 test308 test309 test310 test311	\
6311d4
-test312 test313 test320 test321 test322 test323 test324 test350 test351	\
6311d4
+test312 test313 test317 test318 \
6311d4
+test320 test321 test322 test323 test324 test350 test351	\
6311d4
 test352 test353 test354 test400 test401 test402 test403 test404 test405	\
6311d4
 test406 test407 test408 test409 test500 test501 test502 test503 test504	\
6311d4
 test505 test506 test507 test508 test510 test511 test512 test513 test514	\
6311d4
diff --git a/tests/data/test317 b/tests/data/test317
6311d4
new file mode 100644
6311d4
index 0000000..c6d8697
6311d4
--- /dev/null
6311d4
+++ b/tests/data/test317
6311d4
@@ -0,0 +1,94 @@
6311d4
+<testcase>
6311d4
+<info>
6311d4
+<keywords>
6311d4
+HTTP
6311d4
+HTTP proxy
6311d4
+HTTP Basic auth
6311d4
+HTTP proxy Basic auth
6311d4
+followlocation
6311d4
+</keywords>
6311d4
+</info>
6311d4
+#
6311d4
+# Server-side
6311d4
+<reply>
6311d4
+<data>
6311d4
+HTTP/1.1 302 OK
6311d4
+Date: Thu, 09 Nov 2010 14:49:00 GMT
6311d4
+Server: test-server/fake swsclose
6311d4
+Content-Type: text/html
6311d4
+Funny-head: yesyes
6311d4
+Location: http://goto.second.host.now/3170002
6311d4
+Content-Length: 8
6311d4
+Connection: close
6311d4
+
6311d4
+contents
6311d4
+</data>
6311d4
+<data2>
6311d4
+HTTP/1.1 200 OK
6311d4
+Date: Thu, 09 Nov 2010 14:49:00 GMT
6311d4
+Server: test-server/fake swsclose
6311d4
+Content-Type: text/html
6311d4
+Funny-head: yesyes
6311d4
+Content-Length: 9
6311d4
+
6311d4
+contents
6311d4
+</data2>
6311d4
+
6311d4
+<datacheck>
6311d4
+HTTP/1.1 302 OK
6311d4
+Date: Thu, 09 Nov 2010 14:49:00 GMT
6311d4
+Server: test-server/fake swsclose
6311d4
+Content-Type: text/html
6311d4
+Funny-head: yesyes
6311d4
+Location: http://goto.second.host.now/3170002
6311d4
+Content-Length: 8
6311d4
+Connection: close
6311d4
+
6311d4
+HTTP/1.1 200 OK
6311d4
+Date: Thu, 09 Nov 2010 14:49:00 GMT
6311d4
+Server: test-server/fake swsclose
6311d4
+Content-Type: text/html
6311d4
+Funny-head: yesyes
6311d4
+Content-Length: 9
6311d4
+
6311d4
+contents
6311d4
+</datacheck>
6311d4
+</reply>
6311d4
+
6311d4
+#
6311d4
+# Client-side
6311d4
+<client>
6311d4
+<server>
6311d4
+http
6311d4
+</server>
6311d4
+ <name>
6311d4
+HTTP with custom Authorization: and redirect to new host
6311d4
+ </name>
6311d4
+ <command>
6311d4
+http://first.host.it.is/we/want/that/page/317 -x %HOSTIP:%HTTPPORT -H "Authorization: s3cr3t" --proxy-user testing:this --location
6311d4
+</command>
6311d4
+</client>
6311d4
+
6311d4
+#
6311d4
+# Verify data after the test has been "shot"
6311d4
+<verify>
6311d4
+<strip>
6311d4
+^User-Agent:.*
6311d4
+</strip>
6311d4
+<protocol>
6311d4
+GET http://first.host.it.is/we/want/that/page/317 HTTP/1.1
6311d4
+Proxy-Authorization: Basic dGVzdGluZzp0aGlz
6311d4
+Host: first.host.it.is
6311d4
+Accept: */*
6311d4
+Proxy-Connection: Keep-Alive
6311d4
+Authorization: s3cr3t
6311d4
+
6311d4
+GET http://goto.second.host.now/3170002 HTTP/1.1
6311d4
+Proxy-Authorization: Basic dGVzdGluZzp0aGlz
6311d4
+Host: goto.second.host.now
6311d4
+Accept: */*
6311d4
+Proxy-Connection: Keep-Alive
6311d4
+
6311d4
+</protocol>
6311d4
+</verify>
6311d4
+</testcase>
6311d4
diff --git a/tests/data/test318 b/tests/data/test318
6311d4
new file mode 100644
6311d4
index 0000000..838d1ba
6311d4
--- /dev/null
6311d4
+++ b/tests/data/test318
6311d4
@@ -0,0 +1,95 @@
6311d4
+<testcase>
6311d4
+<info>
6311d4
+<keywords>
6311d4
+HTTP
6311d4
+HTTP proxy
6311d4
+HTTP Basic auth
6311d4
+HTTP proxy Basic auth
6311d4
+followlocation
6311d4
+</keywords>
6311d4
+</info>
6311d4
+#
6311d4
+# Server-side
6311d4
+<reply>
6311d4
+<data>
6311d4
+HTTP/1.1 302 OK
6311d4
+Date: Thu, 09 Nov 2010 14:49:00 GMT
6311d4
+Server: test-server/fake swsclose
6311d4
+Content-Type: text/html
6311d4
+Funny-head: yesyes
6311d4
+Location: http://goto.second.host.now/3180002
6311d4
+Content-Length: 8
6311d4
+Connection: close
6311d4
+
6311d4
+contents
6311d4
+</data>
6311d4
+<data2>
6311d4
+HTTP/1.1 200 OK
6311d4
+Date: Thu, 09 Nov 2010 14:49:00 GMT
6311d4
+Server: test-server/fake swsclose
6311d4
+Content-Type: text/html
6311d4
+Funny-head: yesyes
6311d4
+Content-Length: 9
6311d4
+
6311d4
+contents
6311d4
+</data2>
6311d4
+
6311d4
+<datacheck>
6311d4
+HTTP/1.1 302 OK
6311d4
+Date: Thu, 09 Nov 2010 14:49:00 GMT
6311d4
+Server: test-server/fake swsclose
6311d4
+Content-Type: text/html
6311d4
+Funny-head: yesyes
6311d4
+Location: http://goto.second.host.now/3180002
6311d4
+Content-Length: 8
6311d4
+Connection: close
6311d4
+
6311d4
+HTTP/1.1 200 OK
6311d4
+Date: Thu, 09 Nov 2010 14:49:00 GMT
6311d4
+Server: test-server/fake swsclose
6311d4
+Content-Type: text/html
6311d4
+Funny-head: yesyes
6311d4
+Content-Length: 9
6311d4
+
6311d4
+contents
6311d4
+</datacheck>
6311d4
+</reply>
6311d4
+
6311d4
+#
6311d4
+# Client-side
6311d4
+<client>
6311d4
+<server>
6311d4
+http
6311d4
+</server>
6311d4
+ <name>
6311d4
+HTTP with custom Authorization: and redirect to new host
6311d4
+ </name>
6311d4
+ <command>
6311d4
+http://first.host.it.is/we/want/that/page/318 -x %HOSTIP:%HTTPPORT -H "Authorization: s3cr3t" --proxy-user testing:this --location-trusted
6311d4
+</command>
6311d4
+</client>
6311d4
+
6311d4
+#
6311d4
+# Verify data after the test has been "shot"
6311d4
+<verify>
6311d4
+<strip>
6311d4
+^User-Agent:.*
6311d4
+</strip>
6311d4
+<protocol>
6311d4
+GET http://first.host.it.is/we/want/that/page/318 HTTP/1.1
6311d4
+Proxy-Authorization: Basic dGVzdGluZzp0aGlz
6311d4
+Host: first.host.it.is
6311d4
+Accept: */*
6311d4
+Proxy-Connection: Keep-Alive
6311d4
+Authorization: s3cr3t
6311d4
+
6311d4
+GET http://goto.second.host.now/3180002 HTTP/1.1
6311d4
+Proxy-Authorization: Basic dGVzdGluZzp0aGlz
6311d4
+Host: goto.second.host.now
6311d4
+Accept: */*
6311d4
+Proxy-Connection: Keep-Alive
6311d4
+Authorization: s3cr3t
6311d4
+
6311d4
+</protocol>
6311d4
+</verify>
6311d4
+</testcase>
6311d4
-- 
6311d4
2.13.6
6311d4