Skip to content

Commit 5e66176

Browse files
committed
http: don't pass on set cookies to new origins
Verified by test 2015 Reported-by: azraelxuemo on hackerone Closes curl#21794
1 parent a0c559f commit 5e66176

3 files changed

Lines changed: 94 additions & 2 deletions

File tree

lib/http.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,8 @@ static CURLcode http_cookies(struct Curl_easy *data,
25302530
char *addcookies = NULL;
25312531
bool linecap = FALSE;
25322532
if(data->set.str[STRING_COOKIE] &&
2533-
!Curl_checkheaders(data, STRCONST("Cookie")))
2533+
!Curl_checkheaders(data, STRCONST("Cookie")) &&
2534+
Curl_auth_allowed_to_host(data))
25342535
addcookies = data->set.str[STRING_COOKIE];
25352536

25362537
if(data->cookies || addcookies) {

tests/data/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ test1970 test1971 test1972 test1973 test1974 test1975 test1976 test1977 \
245245
test1978 test1979 test1980 test1981 test1982 test1983 test1984 \
246246
\
247247
test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \
248-
test2008 test2009 test2010 test2011 test2012 test2013 test2014 \
248+
test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \
249249
\
250250
test2023 \
251251
test2024 test2025 test2026 test2027 test2028 test2029 test2030 test2031 \

tests/data/test2015

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="US-ASCII"?>
2+
<testcase>
3+
<info>
4+
<keywords>
5+
HTTP
6+
HTTP proxy
7+
followlocation
8+
cookies
9+
</keywords>
10+
</info>
11+
# Server-side
12+
<reply>
13+
<data>
14+
HTTP/1.1 302 OK
15+
Date: Tue, 09 Nov 2010 14:49:00 GMT
16+
Server: test-server/fake swsclose
17+
Content-Type: text/html
18+
Funny-head: yesyes
19+
Location: http://goto.second.host.now/%TESTNUMBER0002
20+
Content-Length: 8
21+
Connection: close
22+
23+
contents
24+
</data>
25+
<data2>
26+
HTTP/1.1 200 OK
27+
Date: Tue, 09 Nov 2010 14:49:00 GMT
28+
Server: test-server/fake swsclose
29+
Content-Type: text/html
30+
Funny-head: yesyes
31+
Content-Length: 9
32+
33+
contents
34+
</data2>
35+
36+
<datacheck>
37+
HTTP/1.1 302 OK
38+
Date: Tue, 09 Nov 2010 14:49:00 GMT
39+
Server: test-server/fake swsclose
40+
Content-Type: text/html
41+
Funny-head: yesyes
42+
Location: http://goto.second.host.now/%TESTNUMBER0002
43+
Content-Length: 8
44+
Connection: close
45+
46+
HTTP/1.1 200 OK
47+
Date: Tue, 09 Nov 2010 14:49:00 GMT
48+
Server: test-server/fake swsclose
49+
Content-Type: text/html
50+
Funny-head: yesyes
51+
Content-Length: 9
52+
53+
contents
54+
</datacheck>
55+
</reply>
56+
57+
# Client-side
58+
<client>
59+
<server>
60+
http
61+
</server>
62+
<name>
63+
HTTP with cookie with with -b and redirect to new host
64+
</name>
65+
<command>
66+
http://first.host.it.is/we/want/that/page/%TESTNUMBER -x %HOSTIP:%HTTPPORT -b "test=yes" --location
67+
</command>
68+
<features>
69+
proxy
70+
</features>
71+
</client>
72+
73+
# Verify data after the test has been "shot"
74+
<verify>
75+
<protocol crlf="headers">
76+
GET http://first.host.it.is/we/want/that/page/%TESTNUMBER HTTP/1.1
77+
Host: first.host.it.is
78+
User-Agent: curl/%VERSION
79+
Accept: */*
80+
Proxy-Connection: Keep-Alive
81+
Cookie: test=yes
82+
83+
GET http://goto.second.host.now/%TESTNUMBER0002 HTTP/1.1
84+
Host: goto.second.host.now
85+
User-Agent: curl/%VERSION
86+
Accept: */*
87+
Proxy-Connection: Keep-Alive
88+
89+
</protocol>
90+
</verify>
91+
</testcase>

0 commit comments

Comments
 (0)