-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Regression: ForwardedHeaderFilter no longer support IPv6 #27013
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
Comments
The line where the IAE error is raised: this.remoteAddress = UriComponentsBuilder.parseForwardedFor(request, request.getRemoteAddress()); was added in support of "X-Forward-For" and "Forwarded for:" as part of #23582 with commits 883ad09 and d627f60 while the validation was added in #26748. The address "2a02:1810:84ae:d800:c8da:d498:64ec:6edb" is indeed invalid. It should have surrounding square brackets. What I'm not sure is is exactly what happened before. I'm guessing that the header causing the issue simply wasn't parsed. Can you please provide the relevant headers in their entirety? |
You are correct. Seems I'll have to file a bug with the gateway vendor. Below the trace (I've removed some parts of the IP's)
|
Closing as invalid. |
Why was this issue closed as invalid? The problem still exists and older versions accepted such IPv6 addresses. Seems like the Spring Cloud Gateway team solved the issue: spring-cloud/spring-cloud-gateway#2217 |
Unfortunately in this case it is not possible to be lenient due to ambiguity since what comes after the last ":" could be part of the host address or a port. The change in Spring Cloud Gateway is to format IPv6 addresses correctly for forwarded headers it creates, and not for parsing forwarded headers. |
But what should the user do when there's no chance to fix the incorrect header (e.g. the wrong headers are created by the Service Providers infrastructure)? In my case I only need the original hostname (X-Forwarded-Host) but the ForwardedHeaderFilter also tries to parse the IP Address and then the complete request crashes. May it be an option to make the ForwardedHeaderFilter configurable, e.g. that you could configure what headers to parse and how lenient it should be? |
X-Forwarded-Host contains host and port, so parsing is required to get the original hostname. Lenient parsing is not possible and such an option would be misleading at best. For a very specific case, if you want or can make certain assumptions, create add your own filter ordered ahead of ForwaredHeaderFilter to modify the X-Forwarded-Host header. |
@poutsma This seems like a big problem not to fix: currently it means that you can't deploy behind Cloudflare. I opened a support request for them but have no idea when it will be fixed. |
I did a bit of research and this appears to be an overly-strict reading: the There is a consideration for the possibility of port numbers being appended to IP addresses in the It seems like no matter what the decision is here, Spring should handle the exception more gracefully – an HTTP 400 request would be the most appropriate semantically since there's no way the request will succeed without the client changing it. |
Yes, but that’s not normative for
This makes it hard to deploy Spring apps behind Cloudflare, GCP load balancers, nginx, etc. without an additional proxy layer to rewrite the XFF header. |
There isn't anything normative for X-Forwarded-For, so relying on what the URI spec says doesn't seem so unreasonable. That said I understand your point about the pain of running behind popular proxies. Looking again in more detail, |
Thank you so much for pointing that out — this turns out to be a bug in the AWS API Gateway's dispatching for HTTP backends. I had checked the edge logs, internal load-balancer for the Spring containers, and what's seen by the Lambda function authenticating requests, and those all showed only I've reported this upstream. |
I assume I should have opened the bug here rather than in spring-cloud: spring-cloud/spring-cloud-gateway#2512 Google Cloud Run has the same issue with not compliant IPv6 addresses |
Affects:: spring-web 5.3.6
After updating from spring 5.2.8 to 5.3.6 we noticed that ForwardedHeaderFilter would throw:
The code before:
The code as is:
The text was updated successfully, but these errors were encountered: