VYPR
Low severityNVD Advisory· Published Oct 12, 2023· Updated Feb 13, 2025

Undici's cookie header not cleared on cross-origin redirect in fetch

CVE-2023-45143

Description

Undici is an HTTP/1.1 client written from scratch for Node.js. Prior to version 5.26.2, Undici already cleared Authorization headers on cross-origin redirects, but did not clear Cookie headers. 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 third-party site or a malicious attacker who can control the redirection target (ie. an open redirector) to leak the cookie to the third party site. This was patched in version 5.26.2. There are no known workarounds.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
undicinpm
< 5.26.25.26.2

Affected products

1

Patches

1
e041de359221

Merge pull request from GHSA-wqq4-5wpv-mx2g

https://github.com/nodejs/undiciKhafraOct 11, 2023via ghsa
2 files changed · +52 0
  • lib/fetch/index.js+4 0 modified
    @@ -1200,6 +1200,10 @@ async function httpRedirectFetch (fetchParams, response) {
       if (!sameOrigin(requestCurrentURL(request), locationURL)) {
         // https://fetch.spec.whatwg.org/#cors-non-wildcard-request-header-name
         request.headersList.delete('authorization')
    +
    +    // "Cookie" and "Host" are forbidden request-headers, which undici doesn't implement.
    +    request.headersList.delete('cookie')
    +    request.headersList.delete('host')
       }
     
       // 14. If request’s body is non-null, then set request’s body to the first return
    
  • test/fetch/redirect-cross-origin-header.js+48 0 added
    @@ -0,0 +1,48 @@
    +'use strict'
    
    +
    
    +const { test } = require('tap')
    
    +const { createServer } = require('http')
    
    +const { once } = require('events')
    
    +const { fetch } = require('../..')
    
    +
    
    +test('Cross-origin redirects clear forbidden headers', async (t) => {
    
    +  t.plan(5)
    
    +
    
    +  const server1 = createServer((req, res) => {
    
    +    t.equal(req.headers.cookie, undefined)
    
    +    t.equal(req.headers.authorization, undefined)
    
    +
    
    +    res.end('redirected')
    
    +  }).listen(0)
    
    +
    
    +  const server2 = createServer((req, res) => {
    
    +    t.equal(req.headers.authorization, 'test')
    
    +    t.equal(req.headers.cookie, 'ddd=dddd')
    
    +
    
    +    res.writeHead(302, {
    
    +      ...req.headers,
    
    +      Location: `http://localhost:${server1.address().port}`
    
    +    })
    
    +    res.end()
    
    +  }).listen(0)
    
    +
    
    +  t.teardown(() => {
    
    +    server1.close()
    
    +    server2.close()
    
    +  })
    
    +
    
    +  await Promise.all([
    
    +    once(server1, 'listening'),
    
    +    once(server2, 'listening')
    
    +  ])
    
    +
    
    +  const res = await fetch(`http://localhost:${server2.address().port}`, {
    
    +    headers: {
    
    +      Authorization: 'test',
    
    +      Cookie: 'ddd=dddd'
    
    +    }
    
    +  })
    
    +
    
    +  const text = await res.text()
    
    +  t.equal(text, 'redirected')
    
    +})
    
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

19

News mentions

0

No linked articles in our index yet.