Skip to content

X-Forwarded Headers not used #1612

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

Closed
sonic-air-swimmer opened this issue Apr 13, 2022 · 3 comments
Closed

X-Forwarded Headers not used #1612

sonic-air-swimmer opened this issue Apr 13, 2022 · 3 comments
Labels
invalid This doesn't seem right

Comments

@sonic-air-swimmer
Copy link

Describe the bug
Getting "Failed to load remote configuration." when accessing swagger-ui behind api gateway.

Have gone through #215, #153 and https://springdoc.org/faq.html#how-can-i-deploy-springdoc-openapi-ui-behind-a-reverse-proxy
Have set server.forward-headers-strategy = framework.

The api gateway is host on port 8080, serving ServiceA at port 8081 when accessed via /api/servicea/.

A call to test service in ServiceA through api gateway shows that http headers are all set:
C:>curl http://localhost:8080/api/servicea/test
Request HTTP Headers:{user-agent=curl/7.79.1, accept=/, forwarded=proto=http;host="localhost:8080";for="127.0.0.1:50729", x-forwarded-for=127.0.0.1, x-forwarded-proto=http, x-forwarded-prefix=/api/servicea, x-forwarded-port=8080, x-forwarded-host=localhost:8080, host=localhost:8081, content-length=0}

While a call made directly to test service it is not having X-Forwarded headers:
C:>curl http://localhost:8081/test
Request HTTP Headers:{host=localhost:8081, user-agent=curl/7.79.1, accept=/}

To Reproduce
Steps to reproduce the behavior:

Expected behavior

  • A clear and concise description of what you expected to happen.
    Able to access swagger-ui when going through api gateway.

Screenshots
If applicable, add screenshots to help explain your problem.
image

@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Apr 15, 2022

@sonic-air-swimmer,

will be reviewed

@bnasslahsen bnasslahsen added the invalid This doesn't seem right label Apr 15, 2022
@bnasslahsen bnasslahsen reopened this Apr 15, 2022
@bnasslahsen bnasslahsen removed the invalid This doesn't seem right label Apr 15, 2022
@bnasslahsen
Copy link
Collaborator

@sonic-air-swimmer,

The problem, is your implementation.

Replacing your Bean:

    @Bean
    public FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter() {
        ForwardedHeaderFilter filter = new ForwardedHeaderFilter();
        FilterRegistrationBean<ForwardedHeaderFilter> registration = new FilterRegistrationBean<>(filter);
        registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.ERROR);
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        registration.setUrlPatterns(List.of("/**"));
        return registration;
    }

By the following, as described in the documentation:

	@Bean
	ForwardedHeaderFilter forwardedHeaderFilter() {
		return new ForwardedHeaderFilter();
	}

Solves the problem.

@bnasslahsen bnasslahsen added the invalid This doesn't seem right label Apr 21, 2022
@sonic-air-swimmer
Copy link
Author

Hi @bnasslahsen,

Thank you so much for taking time to look on the issue.
I tried it out before and now I realize that it wasn't working previously because it was cached.

I've made it worked by following suggestion from #331

@springdoc springdoc locked as resolved and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants