The vulnerability CVE-2025-41235 in Spring Cloud Gateway allows an attacker to send spoofed X-Forwarded-For and Forwarded headers through an untrusted proxy. The gateway would then incorrectly process these headers, potentially leading to security misconfigurations or bypasses, such as incorrect client IP identification.
The root cause is the lack of validation of the proxy's trustworthiness before processing these headers. The affected functions are primarily ForwardedHeadersFilter.filter and XForwardedHeadersFilter.filter (and their MVC counterparts ForwardedRequestHeadersFilter.apply and XForwardedRequestHeadersFilter.apply). These filters were responsible for parsing and applying the Forwarded and X-Forwarded-* headers to the downstream request.
The patch introduces a spring.cloud.gateway.trusted-proxies (and spring.cloud.gateway.mvc.trusted-proxies) configuration property. This property accepts a regular expression defining which proxies are considered trusted. The core filtering logic in ForwardedHeadersFilter and XForwardedHeadersFilter was modified to consult this list of trusted proxies. If the remote address of the connecting proxy (or the for field within an existing Forwarded header) does not match the trustedProxies pattern, the headers are either not added, or existing untrusted entries are stripped.
Additionally, a DefaultNettyHttpForwardedHeaderHandler was introduced, along with a NettyServerCustomizer in GatewayAutoConfiguration. This allows for the trustedProxies check to occur at the Netty server level, ensuring that connection information is only updated with forwarded headers if the immediate upstream proxy is trusted.
Therefore, when this vulnerability is exploited, the runtime profile would show activity within these header filtering functions as they process the malicious input. After the patch, these functions would first check against the trustedProxies configuration.