Описание
Traefik's ForwardAuth trustForwardHeader=false allows spoofed X-Forwarded-Prefix to bypass authentication
Summary
There is a high-severity authentication bypass vulnerability in Traefik's ForwardAuth middleware when trustForwardHeader=false is configured and Traefik is deployed behind a trusted upstream proxy.
While X-Forwarded-* headers (such as X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto) from trusted context are correctly rebuilt, it does not strip or rebuild X-Forwarded-Prefix, leaving any attacker-supplied value intact in the subrequest forwarded to the authentication service.
When the authentication service makes authorization decisions based on X-Forwarded-Prefix, an external attacker can spoof a trusted prefix value and gain unauthorized access to protected backend routes.
Patches
- https://github.com/traefik/traefik/releases/tag/v2.11.43
- https://github.com/traefik/traefik/releases/tag/v3.6.14
- https://github.com/traefik/traefik/releases/tag/v3.7.0-rc.2
For more information
If there are any questions or comments about this advisory, please open an issue.
Original Description
Summary
ForwardAuth with trustForwardHeader=false still forwards an attacker-controlled X-Forwarded-Prefix header to the authentication service when Traefik is deployed behind a trusted upstream proxy. If the auth service relies on X-Forwarded-Prefix for authorization or routing decisions, an external attacker can bypass access controls and reach protected backend routes.
This was validated this against Traefik v3.6.12 using the official Docker image and a minimal local Docker setup. A direct request to Traefik is correctly rejected, but the same request succeeds when sent through a trusted reverse proxy, which shows the issue is in the ForwardAuth subrequest handling rather than general ingress header stripping.
Details
The vulnerable behavior comes from the way Traefik builds the subrequest sent to the forward-auth server.
In pkg/middlewares/auth/forward.go, writeHeader first copies all incoming request headers into the auth subrequest:
It then selectively rebuilds only a subset of forwarded headers when trustForwardHeader=false, for example:
X-Forwarded-ForX-Forwarded-MethodX-Forwarded-ProtoX-Forwarded-PortX-Forwarded-HostX-Forwarded-Uri
However, it does not remove or rebuild X-Forwarded-Prefix, so an attacker-supplied value remains in the auth request even when forwarded headers are supposed to be untrusted.
This becomes security-relevant when StripPrefix is used before ForwardAuth. In pkg/middlewares/stripprefix/strip_prefix.go, Traefik appends the stripped prefix using Header.Add:
If the attacker already sent X-Forwarded-Prefix: /admin, and StripPrefix later adds /forbidden, the auth service receives both values in this order:
/admin(attacker-controlled)/forbidden(Traefik-generated)
An auth service that uses the first X-Forwarded-Prefix value can therefore be tricked into authorizing a protected route.
Why this appears unintended:
- The docs say
trustForwardHeadermeans "Trust all X-Forwarded-* headers" and defaults tofalse. - The migration notes say
X-Forwarded-Prefixis handled like otherX-Forwarded-*headers and removed from untrusted sources. - The direct-to-Traefik test case behaves consistently with that expectation and returns
403. - Only the auth subrequest path still honors the spoofed
X-Forwarded-Prefix.
Relevant source/documentation locations:
pkg/middlewares/auth/forward.golines 393-459pkg/middlewares/stripprefix/strip_prefix.golines 65-68pkg/middlewares/forwardedheaders/forwarded_header.golines 15-43docs/content/reference/routing-configuration/http/middlewares/forwardauth.mdlines 59-62 and 130-140docs/content/migrate/v3.mdlines 192-196
This was only tested and validated with X-Forwarded-Prefix. By source review, other forwarded headers that are copied but not rebuilt in writeHeader may deserve separate review, but I am not claiming impact for them here.
PoC
The following uses the official traefik:v3.6.12 Docker image and a mounted traefik.toml, matching the documented deployment style.
- Create
traefik.toml:
- Create
dynamic.toml:
- Create
auth.py:
- Create
frontend.conf:
- Start the containers:
- Send three requests:
Direct to Traefik, spoofed header:
Expected result:
Through trusted proxy, no spoofing:
Expected result:
Through trusted proxy, spoofed header:
Observed result:
The backend response confirms that the request reached the protected upstream after the auth service accepted the attacker-controlled prefix.
- Optional log confirmation from the auth service:
Observed log sequence:
- Cleanup:
Impact
This is an authentication bypass / trust-boundary bypass.
Affected deployments are those that:
- run Traefik behind a trusted upstream proxy
- use
ForwardAuth - rely on
trustForwardHeader=falseto avoid trusting client-supplied forwarded headers - pass
X-Forwarded-Prefixto the auth service, which happens by default whenauthRequestHeadersis empty - make authorization or routing decisions based on
X-Forwarded-Prefix, especially whenStripPrefixruns beforeForwardAuthIn those environments, an unauthenticated external attacker can influence the auth service's view of the protected path and gain access to backend routes that should be denied.
Пакеты
github.com/traefik/traefik/v3
>= 3.7.0-ea.1, < 3.7.0-rc.2
3.7.0-rc.2
github.com/traefik/traefik/v3
>= 3.0.0-beta1, < 3.6.14
3.6.14
github.com/traefik/traefik/v2
< 2.11.43
2.11.43
github.com/traefik/traefik
<= 1.7.34
Отсутствует
Связанные уязвимости
Traefik is an HTTP reverse proxy and load balancer. Prior to versions 2.11.43, 3.6.14, and 3.7.0-rc.2, there is an authentication bypass vulnerability in Traefik's ForwardAuth middleware when trustForwardHeader=false is configured and Traefik is deployed behind a trusted upstream proxy. This issue has been patched in versions 2.11.43, 3.6.14, and 3.7.0-rc.2.
Traefik is an HTTP reverse proxy and load balancer. Prior to versions 2.11.43, 3.6.14, and 3.7.0-rc.2, there is an authentication bypass vulnerability in Traefik's ForwardAuth middleware when trustForwardHeader=false is configured and Traefik is deployed behind a trusted upstream proxy. This issue has been patched in versions 2.11.43, 3.6.14, and 3.7.0-rc.2.
Traefik is an HTTP reverse proxy and load balancer. Prior to versions ...
Уязвимость промежуточного программного обеспечения ForwardAuth обратного прокси сервера Containous Traefik, позволяющая нарушителю получить несанкционированный доступ к защищаемой информации