Skip to content

X-Forwarded-Host handling in ServletUriComponentsBuilder does not treat ports correctly [SPR-10718] #15346

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
spring-projects-issues opened this issue Jul 3, 2013 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 3, 2013

Oliver Drotbohm opened SPR-10718 and commented

According to the spec, a Host value consists of a uri-host and an optional port. So when inspecting the X-Forwarded-Host header we have to split uri-host and port and set the values appropriately. Currently the port is still part of the host.

This was originally reported against Spring HATEOAS in this ticket.


Affects: 3.2.3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 3, 2013

Rossen Stoyanchev commented

This appears to be a duplicate of #15329.

@spring-projects-issues
Copy link
Collaborator Author

Philippe Bouteleux commented

Hi, it seems the code that processes the X-Forward-Host header value does not take into account the fact that the forwarded port (after the ":") may be optional and that it should in that case force the value to the default one, that is -1 (which is really 80 for HTTP or 443 for HTTPS in the end).

The HATEOAS version of the builder acts correctly in that case and can be found here :
https://github.com/spring-projects/spring-hateoas/blob/master/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java

Look at the "else" in the method getBuilder(). Unfortunately, there is no overloading with a HttpServletRequest parameter that would suit my needs for mocking services URI dynamically.

PS : this method also correctly treat SSL and X-Forward-Post which should also be retrofited I think.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

The logic in ServletUriComponentsBuilder with regards to an optional forwarded port (see here for comparison). Or am I missing anything? We do have X-Forwarded-Port as well.

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) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants