Description
The ForwardedHeaderFilter
supports already Forwarded headers as defined in: https://tools.ietf.org/html/rfc7239#section-5.2
Improvement:
Implement fallback to X-Forwarded-Host and X-Forwarded-Port header if host
is not defined in Forward header.
Background:
The Forwarded header can contain some or all of the parameters: by, for, host, proto
.
ForwardedHeaderFilter
uses UriComponentsBuilder
to adjust URI parts.
The implementation in UriComponentsBuilder#adaptFromForwardedHeaders
right now is not really symetric.
First it checks if there is a Forwarded header, if yes it tries to take the parameters proto, host from this.
Only for proto
there is a fallback implemented. Meaning that if proto is not found in Forwarded header, the X-Forwarded-Ssl is checked additionally.
This is not done for host
. So if there is a Forwarded header but if this does not contain host-parameter, host and port are not extracted at all.
Wouldn't it be better to also fallback to the X-Forwarded-Host and X-Forwarded-Port header if they exist?
Scenario:
When using spring application behind a fabio proxy this problem occurs.
The headers that fabio sets are:
forwarded: "for=100.93.64.162; proto=http; by=192.168.30.12; httpproto=http/1.1"
x-forwarded-host: "10.65.250.31:9999"
host
is not defined in Forwarded, so the host
is not extracted in current implementation.