follow-redirects: Array-form header credential stripping bypass
The follow-redirects library fails to strip sensitive headers when provided in array format, leading to the unauthorized disclosure of credentials during cross-origin or protocol-downgrade redirects.
CVE search metadata
CVE search record: CVE-2026-40895. Severity: high. CVSS: 7.5. EPSS: 0.82%. KEV: no. Product: follow-redirects (<= 1.16.0). Brief: follow-redirects: Array-form header credential stripping bypass. Brief link: https://feed.craftedsignal.io/briefs/2026-10-follow-redirects-bypass/
Triage facts
Revision 1- Applicability
- follow-redirects (<= 1.16.0)
- Evidence
- Unknown
- Severity
- High
- Action
- Elevated
- Sources
- 2 public sources
- Freshness
- Revision 1Oct 20, 23:56 UTC
- Vulnerabilities
- 1 CVE
- Source quality
- A1Likely
The follow-redirects library, a popular drop-in replacement for Node.js's native http/https modules, contains a vulnerability where sensitive header-stripping mechanisms fail when headers are provided as an array rather than a plain object. The internal removeMatchingHeaders function utilizes a for...in loop to iterate over the headers container. While this correctly matches keys in an object, it iterates over numeric indices when applied to an array, causing the header-matching regular expressions to consistently fail.
This flaw affects the security controls intended to protect credentials (Authorization, Cookie, Proxy-Authorization) and user-declared sensitiveHeaders (introduced in CVE-2026-40895) when a request is redirected to a different origin or a less secure protocol. Because the library silently fails to sanitize these headers, the credentials are forwarded verbatim to the attacker-controlled redirect destination. This vulnerability enables unauthenticated credential harvesting and persists in all versions of the library up to and including 1.16.0.
Attack Chain
- The victim application is configured to use
follow-redirectsfor outgoing HTTP/HTTPS requests. - The application initiates a request to a malicious or compromised server, providing credentials via array-form headers (e.g.,
["Authorization", "Bearer token", "Cookie", "session=id"]). - The malicious server responds with a 302 or similar redirect status code pointing to an attacker-controlled cross-origin host or a protocol-downgrade (HTTPS to HTTP) endpoint.
follow-redirectsintercepts the redirect and invokesremoveMatchingHeadersto strip sensitive credentials and the originalHostheader.- The
removeMatchingHeadersfunction iterates over the array-form headers usingfor...in, yielding numeric indices instead of header names, which results in zero matches. - The sanitization logic fails silently; the library retains the original credential headers and the stale
Hostheader in the options object. - The library follows the redirect, sending the request to the attacker's server with the victim's credentials included in the headers.
- The attacker logs the incoming request headers to harvest the victim's tokens, session cookies, or API keys.
Impact
The vulnerability results in the unauthorized disclosure of sensitive authentication material to third-party servers. Any application utilizing follow-redirects that processes user-controllable or untrusted redirects is susceptible to credential harvesting. This impacts the confidentiality of session identifiers, API keys, and authorization tokens across any sector relying on the library for automated HTTP request handling.
Recommendation
- Update to a version of
follow-redirectsthat implements explicit validation for array-form headers, ensuring either proper sanitization or a clearTypeErrorif array-form input is detected. - Audit applications using
follow-redirectsto determine if outgoing requests are constructed using array-form headers (e.g.,["Name", "Value"]). - Implement strict cross-origin checks or proxying for sensitive traffic if an immediate patch is not feasible.
- Ensure all developers explicitly use object-form headers (
{ "Authorization": "value" }) until the library explicitly validates array-form header structures.
Immediate actions
Audit codebase for use of follow-redirects with array-form headers in request configuration
Threat Hunt
Search for outgoing HTTP requests utilizing follow-redirects where 'headers' property is passed as an array.
Data: Codebase search/static analysis
Mitigations
Enforce object-based header definitions in all outgoing requests utilizing follow-redirects
follow-redirects credential stripping bypass