The vulnerability lies in Traefik's ForwardAuth middleware, which fails to properly sanitize X-Forwarded-Prefix headers when trustForwardHeader=false. An attacker can send a request with a spoofed X-Forwarded-Prefix header to a Traefik instance that is behind a trusted reverse proxy. The ForwardAuth middleware, specifically the writeHeader function in pkg/middlewares/auth/forward.go, would then forward this malicious header to the backend authentication service. If the authentication service uses the value of this header to make authorization decisions, it can be tricked into granting access to protected routes.
The vulnerability is particularly exploitable when the StripPrefix middleware is used before ForwardAuth. StripPrefix adds its own X-Forwarded-Prefix header, but because the attacker's header is not removed, the request to the auth service contains both. If the auth service processes the first X-Forwarded-Prefix header it sees, it will use the attacker's value, leading to an authentication bypass.
The patch addresses this by modifying the writeHeader function to explicitly delete all X-Forwarded-* headers when trustForwardHeader is false, using a new DeleteXForwardedHeaders function. For backward compatibility, the old, vulnerable logic was moved to a new function, oldWriteHeader, which is called with a warning if trustForwardHeader is not explicitly configured.