Summary
Traefik's ForwardAuth and snippet-based authentication middleware contain a header-handling flaw that allows attackers to spoof trust-related forwarded headers using underscore variants (e.g., X_Forwarded_Proto) that Traefik fails to sanitize.
When a downstream authentication backend treats underscore and dash header forms equivalently, an attacker can inject a fake trusted scheme or host and bypass authentication on routes that should require valid credentials.
Affected context
This vulnerability affects deployments where:
- Traefik is used as an HTTP reverse proxy in front of applications protected by ForwardAuth or snippet-based authentication middleware, and
- Traefik's forwarded-header sanitization is relied upon to present a trusted request context to an authentication backend, and
- The authentication backend (or downstream app) normalizes or treats
X-Forwarded-*andX_Forwarded_*headers as equivalent.
Under these conditions, alias headers using underscores can carry spoofed "trusted" attributes (such as scheme or host) past Traefik's sanitization logic and into the backend's trust decisions.
Exploit preconditions
- Attack surface: HTTP(S) endpoints fronted by Traefik where ForwardAuth or snippet-based authentication middleware protects routes.
- Required access: Network-level ability to send crafted HTTP requests directly to Traefik, including custom headers.
- Trigger point: Submission of requests containing underscored alias headers (e.g.,
X_Forwarded_Proto,X_Forwarded_Host) that the backend normalizes into canonicalX-Forwarded-*equivalents. - Why exploitation is possible: Traefik's sanitization logic only strips or overwrites canonical header names with dashes and does not normalize or remove underscored variants, while many backends merge or treat these variants as the same header and use them to infer "trusted" context (such as whether the original request was HTTPS or which host was addressed).
Why this happens
The root cause is incomplete normalization and sanitization of forwarded headers in Traefik's authentication-related middleware.
Traefik applies security logic to canonical X-Forwarded-* headers with hyphens, but it does not treat X_Forwarded_* underscore variants as equivalent or untrusted aliases.
This asymmetry creates a discrepancy between Traefik's trust model and that of typical backends, which may normalize header names or accept both forms when deriving security decisions.
Conceptually, this maps to CWE-290: Authentication Bypass by Spoofing, because the attacker can forge a trusted context (e.g., "this request is already authenticated and came over HTTPS") using headers that Traefik fails to sanitize, leading the backend to treat the request as legitimately authenticated.
It is closely related to CWE-306: Missing Authentication for Critical Function, since critical, protected routes can end up exposed without effective authentication when the spoofed headers convince the backend to skip checks.
Potential impact
- Unauthorized access to endpoints that are intended to be protected by ForwardAuth or snippet-based authentication.
- Bypass of single sign-on (SSO) or external authentication flows for specific routes or entire applications.
- Impersonation of trusted request attributes (e.g., HTTPS scheme, internal host, or original client IP) that influence authorization logic.
- Exposure of sensitive data or administrative interfaces to unauthenticated users.
- Ability for attackers to pivot within internal services that rely on Traefik's sanitized headers for security decisions.
General mitigation guidance
Effective mitigation focuses on aligning header normalization across the proxy and backend and reducing trust in client-controlled forwarded headers:
- Normalize header handling so that all variants of forwarded headers (dash and underscore forms) are treated consistently, ideally by rejecting or stripping unrecognized or ambiguous forms at the edge.
- Harden authentication middleware and backends to avoid trusting client-supplied
X-Forwarded-*or similar headers unless they originate from a known, authenticated proxy path. - Prefer explicit, secure context propagation mechanisms (such as dedicated authentication tokens, signed headers, or mTLS-based identity) over inferred trust from forwarded headers.
- Apply a deny-by-default policy for non-canonical header names in security-sensitive code paths, including ForwardAuth integrations and custom middleware snippets.
- Use least-privilege design on routes: even if a request appears "internal" or "already authenticated" based on headers, sensitive operations should still enforce strong, direct authentication and authorization.
How teams detect issues like this
Detection generally involves reviewing how forwarded headers are handled and ensuring header aliasing does not undermine authentication:
- Static analysis / configuration review: Look for Traefik configurations and snippets that rely on
X-Forwarded-*values to gate access, and verify that no logic considers underscore and dash variants equivalently without explicit sanitization. - Code review signals in backends: Identify frameworks or middleware that normalize header names (e.g., converting underscores to dashes) and then use
X-Forwarded-*headers to decide whether to enforce authentication. - Security testing: Use automated or manual tests to send requests with both hyphenated and underscored forwarded headers, observing whether any authenticated-only route becomes accessible without valid credentials.
- Monitoring and logging: Enable detailed access logs and authentication logs that include raw request headers where feasible, and set up alerts for anomalous patterns such as frequent use of
X_Forwarded_*headers on protected endpoints. - Automated policy enforcement: Integrate HTTP gateway or WAF rules that normalize or drop ambiguous forwarding headers and flag configuration changes that weaken header sanitization behavior.

