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

Centralize handling of "Forwarded" headers to ForwardedHeaderFilter [SPR-16668] #21209

Closed
spring-projects-issues opened this issue Mar 29, 2018 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 29, 2018

Rossen Stoyanchev opened SPR-16668 and commented

Currently "Forwarded" headers are consumed indirectly when building links with ServletUriComponentsBuilder, MvcUriComponentsBuilder or in CORS checks. While the behavior is documented, it can be overlooked, and it would be better to differ the treatment of such headers to the ForwadedHeaderFilter which requires an explicit choice, handles such headers more efficiently (once per request), is more comprehensive as a solution (e.g. applies to redirects too), and provides a removeOnly flag which can discard such headers when the application is not behind a trusted proxy.

On the implementation level we would keep the current UriComponentsBuilder.fromHttpRequest which encapsulates the actual handling of such headers, and switch the above to use UriComponentsBuilder.fromUri instead.

In the mean time, applications can use the ForwadedHeaderFilter which removes those headers (by wrapping the request), either consuming or ignoring them, and thus providing a single point of handling.


Affects: 5.0.4

Issue Links:

Referenced from: commits 4da43de

0 votes, 6 watchers

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Wiki updated.

@spring-projects-issues
Copy link
Collaborator Author

johann-sonntagbauer commented

Sorry for asking questions on an closed Issue, but the current implementation of the ServletUriComponentsBuilder does ignore Forward Headers. But the javadoc suggests otherwise. We are now a little bit confused what should be done and what is the expected behaviour.

@spring-projects-issues
Copy link
Collaborator Author

johann-sonntagbauer commented

One example for confusing javadoc:

ServletUriComponentsBuilder.fromCurrentServletMapping()  -  notes that Forward headers are used

but the internal implementation ignores them.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 1, 2018

Rossen Stoyanchev commented

Thanks for pointing this out and for creating #21850.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants