CVE-2026-40895: follow-redirects leaks Custom Authentication Headers to Cross-Domain Redirect Targets
Summary
When an HTTP request follows a cross-domain redirect (301/302/307/308), follow-redirects only strips authorization, proxy-authorization, and cookie headers (matched by regex at index.js:469-476). Any custom authentication header (e.g., X-API-Key, X-Auth-Token, Api-Key, Token) is forwarded verbatim to the redirect target.
Since follow-redirects is the redirect-handling dependency for axios (105K+ stars), this vulnerability affects the entire axios ecosystem.
Affected Code
index.js, lines 469-476:
javascript if (redirectUrl.protocol !== currentUrlParts.protocol && redirectUrl.protocol !== "https:" || redirectUrl.host !== currentHost && !isSubdomain(redirectUrl.host, currentHost)) { removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i, this.options.headers); }
The regex only matches authorization, proxy-authorization, and cookie. Custom headers like X-API-Key are not matched.
Attack Scenario
1. App uses axios with custom auth header: headers: { 'X-API-Key': 'sk-live-secret123' } 2. Server returns 302 Location: https://evil.com/steal 3. follow-redirects sends X-API-Key: sk-live-secret123 to evil.com 4. Attacker captures the API key
Impact
Any custom auth header set via axios leaks on cross-domain redirect. Extremely common pattern. Affects all axios users in Node.js.
Suggested Fix
Add a sensitiveHeaders option that users can extend, or strip ALL non-standard headers on cross-domain redirect.
Disclosure
Source code review, manually verified. Found 2026-03-20.
Other sources
follow-redirects is an open source, drop-in replacement for Node's http and https modules that automatically follows redirects. Prior to 1.16.0, when an HTTP request follows a cross-domain redirect (301/302/307/308), follow-redirects only strips authorization, proxy-authorization, and cookie headers (matched by regex at index.js). Any custom authentication header (e.g., X-API-Key, X-Auth-Token, Api-Key, Token) is forwarded verbatim to the redirect target. This vulnerability is fixed in 1.16.0.
— Debian
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/follow-redirectsto a version that resolves this vulnerability.Fixed in 1.16.0 - Upgrade
Upgrade
debian/node-follow-redirectsto a version that resolves this vulnerability.Fixed in 1.16.0+~1.14.4-1 - Upgrade
Upgrade
debian/node-follow-redirectsto a version that resolves this vulnerability.Fixed in 1.16.1+~1.14.4-1 - Upgrade
Upgrade
follow-redirectsto a version that resolves this vulnerability.Fixed in 1.16.0
Event History
Frequently Asked Questions
What are the details of CVE-2026-40895?
CVE-2026-40895 identifies a vulnerability in the 'follow-redirects' NPM package that causes custom authentication headers to leak when following cross-domain redirects.
What is the severity of CVE-2026-40895?
CVE-2026-40895 has a moderate severity level due to its potential to expose sensitive information.
How do I fix CVE-2026-40895?
To fix CVE-2026-40895, upgrade the 'follow-redirects' package to version 1.16.0 or later.
Which versions of 'follow-redirects' are affected by CVE-2026-40895?
CVE-2026-40895 affects all versions of 'follow-redirects' prior to 1.16.0.
What types of redirects are involved in CVE-2026-40895?
CVE-2026-40895 involves HTTP responses with redirect status codes 301, 302, or 303.