spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Server WebMVC docs list X-Forwarded properties that are not bound

Open rajeshvasa opened this issue 3 weeks ago • 0 comments

The Server WebMVC "HTTP Headers Filters" page documents the per-header properties of the XForwarded headers filter as:

spring.cloud.gateway.server.webmvc.x-forwarded.for-enabled
spring.cloud.gateway.server.webmvc.x-forwarded.for-append
... (10 properties in total)

However, XForwardedRequestHeadersFilterProperties binds under a different prefix:

public static final String PREFIX = GatewayMvcProperties.PREFIX + ".x-forwarded-request-headers-filter";

so the actual names are spring.cloud.gateway.server.webmvc.x-forwarded-request-headers-filter.for-enabled and so on. The generated configuration properties appendix (_configprops.adoc) already lists these correct names. The hand-written page appears to reuse the Server WebFlux names (spring.cloud.gateway.server.webflux.x-forwarded.*).

Impact: a user who follows the page and sets, for example, ...webmvc.x-forwarded.for-enabled=false gets no error and no effect. The header is still written.

Two tests set the non-existent names as well:

  • GatewayServerMvcAutoConfigurationTests#forwardedHeaderFiltersEnabledWithProperties
  • RemoveForwardedRequestHeadersFilterIntegrationTests

Both set ...webmvc.forwarded.enabled=true and ...webmvc.x-forwarded.enabled=true. The real properties are forwarded-request-headers-filter.enabled and x-forwarded-request-headers-filter.enabled. The tests pass only because both filters are enabled by default.

I'm happy to submit a PR that corrects the docs and tests and adds a test that binds every documented property. If you would rather keep backwards compatibility by also accepting the x-forwarded.* names in Server WebMVC, I can do that instead.

rajeshvasa avatar Nov 11 '26 19:11 rajeshvasa