-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Consistent formatting of IPv6 host in forwarded header handling #34253
Comments
We can add the square brackets in the x-forwarded-for case to match the RFC forwarded header syntax. |
Hi @rstoyanchev - I believe only IPv6 should be enclosed within square brackets. This is true for "Forwarded" handling. If you enclose IPv4 within square brackets then it's again inconsistent. |
Good point. In that case, we might not be able to do this. I'm not sure there is an easy way to tell them apart. |
The obvious difference is that IPv6 blocks are separated by colon |
I was thinking of an address with a port, but "X-Forwarded-For" is just a host, so it should be an easy check indeed. |
Even with port, IPv6 will always contain more than one |
I have originally submitted the issue to spring-cloud-gateway, so pardon the reproducer name.
In RFC for handling Forwarded and X-Forwarded compatibility [1] and there is an issue when X-Forwarded-For contains an IPv6 as first entry. I could reproduce this only via Cloudfare with an ISP that offers dual IP stack.
The X-Forwarded-For header that is received from Cloudfare when source IP is a real IPv6 is shown below (fully anonymized, of course).
Consider the following
When using X-Forwarded-For header such as
The
org.springframework.web.util.ForwardedHeaderUtils
produces an InetHostAddress without square brackets "[]"When using an equivalent
Forwarded
header, the InetHostAddress is present WITH square brackets "[]"It would be nice if both would return the same format.
Reproducer https://github.com/ZIRAKrezovic/gateway-reproducer
Simply run
./mvnw clean verify
Adjust
DemoApplicationSimpleTests
to switch betweenX-Forwarded-For
andForwarded
as shown above.[1] https://datatracker.ietf.org/doc/html/rfc7239#section-7.4
The text was updated successfully, but these errors were encountered: