/

CVE-2026-40895

Severity:

HIGH RISK

(7.5)

Information Exposure / Sensitive Data Leakage

CVE-2026-40895

Modified

Vulnerability type

Category:

Information Exposure / Sensitive Data Leakage

CWE:

CWE-200, CWE-212

Impact:

Exposure of Authentication Credentials and API Tokens

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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 to Authorization, 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.

Sources

SourceLink
github.comgithub.com/follow-redirects/follow-redirects/commit/844c4d302ac963d29bdb5dc1754ec7df3d70d7f9
github.comgithub.com/follow-redirects/follow-redirects/security/advisories/GHSA-r4q5-vmmm-2653
access.redhat.comaccess.redhat.com/errata/RHSA-2026:13826
access.redhat.comaccess.redhat.com/errata/RHSA-2026:14937
access.redhat.comaccess.redhat.com/errata/RHSA-2026:16476
access.redhat.comaccess.redhat.com/errata/RHSA-2026:16532
access.redhat.comaccess.redhat.com/errata/RHSA-2026:16534
access.redhat.comaccess.redhat.com/errata/RHSA-2026:16535
access.redhat.comaccess.redhat.com/errata/RHSA-2026:16542
access.redhat.comaccess.redhat.com/errata/RHSA-2026:16874
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17657
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17699
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17789
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19109
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19375
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19712
access.redhat.comaccess.redhat.com/errata/RHSA-2026:20889
access.redhat.comaccess.redhat.com/errata/RHSA-2026:20938
access.redhat.comaccess.redhat.com/errata/RHSA-2026:21017
access.redhat.comaccess.redhat.com/errata/RHSA-2026:21338
access.redhat.comaccess.redhat.com/errata/RHSA-2026:21772
access.redhat.comaccess.redhat.com/errata/RHSA-2026:22465
access.redhat.comaccess.redhat.com/errata/RHSA-2026:22629
access.redhat.comaccess.redhat.com/errata/RHSA-2026:22840
access.redhat.comaccess.redhat.com/errata/RHSA-2026:23361
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24536
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24539
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24766
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24853
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24977
access.redhat.comaccess.redhat.com/errata/RHSA-2026:25271
access.redhat.comaccess.redhat.com/errata/RHSA-2026:25273
access.redhat.comaccess.redhat.com/errata/RHSA-2026:26010
access.redhat.comaccess.redhat.com/errata/RHSA-2026:27004
access.redhat.comaccess.redhat.com/errata/RHSA-2026:27044
access.redhat.comaccess.redhat.com/errata/RHSA-2026:27063
access.redhat.comaccess.redhat.com/errata/RHSA-2026:36882
access.redhat.comaccess.redhat.com/errata/RHSA-2026:40768
access.redhat.comaccess.redhat.com/errata/RHSA-2026:41928
access.redhat.comaccess.redhat.com/errata/RHSA-2026:44235
access.redhat.comaccess.redhat.com/errata/RHSA-2026:44263
access.redhat.comaccess.redhat.com/errata/RHSA-2026:44267
access.redhat.comaccess.redhat.com/errata/RHSA-2026:47728
access.redhat.comaccess.redhat.com/errata/RHSA-2026:48699
access.redhat.comaccess.redhat.com/errata/RHSA-2026:50300
access.redhat.comaccess.redhat.com/errata/RHSA-2026:65126
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-40895
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2460297
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-40895.json

Frequently asked

questions

Yes. An attacker who controls or can influence a redirecting server can trigger the client to follow cross-domain redirects and capture any custom authentication headers that are forwarded, without needing direct access to the victim application.

They need the ability to cause the application to make HTTP(S) requests to a domain they control or influence, and then return a redirect response to another host. This could arise through user-controlled URLs, compromised upstream services, DNS hijacking, or malicious third-party endpoints.

The safest pattern is to avoid sending authentication tokens on requests that may follow cross-domain redirects, and to enforce strict header-stripping or allowlisting when redirects do occur. HTTP clients should treat all auth-related headers as sensitive and avoid forwarding them to different domains by default.

Preventive measures include designing HTTP client abstractions with secure-by-default redirect handling, conducting security reviews focused on header and redirect behavior, and using threat modeling to identify where credentials might cross trust boundaries. Additionally, standardizing on consistent header names for authentication within your organization can make it easier to enforce robust filtering rules and static analysis checks.

Find out what's already
exploitable in your codebase.