Skip to content

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

@florentm35

Description

@florentm35

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;
            }
        };
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions