Skip to content

Issue #4645 - ForwardedRequestCustomizer now gives 400 response for bad port values#4648

Merged
lachlan-roberts merged 5 commits intojetty-9.4.xfrom
jetty-9.4.x-4645-forwardedPortException
Mar 15, 2020
Merged

Issue #4645 - ForwardedRequestCustomizer now gives 400 response for bad port values#4648
lachlan-roberts merged 5 commits intojetty-9.4.xfrom
jetty-9.4.x-4645-forwardedPortException

Conversation

@lachlan-roberts
Copy link
Copy Markdown
Contributor

Issue #4645

Replace the previous NumberFormatException with an IllegalArgumentException with a more descriptive error message.

It would also be possible to change the code to just return if we have an empty X-Forwarded-Port value, which would ignore it. I'm not sure if that would be more correct than throwing.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Copy link
Copy Markdown
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should catch exceptions from parsing all these headers and pass to a method on the Customizer, which by default will throw a BadMessageException.

If users want to ignore these bad headers they can extend and change the method

@gregw
Copy link
Copy Markdown
Contributor

gregw commented Mar 9, 2020

@sbordet has also suggested that when we parse a port we check that it is a valid integer for a port... ie >0 <=64k

Copy link
Copy Markdown
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like @gregw said, we should also be validating the range of possible post-parsed values.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Copy link
Copy Markdown
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add at least one ForwardedRequestCustomerizerTest test that has a bad port. I want to make sure that the BadMessageException thrown and then wrapped as a RuntimeException is correctly unwrapped to get the 400 (rather than a 500).

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Copy link
Copy Markdown
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost!

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@lachlan-roberts lachlan-roberts merged commit b497827 into jetty-9.4.x Mar 15, 2020
@lachlan-roberts lachlan-roberts deleted the jetty-9.4.x-4645-forwardedPortException branch March 15, 2020 23:35
@lachlan-roberts lachlan-roberts changed the title Issue #4645 - better error message for empty X-Forwarded-Port value Issue #4645 - ForwardedRequestCustomizer gives 400 response for bad port values Mar 15, 2020
@lachlan-roberts lachlan-roberts changed the title Issue #4645 - ForwardedRequestCustomizer gives 400 response for bad port values Issue #4645 - ForwardedRequestCustomizer now gives 400 response for bad port values Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty "X-Forwarded-Port" header results in NumberFormatException

3 participants