01238a
From 48f126157d36962e458bf12f90b50cfcef26eee9 Mon Sep 17 00:00:00 2001
01238a
From: Daniel Stenberg <daniel@haxx.se>
01238a
Date: Mon, 25 Apr 2022 16:24:33 +0200
01238a
Subject: [PATCH 1/4] connect: store "conn_remote_port" in the info struct
01238a
01238a
To make it available after the connection ended.
01238a
01238a
Upstream-commit: 08b8ef4e726ba10f45081ecda5b3cea788d3c839
01238a
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
01238a
---
01238a
 lib/connect.c | 1 +
01238a
 lib/urldata.h | 6 +++++-
01238a
 2 files changed, 6 insertions(+), 1 deletion(-)
01238a
01238a
diff --git a/lib/connect.c b/lib/connect.c
01238a
index f724646..12a8aae 100644
01238a
--- a/lib/connect.c
01238a
+++ b/lib/connect.c
01238a
@@ -614,6 +614,7 @@ void Curl_persistconninfo(struct connectdata *conn)
01238a
   conn->data->info.conn_scheme = conn->handler->scheme;
01238a
   conn->data->info.conn_protocol = conn->handler->protocol;
01238a
   conn->data->info.conn_primary_port = conn->primary_port;
01238a
+  conn->data->info.conn_remote_port = conn->remote_port;
01238a
   conn->data->info.conn_local_port = conn->local_port;
01238a
 }
01238a
 
01238a
diff --git a/lib/urldata.h b/lib/urldata.h
01238a
index 4bb0a84..cadf0e5 100644
01238a
--- a/lib/urldata.h
01238a
+++ b/lib/urldata.h
01238a
@@ -1050,7 +1050,11 @@ struct PureInfo {
01238a
      reused, in the connection cache. */
01238a
 
01238a
   char conn_primary_ip[MAX_IPADR_LEN];
01238a
-  long conn_primary_port;
01238a
+  long conn_primary_port;/* this is the destination port to the connection,
01238a
+                            which might have been a proxy */
01238a
+  int conn_remote_port;  /* this is the "remote port", which is the port
01238a
+                            number of the used URL, independent of proxy or
01238a
+                            not */
01238a
 
01238a
   char conn_local_ip[MAX_IPADR_LEN];
01238a
   long conn_local_port;
01238a
-- 
01238a
2.34.1
01238a
01238a
01238a
From 6307fa6f9784402ba58697f46ba04354225391b7 Mon Sep 17 00:00:00 2001
01238a
From: Daniel Stenberg <daniel@haxx.se>
01238a
Date: Mon, 25 Apr 2022 16:24:33 +0200
01238a
Subject: [PATCH 2/4] transfer: redirects to other protocols or ports clear
01238a
 auth
01238a
01238a
... unless explicitly permitted.
01238a
01238a
Bug: https://curl.se/docs/CVE-2022-27774.html
01238a
Reported-by: Harry Sintonen
01238a
Closes #8748
01238a
01238a
Upstream-commit: 620ea21410030a9977396b4661806bc187231b79
01238a
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
01238a
---
01238a
 lib/transfer.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++
01238a
 lib/url.c      | 27 ++++++++++++++--------
01238a
 lib/urldata.h  |  1 +
01238a
 3 files changed, 81 insertions(+), 10 deletions(-)
01238a
01238a
diff --git a/lib/transfer.c b/lib/transfer.c
01238a
index ad5a7ba..2022cba 100644
01238a
--- a/lib/transfer.c
01238a
+++ b/lib/transfer.c
01238a
@@ -1370,6 +1370,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
01238a
   data->state.wildcardmatch = data->set.wildcard_enabled;
01238a
   data->set.followlocation = 0; /* reset the location-follow counter */
01238a
   data->state.this_is_a_follow = FALSE; /* reset this */
01238a
+  data->state.this_is_a_follow_without_auth = FALSE;
01238a
   data->state.errorbuf = FALSE; /* no error has occurred */
01238a
   data->state.httpversion = 0; /* don't assume any particular server version */
01238a
 
01238a
@@ -1554,6 +1555,68 @@ CURLcode Curl_follow(struct Curl_easy *data,
01238a
 
01238a
   }
01238a
 
01238a
+  /* Clear auth if this redirects to a different port number or protocol,
01238a
+     unless permitted */
01238a
+  if(!data->set.allow_auth_to_other_hosts && (type != FOLLOW_FAKE)) {
01238a
+    int port;
01238a
+    bool clear = FALSE;
01238a
+
01238a
+    CURLU *u = curl_url();
01238a
+    if(!u)
01238a
+      return CURLE_OUT_OF_MEMORY;
01238a
+
01238a
+    uc = curl_url_set(u, CURLUPART_URL, newurl,
01238a
+        ((type == FOLLOW_REDIR) ? CURLU_URLENCODE : 0));
01238a
+    if(uc) {
01238a
+      infof(data, "Clear auth, curl_url_set() failed\n");
01238a
+      clear = TRUE;
01238a
+    }
01238a
+
01238a
+    if(!clear) {
01238a
+      if(data->set.use_port && data->state.allow_port)
01238a
+        /* a custom port is used */
01238a
+        port = (int)data->set.use_port;
01238a
+      else {
01238a
+        char *portnum;
01238a
+        uc = curl_url_get(u, CURLUPART_PORT, &portnum, CURLU_DEFAULT_PORT);
01238a
+        if(uc) {
01238a
+          infof(data, "Clear auth, failed to parse port number\n");
01238a
+          clear = TRUE;
01238a
+        }
01238a
+        else {
01238a
+          port = atoi(portnum);
01238a
+          free(portnum);
01238a
+        }
01238a
+      }
01238a
+    }
01238a
+    if(!clear && port != data->info.conn_remote_port) {
01238a
+      infof(data, "Clear auth, redirects to port from %u to %u\n",
01238a
+            data->info.conn_remote_port, port);
01238a
+      clear = TRUE;
01238a
+    }
01238a
+    if(!clear) {
01238a
+      char *scheme;
01238a
+      const struct Curl_handler *p;
01238a
+      uc = curl_url_get(u, CURLUPART_SCHEME, &scheme, 0);
01238a
+      if(uc) {
01238a
+        infof(data, "Clear auth, failed to parse scheme\n");
01238a
+        clear = TRUE;
01238a
+      }
01238a
+      else {
01238a
+        p = Curl_builtin_scheme(scheme);
01238a
+        if(p && (p->protocol != data->info.conn_protocol)) {
01238a
+          infof(data, "Clear auth, redirects scheme from %s to %s\n",
01238a
+                data->info.conn_scheme, scheme);
01238a
+          clear = TRUE;
01238a
+        }
01238a
+        free(scheme);
01238a
+      }
01238a
+    }
01238a
+    if(clear)
01238a
+      data->state.this_is_a_follow_without_auth = TRUE;
01238a
+    curl_url_cleanup(u);
01238a
+  }
01238a
+
01238a
   if(type == FOLLOW_FAKE) {
01238a
     /* we're only figuring out the new url if we would've followed locations
01238a
        but now we're done so we can get out! */
01238a
diff --git a/lib/url.c b/lib/url.c
01238a
index ed3c933..7dd5267 100644
01238a
--- a/lib/url.c
01238a
+++ b/lib/url.c
01238a
@@ -3483,18 +3483,25 @@ static CURLcode override_login(struct Curl_easy *data,
01238a
                                struct connectdata *conn,
01238a
                                char **userp, char **passwdp, char **optionsp)
01238a
 {
01238a
-  if(data->set.str[STRING_USERNAME]) {
01238a
-    free(*userp);
01238a
-    *userp = strdup(data->set.str[STRING_USERNAME]);
01238a
-    if(!*userp)
01238a
-      return CURLE_OUT_OF_MEMORY;
01238a
+  if(data->state.this_is_a_follow
01238a
+      && data->state.this_is_a_follow_without_auth)
01238a
+  {
01238a
+    conn->bits.user_passwd = FALSE;
01238a
   }
01238a
+  else {
01238a
+    if(data->set.str[STRING_USERNAME]) {
01238a
+      free(*userp);
01238a
+      *userp = strdup(data->set.str[STRING_USERNAME]);
01238a
+      if(!*userp)
01238a
+        return CURLE_OUT_OF_MEMORY;
01238a
+    }
01238a
 
01238a
-  if(data->set.str[STRING_PASSWORD]) {
01238a
-    free(*passwdp);
01238a
-    *passwdp = strdup(data->set.str[STRING_PASSWORD]);
01238a
-    if(!*passwdp)
01238a
-      return CURLE_OUT_OF_MEMORY;
01238a
+    if(data->set.str[STRING_PASSWORD]) {
01238a
+      free(*passwdp);
01238a
+      *passwdp = strdup(data->set.str[STRING_PASSWORD]);
01238a
+      if(!*passwdp)
01238a
+        return CURLE_OUT_OF_MEMORY;
01238a
+    }
01238a
   }
01238a
 
01238a
   if(data->set.str[STRING_OPTIONS]) {
01238a
diff --git a/lib/urldata.h b/lib/urldata.h
01238a
index cadf0e5..026684b 100644
01238a
--- a/lib/urldata.h
01238a
+++ b/lib/urldata.h
01238a
@@ -1234,6 +1234,7 @@ struct UrlState {
01238a
   curl_off_t current_speed;  /* the ProgressShow() function sets this,
01238a
                                 bytes / second */
01238a
   bool this_is_a_follow; /* this is a followed Location: request */
01238a
+  bool this_is_a_follow_without_auth;
01238a
   bool refused_stream; /* this was refused, try again */
01238a
 
01238a
   /* host name, port number and protocol of the first (not followed) request.
01238a
-- 
01238a
2.34.1
01238a
01238a
01238a
From b142f97840dfb033a1776d5a2986385da7753224 Mon Sep 17 00:00:00 2001
01238a
From: Daniel Stenberg <daniel@haxx.se>
01238a
Date: Mon, 25 Apr 2022 16:24:33 +0200
01238a
Subject: [PATCH 3/4] tests: verify the fix for CVE-2022-27774
01238a
01238a
 - Test 973 redirects from HTTP to FTP, clear auth
01238a
 - Test 974 redirects from HTTP to HTTP different port, clear auth
01238a
 - Test 975 redirects from HTTP to FTP, permitted to keep auth
01238a
 - Test 976 redirects from HTTP to HTTP different port, permitted to keep
01238a
   auth
01238a
01238a
Upstream-commit: 5295e8d64ac6949ecb3f9e564317a608f51b90d8
01238a
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
01238a
---
01238a
 tests/data/Makefile.inc |  1 +
01238a
 tests/data/test973      | 90 +++++++++++++++++++++++++++++++++++++++++
01238a
 tests/data/test974      | 88 ++++++++++++++++++++++++++++++++++++++++
01238a
 tests/data/test975      | 90 +++++++++++++++++++++++++++++++++++++++++
01238a
 tests/data/test976      | 89 ++++++++++++++++++++++++++++++++++++++++
01238a
 5 files changed, 358 insertions(+)
01238a
 create mode 100644 tests/data/test973
01238a
 create mode 100644 tests/data/test974
01238a
 create mode 100644 tests/data/test975
01238a
 create mode 100644 tests/data/test976
01238a
01238a
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
01238a
index 58c9e31..6c920ff 100644
01238a
--- a/tests/data/Makefile.inc
01238a
+++ b/tests/data/Makefile.inc
01238a
@@ -108,6 +108,7 @@ test927 test928 test929 test930 test931 test932 test933 test934 test935 \
01238a
 test936 test937 test938 test939 test940 test941 test942 test943 test944 \
01238a
 test945 test946 test947 test948 test949 test950 test951 test952 \
01238a
 \
01238a
+test973 test974 test975 test976 \
01238a
 test980 test981 test982 test983 test984 test985 test986 \
01238a
 \
01238a
 test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 \
01238a
diff --git a/tests/data/test973 b/tests/data/test973
01238a
new file mode 100644
01238a
index 0000000..6fe6ce0
01238a
--- /dev/null
01238a
+++ b/tests/data/test973
01238a
@@ -0,0 +1,90 @@
01238a
+<testcase>
01238a
+<info>
01238a
+<keywords>
01238a
+HTTP
01238a
+FTP
01238a
+--location
01238a
+</keywords>
01238a
+</info>
01238a
+
01238a
+#
01238a
+# Server-side
01238a
+<reply>
01238a
+<data>
01238a
+HTTP/1.1 301 redirect
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 0
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+Location: ftp://127.0.0.1:8992/a/path/9730002
01238a
+
01238a
+</data>
01238a
+<data2>
01238a
+data
01238a
+    to
01238a
+      see
01238a
+that FTP
01238a
+works
01238a
+  so does it?
01238a
+</data2>
01238a
+
01238a
+<datacheck>
01238a
+HTTP/1.1 301 redirect
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 0
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+Location: ftp://127.0.0.1:8992/a/path/9730002
01238a
+
01238a
+data
01238a
+    to
01238a
+      see
01238a
+that FTP
01238a
+works
01238a
+  so does it?
01238a
+</datacheck>
01238a
+
01238a
+</reply>
01238a
+
01238a
+#
01238a
+# Client-side
01238a
+<client>
01238a
+<server>
01238a
+http
01238a
+ftp
01238a
+</server>
01238a
+ <name>
01238a
+HTTP with auth redirected to FTP w/o auth
01238a
+ </name>
01238a
+ <command>
01238a
+http://%HOSTIP:%HTTPPORT/973 -L -u joe:secret
01238a
+</command>
01238a
+</client>
01238a
+
01238a
+#
01238a
+# Verify data after the test has been "shot"
01238a
+<verify>
01238a
+<strip>
01238a
+^User-Agent:.*
01238a
+</strip>
01238a
+<protocol>
01238a
+GET /973 HTTP/1.1
01238a
+Host: %HOSTIP:%HTTPPORT
01238a
+Authorization: Basic am9lOnNlY3JldA==
01238a
+Accept: */*
01238a
+
01238a
+USER anonymous
01238a
+PASS ftp@example.com
01238a
+PWD
01238a
+CWD a
01238a
+CWD path
01238a
+EPSV
01238a
+TYPE I
01238a
+SIZE 9730002
01238a
+RETR 9730002
01238a
+QUIT
01238a
+</protocol>
01238a
+</verify>
01238a
+</testcase>
01238a
diff --git a/tests/data/test974 b/tests/data/test974
01238a
new file mode 100644
01238a
index 0000000..de02d89
01238a
--- /dev/null
01238a
+++ b/tests/data/test974
01238a
@@ -0,0 +1,88 @@
01238a
+<testcase>
01238a
+<info>
01238a
+<keywords>
01238a
+HTTP
01238a
+--location
01238a
+</keywords>
01238a
+</info>
01238a
+
01238a
+#
01238a
+# Server-side
01238a
+<reply>
01238a
+<data>
01238a
+HTTP/1.1 301 redirect
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 0
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+Location: http://firsthost.com:9999/a/path/9740002
01238a
+
01238a
+</data>
01238a
+<data2>
01238a
+HTTP/1.1 200 OK
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 4
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+
01238a
+hey
01238a
+</data2>
01238a
+
01238a
+<datacheck>
01238a
+HTTP/1.1 301 redirect
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 0
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+Location: http://firsthost.com:9999/a/path/9740002
01238a
+
01238a
+HTTP/1.1 200 OK
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 4
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+
01238a
+hey
01238a
+</datacheck>
01238a
+
01238a
+</reply>
01238a
+
01238a
+#
01238a
+# Client-side
01238a
+<client>
01238a
+<server>
01238a
+http
01238a
+</server>
01238a
+ <name>
01238a
+HTTP with auth redirected to HTTP on a diff port w/o auth
01238a
+ </name>
01238a
+ <command>
01238a
+-x http://%HOSTIP:%HTTPPORT http://firsthost.com -L -u joe:secret
01238a
+</command>
01238a
+</client>
01238a
+
01238a
+#
01238a
+# Verify data after the test has been "shot"
01238a
+<verify>
01238a
+<strip>
01238a
+^User-Agent:.*
01238a
+</strip>
01238a
+<protocol>
01238a
+GET http://firsthost.com/ HTTP/1.1
01238a
+Host: firsthost.com
01238a
+Authorization: Basic am9lOnNlY3JldA==
01238a
+Accept: */*
01238a
+Proxy-Connection: Keep-Alive
01238a
+
01238a
+GET http://firsthost.com:9999/a/path/9740002 HTTP/1.1
01238a
+Host: firsthost.com:9999
01238a
+Accept: */*
01238a
+Proxy-Connection: Keep-Alive
01238a
+
01238a
+</protocol>
01238a
+</verify>
01238a
+</testcase>
01238a
diff --git a/tests/data/test975 b/tests/data/test975
01238a
new file mode 100644
01238a
index 0000000..3a4eccf
01238a
--- /dev/null
01238a
+++ b/tests/data/test975
01238a
@@ -0,0 +1,90 @@
01238a
+<testcase>
01238a
+<info>
01238a
+<keywords>
01238a
+HTTP
01238a
+FTP
01238a
+--location-trusted
01238a
+</keywords>
01238a
+</info>
01238a
+
01238a
+#
01238a
+# Server-side
01238a
+<reply>
01238a
+<data>
01238a
+HTTP/1.1 301 redirect
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 0
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+Location: ftp://127.0.0.1:8992/a/path/9750002
01238a
+
01238a
+</data>
01238a
+<data2>
01238a
+data
01238a
+    to
01238a
+      see
01238a
+that FTP
01238a
+works
01238a
+  so does it?
01238a
+</data2>
01238a
+
01238a
+<datacheck>
01238a
+HTTP/1.1 301 redirect
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 0
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+Location: ftp://127.0.0.1:8992/a/path/9750002
01238a
+
01238a
+data
01238a
+    to
01238a
+      see
01238a
+that FTP
01238a
+works
01238a
+  so does it?
01238a
+</datacheck>
01238a
+
01238a
+</reply>
01238a
+
01238a
+#
01238a
+# Client-side
01238a
+<client>
01238a
+<server>
01238a
+http
01238a
+ftp
01238a
+</server>
01238a
+ <name>
01238a
+HTTP with auth redirected to FTP allowing auth to continue
01238a
+ </name>
01238a
+ <command>
01238a
+http://%HOSTIP:%HTTPPORT/975 --location-trusted -u joe:secret
01238a
+</command>
01238a
+</client>
01238a
+
01238a
+#
01238a
+# Verify data after the test has been "shot"
01238a
+<verify>
01238a
+<strip>
01238a
+^User-Agent:.*
01238a
+</strip>
01238a
+<protocol>
01238a
+GET /975 HTTP/1.1
01238a
+Host: %HOSTIP:%HTTPPORT
01238a
+Authorization: Basic am9lOnNlY3JldA==
01238a
+Accept: */*
01238a
+
01238a
+USER joe
01238a
+PASS secret
01238a
+PWD
01238a
+CWD a
01238a
+CWD path
01238a
+EPSV
01238a
+TYPE I
01238a
+SIZE 9750002
01238a
+RETR 9750002
01238a
+QUIT
01238a
+</protocol>
01238a
+</verify>
01238a
+</testcase>
01238a
diff --git a/tests/data/test976 b/tests/data/test976
01238a
new file mode 100644
01238a
index 0000000..3b6fac7
01238a
--- /dev/null
01238a
+++ b/tests/data/test976
01238a
@@ -0,0 +1,89 @@
01238a
+<testcase>
01238a
+<info>
01238a
+<keywords>
01238a
+HTTP
01238a
+--location-trusted
01238a
+</keywords>
01238a
+</info>
01238a
+
01238a
+#
01238a
+# Server-side
01238a
+<reply>
01238a
+<data>
01238a
+HTTP/1.1 301 redirect
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 0
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+Location: http://firsthost.com:9999/a/path/9760002
01238a
+
01238a
+</data>
01238a
+<data2>
01238a
+HTTP/1.1 200 OK
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 4
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+
01238a
+hey
01238a
+</data2>
01238a
+
01238a
+<datacheck>
01238a
+HTTP/1.1 301 redirect
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 0
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+Location: http://firsthost.com:9999/a/path/9760002
01238a
+
01238a
+HTTP/1.1 200 OK
01238a
+Date: Tue, 09 Nov 2010 14:49:00 GMT
01238a
+Server: test-server/fake
01238a
+Content-Length: 4
01238a
+Connection: close
01238a
+Content-Type: text/html
01238a
+
01238a
+hey
01238a
+</datacheck>
01238a
+
01238a
+</reply>
01238a
+
01238a
+#
01238a
+# Client-side
01238a
+<client>
01238a
+<server>
01238a
+http
01238a
+</server>
01238a
+ <name>
01238a
+HTTP with auth redirected to HTTP on a diff port --location-trusted
01238a
+ </name>
01238a
+ <command>
01238a
+-x http://%HOSTIP:%HTTPPORT http://firsthost.com --location-trusted -u joe:secret
01238a
+</command>
01238a
+</client>
01238a
+
01238a
+#
01238a
+# Verify data after the test has been "shot"
01238a
+<verify>
01238a
+<strip>
01238a
+^User-Agent:.*
01238a
+</strip>
01238a
+<protocol>
01238a
+GET http://firsthost.com/ HTTP/1.1
01238a
+Host: firsthost.com
01238a
+Authorization: Basic am9lOnNlY3JldA==
01238a
+Accept: */*
01238a
+Proxy-Connection: Keep-Alive
01238a
+
01238a
+GET http://firsthost.com:9999/a/path/9760002 HTTP/1.1
01238a
+Host: firsthost.com:9999
01238a
+Authorization: Basic am9lOnNlY3JldA==
01238a
+Accept: */*
01238a
+Proxy-Connection: Keep-Alive
01238a
+
01238a
+</protocol>
01238a
+</verify>
01238a
+</testcase>
01238a
-- 
01238a
2.34.1
01238a
01238a
01238a
From cf98bd64b9949c50d4726eb26745c2f7fdf3a075 Mon Sep 17 00:00:00 2001
01238a
From: Daniel Stenberg <daniel@haxx.se>
01238a
Date: Mon, 25 Apr 2022 17:59:15 +0200
01238a
Subject: [PATCH 4/4] openssl: don't leak the SRP credentials in redirects
01238a
 either
01238a
01238a
Follow-up to 620ea21410030
01238a
01238a
Reported-by: Harry Sintonen
01238a
Closes #8751
01238a
01238a
Upstream-commit: 139a54ed0a172adaaf1a78d6f4fff50b2c3f9e08
01238a
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
01238a
---
01238a
 lib/http.c         | 10 +++++-----
01238a
 lib/http.h         |  6 ++++++
01238a
 lib/vtls/openssl.c |  3 ++-
01238a
 3 files changed, 13 insertions(+), 6 deletions(-)
01238a
01238a
diff --git a/lib/http.c b/lib/http.c
01238a
index 39fc7aa..d413738 100644
01238a
--- a/lib/http.c
01238a
+++ b/lib/http.c
01238a
@@ -689,10 +689,10 @@ output_auth_headers(struct connectdata *conn,
01238a
 }
01238a
 
01238a
 /*
01238a
- * allow_auth_to_host() tells if autentication, cookies or other "sensitive
01238a
- * data" can (still) be sent to this host.
01238a
+ * Curl_allow_auth_to_host() tells if authentication, cookies or other
01238a
+ * "sensitive data" can (still) be sent to this host.
01238a
  */
01238a
-static bool allow_auth_to_host(struct connectdata *conn)
01238a
+bool Curl_allow_auth_to_host(struct connectdata *conn)
01238a
 {
01238a
   struct Curl_easy *data = conn->data;
01238a
   return (!data->state.this_is_a_follow ||
01238a
@@ -773,7 +773,7 @@ Curl_http_output_auth(struct connectdata *conn,
01238a
 
01238a
   /* To prevent the user+password to get sent to other than the original host
01238a
      due to a location-follow */
01238a
-  if(allow_auth_to_host(conn)
01238a
+  if(Curl_allow_auth_to_host(conn)
01238a
      || conn->bits.netrc)
01238a
     result = output_auth_headers(conn, authhost, request, path, FALSE);
01238a
   else
01238a
@@ -1789,7 +1789,7 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
01238a
                    checkprefix("Cookie:", headers->data)) &&
01238a
                   /* be careful of sending this potentially sensitive header to
01238a
                      other hosts */
01238a
-                  !allow_auth_to_host(conn))
01238a
+                  !Curl_allow_auth_to_host(conn))
01238a
             ;
01238a
           else {
01238a
             result = Curl_add_bufferf(req_buffer, "%s\r\n", headers->data);
01238a
diff --git a/lib/http.h b/lib/http.h
01238a
index 1d373e8..56a6061 100644
01238a
--- a/lib/http.h
01238a
+++ b/lib/http.h
01238a
@@ -252,5 +252,11 @@ Curl_http_output_auth(struct connectdata *conn,
01238a
                       bool proxytunnel); /* TRUE if this is the request setting
01238a
                                             up the proxy tunnel */
01238a
 
01238a
+/*
01238a
+ * Curl_allow_auth_to_host() tells if authentication, cookies or other
01238a
+ * "sensitive data" can (still) be sent to this host.
01238a
+ */
01238a
+bool Curl_allow_auth_to_host(struct connectdata *conn);
01238a
+
01238a
 #endif /* HEADER_CURL_HTTP_H */
01238a
 
01238a
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
01238a
index 28eaa6d..6c8faa2 100644
01238a
--- a/lib/vtls/openssl.c
01238a
+++ b/lib/vtls/openssl.c
01238a
@@ -2499,7 +2499,8 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
01238a
 #endif
01238a
 
01238a
 #ifdef USE_TLS_SRP
01238a
-  if(ssl_authtype == CURL_TLSAUTH_SRP) {
01238a
+  if((ssl_authtype == CURL_TLSAUTH_SRP) &&
01238a
+     Curl_allow_auth_to_host(conn)) {
01238a
     char * const ssl_username = SSL_SET_OPTION(username);
01238a
 
01238a
     infof(data, "Using TLS-SRP username: %s\n", ssl_username);
01238a
-- 
01238a
2.34.1
01238a