Traefik ForwardAuth Authentication Bypass via X-Forwarded-Prefix Spoofing
A high-severity authentication bypass vulnerability exists in Traefik's `ForwardAuth` middleware when `trustForwardHeader=false` is configured and Traefik is deployed behind a trusted upstream proxy; Traefik fails to sanitize the `X-Forwarded-Prefix` header, allowing attackers to spoof a trusted prefix value and gain unauthorized access to protected backend routes.
A critical authentication bypass vulnerability impacts Traefik instances utilizing the ForwardAuth middleware with trustForwardHeader=false, when deployed behind a trusted upstream proxy. This vulnerability arises from Traefik’s failure to properly sanitize the X-Forwarded-Prefix header. Although Traefik correctly rebuilds other X-Forwarded-* headers like X-Forwarded-For and X-Forwarded-Host, it does not strip or rebuild X-Forwarded-Prefix. An attacker can inject a malicious X-Forwarded-Prefix value, which is then passed to the authentication service in the subrequest. If the authentication service relies on the X-Forwarded-Prefix header for authorization decisions, an attacker can bypass access controls and reach protected backend routes. This issue affects Traefik versions v2.11.x before v2.11.43, v3.6.x before v3.6.14, and v3.7.0-rc.1.
Attack Chain
- An attacker sends a request with a crafted
X-Forwarded-Prefixheader (e.g.,X-Forwarded-Prefix: /admin) to a trusted upstream proxy (e.g., nginx). - The trusted proxy forwards the request to the Traefik instance.
- Traefik’s
StripPrefixmiddleware processes the request, stripping a configured prefix (e.g.,/forbidden) and appending it to theX-Forwarded-Prefixheader usingHeader.Add. - The
ForwardAuthmiddleware creates a subrequest to the authentication service, copying all incoming headers, including the attacker-controlledX-Forwarded-Prefixand theStripPrefix-added value. - The authentication service receives the subrequest with the concatenated
X-Forwarded-Prefixvalues, where the attacker’s value appears first (e.g.,X-Forwarded-Prefix: /admin, /forbidden). - The authentication service incorrectly uses the attacker-supplied
/adminprefix to make authorization decisions. - The authentication service authorizes the request due to the spoofed prefix.
- Traefik forwards the request to the protected backend route, granting the attacker unauthorized access.
Impact
Successful exploitation allows unauthenticated attackers to bypass access controls and gain unauthorized access to protected backend routes. This can lead to data breaches, unauthorized modification of resources, and other security compromises. The impact is especially severe in environments where StripPrefix is used before ForwardAuth, and where the authentication service relies heavily on the X-Forwarded-Prefix header for authorization decisions. The number of affected deployments is unknown but likely significant, given Traefik’s popularity as a reverse proxy and load balancer.
Recommendation
- Upgrade to Traefik version v2.11.43, v3.6.14, or v3.7.0-rc.2 or later to patch the vulnerability.
- As a workaround, if upgrading is not immediately feasible, configure your authentication service to validate and sanitize the
X-Forwarded-Prefixheader, ensuring it only trusts values originating from the trusted proxy. - Implement the following Sigma rule to detect suspicious requests with the
X-Forwarded-Prefixheader targeting the/forbiddenpath, indicating potential exploitation attempts. - Review and harden your Traefik configuration to ensure that the
trustForwardHeaderparameter is appropriately set based on your deployment environment and trust relationships. - Monitor Traefik access logs for suspicious activity, especially requests with unusual
X-Forwarded-Prefixvalues, using thewebserverlog source.
Detection coverage 2
Detect Suspicious X-Forwarded-Prefix Header in Traefik Access Logs
highDetects requests with a suspicious X-Forwarded-Prefix header targeting the /forbidden path, potentially indicating an authentication bypass attempt.
Detect Malicious X-Forwarded-Prefix Value
mediumDetects requests containing '/admin' in the X-Forwarded-Prefix Header.
Detection queries are kept inside the platform. Get full rules →