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

ForwardedHeaderFilter should reject invalid requests #31842

Closed
ravihansa3000 opened this issue Dec 14, 2023 · 4 comments
Closed

ForwardedHeaderFilter should reject invalid requests #31842

ravihansa3000 opened this issue Dec 14, 2023 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@ravihansa3000
Copy link

Hi, our Spring Boot application using Spring Boot 3.1.4 which includes spring-web:6.0.12 started throwing 5xx due to a malformed X-Forwarded-For header in the requests that were returned with 5xx and this error in our logs; java.lang.IllegalArgumentException: Failed to parse a port from "forwarded"-type headers.

I would suggest introducing a mechanism to skip extracting "forwarded"-type headers in ForwardedHeaderFilter when the header format is invalid. Our service SLOs are impacted by this issue and such incidents attract unnecessary attention. Thanks!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 14, 2023
@bclozel
Copy link
Member

bclozel commented Dec 14, 2023

Hello @ravihansa3000, thanks for reaching out.

It's not clear from your description whether this is something that used to work with a previous Spring version or if this problem appeared because invalid requests started coming in production. Can you elaborate?

Can you give an example of such invalid request? Do you happen to know where this comes from? Is there a specific proxy or client that we should know about? Knowing if this is a custom client or some well-known product would really help.

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue in: web Issues in web modules (web, webmvc, webflux, websocket) labels Dec 14, 2023
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Dec 14, 2023

In addition, please provide a stacktrace that shows the location of the failure, and also try with the latest 6.0.15 just in case.

@ravihansa3000
Copy link
Author

Hi @bclozel I don't think this is a regression and the problem appeared in prod when Forwarded header contained a malformed value like; "for=[a:" We don't know whether this payload was maliciously formed or due to a faulty intermediary gateway. The app follows a standard deployment in AWS infrastructure.

@rstoyanchev This behavior is present in 6.0.15 as well and the exception is raised in

throw new IllegalArgumentException("Invalid IPv4 address: " + rawValue);

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 14, 2023
@bclozel bclozel changed the title Invalid "forwarded"-type headers lead to 5xx status responses ForwardedHeaderFilter should reject invalid requests Dec 22, 2023
@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Dec 22, 2023
@bclozel bclozel added this to the 6.1.3 milestone Dec 22, 2023
@bclozel bclozel added the for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x label Dec 22, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x labels Dec 22, 2023
@bclozel
Copy link
Member

bclozel commented Dec 22, 2023

We should reject invalid requests right away instead of throwing IllegalStateException or IllegalArgumentException instance. This will align the behavior here with HttpWebHandlerAdapter on the WebFlux side.

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: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants