From 5e661767339f1c300b01dc7e0cffe5a8290324a5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 28 May 2026 10:14:08 +0200 Subject: [PATCH] http: don't pass on set cookies to new origins Verified by test 2015 Reported-by: azraelxuemo on hackerone Closes #21794 --- lib/http.c | 3 +- tests/data/Makefile.am | 2 +- tests/data/test2015 | 91 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 tests/data/test2015 diff --git a/lib/http.c b/lib/http.c index c9fb9995c0..26f5280502 100644 --- a/lib/http.c +++ b/lib/http.c @@ -2530,7 +2530,8 @@ static CURLcode http_cookies(struct Curl_easy *data, char *addcookies = NULL; bool linecap = FALSE; if(data->set.str[STRING_COOKIE] && - !Curl_checkheaders(data, STRCONST("Cookie"))) + !Curl_checkheaders(data, STRCONST("Cookie")) && + Curl_auth_allowed_to_host(data)) addcookies = data->set.str[STRING_COOKIE]; if(data->cookies || addcookies) { diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 4887a3594a..058be3d734 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -245,7 +245,7 @@ test1970 test1971 test1972 test1973 test1974 test1975 test1976 test1977 \ test1978 test1979 test1980 test1981 test1982 test1983 test1984 \ \ test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \ -test2008 test2009 test2010 test2011 test2012 test2013 test2014 \ +test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \ \ test2023 \ test2024 test2025 test2026 test2027 test2028 test2029 test2030 test2031 \ diff --git a/tests/data/test2015 b/tests/data/test2015 new file mode 100644 index 0000000000..6cd758471e --- /dev/null +++ b/tests/data/test2015 @@ -0,0 +1,91 @@ + + + + +HTTP +HTTP proxy +followlocation +cookies + + +# Server-side + + +HTTP/1.1 302 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake swsclose +Content-Type: text/html +Funny-head: yesyes +Location: http://goto.second.host.now/%TESTNUMBER0002 +Content-Length: 8 +Connection: close + +contents + + +HTTP/1.1 200 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake swsclose +Content-Type: text/html +Funny-head: yesyes +Content-Length: 9 + +contents + + + +HTTP/1.1 302 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake swsclose +Content-Type: text/html +Funny-head: yesyes +Location: http://goto.second.host.now/%TESTNUMBER0002 +Content-Length: 8 +Connection: close + +HTTP/1.1 200 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake swsclose +Content-Type: text/html +Funny-head: yesyes +Content-Length: 9 + +contents + + + +# Client-side + + +http + + +HTTP with cookie with with -b and redirect to new host + + +http://first.host.it.is/we/want/that/page/%TESTNUMBER -x %HOSTIP:%HTTPPORT -b "test=yes" --location + + +proxy + + + +# Verify data after the test has been "shot" + + +GET http://first.host.it.is/we/want/that/page/%TESTNUMBER HTTP/1.1 +Host: first.host.it.is +User-Agent: curl/%VERSION +Accept: */* +Proxy-Connection: Keep-Alive +Cookie: test=yes + +GET http://goto.second.host.now/%TESTNUMBER0002 HTTP/1.1 +Host: goto.second.host.now +User-Agent: curl/%VERSION +Accept: */* +Proxy-Connection: Keep-Alive + + + +