Blame SOURCES/0012-curl-7.76.1-CVE-2022-27776.patch

e078bf
From 2be87227d4b4024c91ff6c856520cac9c9619555 Mon Sep 17 00:00:00 2001
e078bf
From: Daniel Stenberg <daniel@haxx.se>
e078bf
Date: Mon, 25 Apr 2022 13:05:40 +0200
e078bf
Subject: [PATCH 1/2] http: avoid auth/cookie on redirects same host diff port
e078bf
e078bf
CVE-2022-27776
e078bf
e078bf
Reported-by: Harry Sintonen
e078bf
Bug: https://curl.se/docs/CVE-2022-27776.html
e078bf
Closes #8749
e078bf
e078bf
Upstream-commit: 6e659993952aa5f90f48864be84a1bbb047fc258
e078bf
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
e078bf
---
e078bf
 lib/http.c    | 33 +++++++++++++++++++++------------
e078bf
 lib/urldata.h | 16 +++++++++-------
e078bf
 2 files changed, 30 insertions(+), 19 deletions(-)
e078bf
e078bf
diff --git a/lib/http.c b/lib/http.c
e078bf
index 799d4fb..0791dcf 100644
e078bf
--- a/lib/http.c
e078bf
+++ b/lib/http.c
e078bf
@@ -775,6 +775,21 @@ output_auth_headers(struct Curl_easy *data,
e078bf
   return CURLE_OK;
e078bf
 }
e078bf
 
e078bf
+/*
e078bf
+ * allow_auth_to_host() tells if autentication, cookies or other "sensitive
e078bf
+ * data" can (still) be sent to this host.
e078bf
+ */
e078bf
+static bool allow_auth_to_host(struct Curl_easy *data)
e078bf
+{
e078bf
+  struct connectdata *conn = data->conn;
e078bf
+  return (!data->state.this_is_a_follow ||
e078bf
+          data->set.allow_auth_to_other_hosts ||
e078bf
+          (data->state.first_host &&
e078bf
+           strcasecompare(data->state.first_host, conn->host.name) &&
e078bf
+           (data->state.first_remote_port == conn->remote_port) &&
e078bf
+           (data->state.first_remote_protocol == conn->handler->protocol)));
e078bf
+}
e078bf
+
e078bf
 /**
e078bf
  * Curl_http_output_auth() setups the authentication headers for the
e078bf
  * host/proxy and the correct authentication
e078bf
@@ -847,15 +862,11 @@ Curl_http_output_auth(struct Curl_easy *data,
e078bf
        with it */
e078bf
     authproxy->done = TRUE;
e078bf
 
e078bf
-  /* To prevent the user+password to get sent to other than the original
e078bf
-     host due to a location-follow, we do some weirdo checks here */
e078bf
-  if(!data->state.this_is_a_follow ||
e078bf
-     conn->bits.netrc ||
e078bf
-     !data->state.first_host ||
e078bf
-     data->set.allow_auth_to_other_hosts ||
e078bf
-     strcasecompare(data->state.first_host, conn->host.name)) {
e078bf
+  /* To prevent the user+password to get sent to other than the original host
e078bf
+     due to a location-follow */
e078bf
+  if(allow_auth_to_host(data)
e078bf
+     || conn->bits.netrc)
e078bf
     result = output_auth_headers(data, conn, authhost, request, path, FALSE);
e078bf
-  }
e078bf
   else
e078bf
     authhost->done = TRUE;
e078bf
 
e078bf
@@ -1906,10 +1917,7 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data,
e078bf
                    checkprefix("Cookie:", compare)) &&
e078bf
                   /* be careful of sending this potentially sensitive header to
e078bf
                      other hosts */
e078bf
-                  (data->state.this_is_a_follow &&
e078bf
-                   data->state.first_host &&
e078bf
-                   !data->set.allow_auth_to_other_hosts &&
e078bf
-                   !strcasecompare(data->state.first_host, conn->host.name)))
e078bf
+                  !allow_auth_to_host(data))
e078bf
             ;
e078bf
           else {
e078bf
 #ifdef USE_HYPER
e078bf
@@ -2081,6 +2089,7 @@ CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn)
e078bf
       return CURLE_OUT_OF_MEMORY;
e078bf
 
e078bf
     data->state.first_remote_port = conn->remote_port;
e078bf
+    data->state.first_remote_protocol = conn->handler->protocol;
e078bf
   }
e078bf
   Curl_safefree(data->state.aptr.host);
e078bf
 
e078bf
diff --git a/lib/urldata.h b/lib/urldata.h
e078bf
index 03da59a..f92052a 100644
e078bf
--- a/lib/urldata.h
e078bf
+++ b/lib/urldata.h
e078bf
@@ -1336,14 +1336,16 @@ struct UrlState {
e078bf
   char *ulbuf; /* allocated upload buffer or NULL */
e078bf
   curl_off_t current_speed;  /* the ProgressShow() function sets this,
e078bf
                                 bytes / second */
e078bf
-  char *first_host; /* host name of the first (not followed) request.
e078bf
-                       if set, this should be the host name that we will
e078bf
-                       sent authorization to, no else. Used to make Location:
e078bf
-                       following not keep sending user+password... This is
e078bf
-                       strdup() data.
e078bf
-                    */
e078bf
+
e078bf
+  /* host name, port number and protocol of the first (not followed) request.
e078bf
+     if set, this should be the host name that we will sent authorization to,
e078bf
+     no else. Used to make Location: following not keep sending user+password.
e078bf
+     This is strdup()ed data. */
e078bf
+  char *first_host;
e078bf
+  int first_remote_port;
e078bf
+  unsigned int first_remote_protocol;
e078bf
+
e078bf
   int retrycount; /* number of retries on a new connection */
e078bf
-  int first_remote_port; /* remote port of the first (not followed) request */
e078bf
   struct Curl_ssl_session *session; /* array of 'max_ssl_sessions' size */
e078bf
   long sessionage;                  /* number of the most recent session */
e078bf
   struct tempbuf tempwrite[3]; /* BOTH, HEADER, BODY */
e078bf
-- 
e078bf
2.34.1
e078bf
e078bf
e078bf
From c0d12f1634785596746e5d461319dcb95b5b6ae8 Mon Sep 17 00:00:00 2001
e078bf
From: Daniel Stenberg <daniel@haxx.se>
e078bf
Date: Mon, 25 Apr 2022 13:05:47 +0200
e078bf
Subject: [PATCH 2/2] test898: verify the fix for CVE-2022-27776
e078bf
e078bf
Do not pass on Authorization headers on redirects to another port
e078bf
e078bf
Upstream-commit: afe752e0504ab60bf63787ede0b992cbe1065f78
e078bf
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
e078bf
---
e078bf
 tests/data/Makefile.inc |  2 +-
e078bf
 tests/data/test898      | 90 +++++++++++++++++++++++++++++++++++++++++
e078bf
 2 files changed, 91 insertions(+), 1 deletion(-)
e078bf
 create mode 100644 tests/data/test898
e078bf
e078bf
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
e078bf
index 59d46bc..7ae2cf8 100644
e078bf
--- a/tests/data/Makefile.inc
e078bf
+++ b/tests/data/Makefile.inc
e078bf
@@ -106,7 +106,7 @@ test854 test855 test856 test857 test858 test859 test860 test861 test862 \
e078bf
 test863 test864 test865 test866 test867 test868 test869 test870 test871 \
e078bf
 test872 test873 test874 test875 test876 test877 test878 test879 test880 \
e078bf
 test881 test882 test883 test884 test885 test886 test887 test888 test889 \
e078bf
-test890 test891 test892 test893 test894 test895 test896 \
e078bf
+test890 test891 test892 test893 test894 test895 test896         test898 \
e078bf
 \
e078bf
 test900 test901 test902 test903 test904 test905 test906 test907 test908 \
e078bf
 test909 test910 test911 test912 test913 test914 test915 test916 test917 \
e078bf
diff --git a/tests/data/test898 b/tests/data/test898
e078bf
new file mode 100644
e078bf
index 0000000..5cbb7d8
e078bf
--- /dev/null
e078bf
+++ b/tests/data/test898
e078bf
@@ -0,0 +1,90 @@
e078bf
+<testcase>
e078bf
+<info>
e078bf
+<keywords>
e078bf
+HTTP
e078bf
+--location
e078bf
+Authorization
e078bf
+Cookie
e078bf
+</keywords>
e078bf
+</info>
e078bf
+
e078bf
+#
e078bf
+# Server-side
e078bf
+<reply>
e078bf
+<data>
e078bf
+HTTP/1.1 301 redirect
e078bf
+Date: Tue, 09 Nov 2010 14:49:00 GMT
e078bf
+Server: test-server/fake
e078bf
+Content-Length: 0
e078bf
+Connection: close
e078bf
+Content-Type: text/html
e078bf
+Location: http://firsthost.com:9999/a/path/%TESTNUMBER0002
e078bf
+
e078bf
+</data>
e078bf
+<data2>
e078bf
+HTTP/1.1 200 OK
e078bf
+Date: Tue, 09 Nov 2010 14:49:00 GMT
e078bf
+Server: test-server/fake
e078bf
+Content-Length: 4
e078bf
+Connection: close
e078bf
+Content-Type: text/html
e078bf
+
e078bf
+hey
e078bf
+</data2>
e078bf
+
e078bf
+<datacheck>
e078bf
+HTTP/1.1 301 redirect
e078bf
+Date: Tue, 09 Nov 2010 14:49:00 GMT
e078bf
+Server: test-server/fake
e078bf
+Content-Length: 0
e078bf
+Connection: close
e078bf
+Content-Type: text/html
e078bf
+Location: http://firsthost.com:9999/a/path/%TESTNUMBER0002
e078bf
+
e078bf
+HTTP/1.1 200 OK
e078bf
+Date: Tue, 09 Nov 2010 14:49:00 GMT
e078bf
+Server: test-server/fake
e078bf
+Content-Length: 4
e078bf
+Connection: close
e078bf
+Content-Type: text/html
e078bf
+
e078bf
+hey
e078bf
+</datacheck>
e078bf
+
e078bf
+</reply>
e078bf
+
e078bf
+#
e078bf
+# Client-side
e078bf
+<client>
e078bf
+<server>
e078bf
+http
e078bf
+</server>
e078bf
+ <name>
e078bf
+HTTP with custom auth and cookies redirected to HTTP on a diff port
e078bf
+ </name>
e078bf
+ <command>
e078bf
+-x http://%HOSTIP:%HTTPPORT http://firsthost.com -L -H "Authorization: Basic am9lOnNlY3JldA==" -H "Cookie: userpwd=am9lOnNlY3JldA=="
e078bf
+</command>
e078bf
+</client>
e078bf
+
e078bf
+#
e078bf
+# Verify data after the test has been "shot"
e078bf
+<verify>
e078bf
+<protocol>
e078bf
+GET http://firsthost.com/ HTTP/1.1
e078bf
+Host: firsthost.com
e078bf
+User-Agent: curl/%VERSION
e078bf
+Accept: */*
e078bf
+Proxy-Connection: Keep-Alive
e078bf
+Authorization: Basic am9lOnNlY3JldA==
e078bf
+Cookie: userpwd=am9lOnNlY3JldA==
e078bf
+
e078bf
+GET http://firsthost.com:9999/a/path/%TESTNUMBER0002 HTTP/1.1
e078bf
+Host: firsthost.com:9999
e078bf
+User-Agent: curl/%VERSION
e078bf
+Accept: */*
e078bf
+Proxy-Connection: Keep-Alive
e078bf
+
e078bf
+</protocol>
e078bf
+</verify>
e078bf
+</testcase>
e078bf
-- 
e078bf
2.34.1
e078bf