Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring cloud gateway MVC : add parameters to disable adding Forwarded header #3238

Closed
florentm35 opened this issue Jan 25, 2024 · 0 comments
Closed
Milestone

Comments

@florentm35
Copy link

florentm35 commented Jan 25, 2024

Describe the bug
I use reverse proxy who add the headers X-Forwarded-* in front of the gateway and a backend spring-boot application behind the gateway.

On the backend spring boot application i use the property server.forward-headers-strategy=FRAMEWORK, the problem is that in spring framework web ForwardedHeaderUtils#adaptFromForwardedHeaders (use in ForwardedHeaderFilter#ForwardedHeaderExtractingRequest) check the header Forwarded before the header X-Forwarded-*

Use the X-Forward-* header to build the header Forwarded in ForwardedRequestHeadersFilter or disable if the header X-Forwarded-* is present

Workaround
For the moment i override ForwardedRequestHeadersFilter

 @Bean
    public ForwardedRequestHeadersFilter forwardedRequestHeadersFilter() {
        return new ForwardedRequestHeadersFilter() {
            @Override
            public HttpHeaders apply(HttpHeaders input, ServerRequest request) {
                return input;
            }
        };
    }
@spencergibb spencergibb added this to the 4.1.2 milestone Mar 11, 2024
spencergibb added a commit that referenced this issue Mar 11, 2024
From spring.cloud.gateway.x-forwarded to spring.cloud.gateway.mvc.x-forwarded-request-headers-filter. Deprecates the later.

The XForwardedRequestHeadersFilter bean is conditional on the x-forwarded-request-headers-filter.enabled property.

Fixes gh-3238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants