Summary
The follow-redirects library for Node.js failed to strip custom authentication headers when following cross-domain HTTP redirects.
As a result, sensitive API keys or tokens could be unintentionally forwarded to third-party hosts, exposing credentials to untrusted domains during redirect chains.
Affected context
This vulnerability affects applications using the follow-redirects library as a drop-in replacement for Node's http and https modules when making outbound HTTP(S) requests.
It becomes relevant when:
- The application follows 301/302/307/308 redirects across different domains (cross-origin), and
- The client uses custom authentication headers (e.g.,
X-API-Key,X-Auth-Token,Api-Key,Token) instead of or in addition toAuthorization,Proxy-Authorization, or cookies.
In such scenarios, those custom headers may be forwarded to the redirect target, even when that target is a separate, potentially untrusted domain.
Exploit preconditions
- Attack surface: Outbound HTTP(S) requests issued by a Node.js application that uses follow-redirects.
- Required access: Ability for an attacker to influence redirect responses (e.g., control or intercept a server that issues HTTP 301/302/307/308 responses) or cause the client to contact a malicious domain that returns controlled redirects.
- Trigger point: The library processes an HTTP redirect to a different domain and automatically forwards request headers to the new location.
- Why exploitation is possible: follow-redirects only stripped a limited set of known sensitive headers (Authorization, Proxy-Authorization, Cookie) based on regex matching. Other headers commonly used for authentication were not recognized as sensitive and were forwarded unchanged, allowing a redirecting server to receive secrets intended solely for the original host.
Why this happens
The core issue is incomplete sanitization of sensitive headers during cross-domain redirect handling.
The library implemented a rule-based approach that removed only a small subset of known credentials (e.g., Authorization and cookies) when following redirects to a different domain.
This behavior maps to CWE-200: Exposure of Sensitive Information to an Unauthorized Actor, as the software disclosed authentication data to redirect targets that were not authorized recipients.
Conceptually, the bug arises from assuming that only a few canonical header names can contain secrets, while modern APIs commonly rely on arbitrary or custom header names for tokens and keys.
Potential impact
- Leakage of API keys, bearer tokens, or other credentials in custom headers to third-party domains.
- Unauthorized access to protected APIs or backend services if a malicious redirect target captures and reuses leaked credentials.
- Lateral movement across services that share or trust the leaked authentication scheme.
- Long-lived credential compromise leading to data exfiltration, account takeover, or abuse of rate-limited APIs.
- Difficulty in incident response due to credentials leaking over HTTPS connections that are not easily observable in transit.
General mitigation guidance
Effective mitigation generally involves tightening how redirects and sensitive headers are handled:
- Treat any header that conveys authentication or authorization data as sensitive, regardless of its name, and avoid automatically forwarding it across domains.
- Implement an explicit allowlist of headers that may be forwarded on cross-domain redirects, instead of a blocklist of "sensitive" names.
- Introduce policy controls in HTTP client code to disable automatic cross-domain redirects for requests carrying sensitive credentials, or require explicit opt-in.
- Design authentication schemes so that long-lived secrets are not sent to arbitrary hosts (e.g., use scoped, short-lived tokens with strict audience restrictions).
- Apply least privilege to issued credentials so that any accidentally leaked key has limited impact and can be rotated quickly.
How teams detect issues like this
Potential detection approaches include:
- Static analysis and code review:
- Flag usage of HTTP clients that automatically follow redirects without per-domain header policies.
- Look for patterns where custom authentication headers (e.g.,
X-API-Key,X-Auth-*) are set on generic client instances reused across domains. - Review redirect-handling middleware or wrappers for incomplete header filtering logic or overly permissive forwarding behavior.
- Runtime and logging analysis:
- Instrument HTTP client libraries to log when requests with sensitive headers are redirected to a different domain (without logging the secret values themselves).
- Monitor for unusual outbound traffic patterns where protected APIs are contacted via domains that should not receive credentials.
- Policy enforcement:
- Use internal security guidelines or automated CI checks to require explicit configuration for cross-domain redirects and header forwarding rules.
- Incorporate automated security testing tools that can simulate redirect scenarios and assert that sensitive headers are stripped.

