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

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