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

Configurable Unsafe Host Header Behaviors #9283

Merged
merged 9 commits into from
Feb 3, 2023

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Feb 1, 2023

  • Adding HttpCompliance.DUPLICATE_HOST_HEADERS
    • Optional compliance that allowance duplicate host headers.
  • Adding HttpCompliance.UNSAFE_HOST_HEADER
    • Optional compliance that allows unsafe host headers.
  • Adding warning logging for bad Host / authority situations

+ Optional compliance that allowance
  duplicate host headers.

Signed-off-by: Joakim Erdfelt <[email protected]>
+ Optional compliance that allows
  unsafe host headers.

Signed-off-by: Joakim Erdfelt <[email protected]>
@joakime joakime added Enhancement Sponsored This issue affects a user with a commercial support agreement labels Feb 1, 2023
@joakime joakime added this to the 10.0.x milestone Feb 1, 2023
@joakime joakime requested a review from gregw February 1, 2023 20:03
@joakime joakime self-assigned this Feb 1, 2023
Copy link
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.

looking good, but a couple of niggles

Signed-off-by: Joakim Erdfelt <[email protected]>
@joakime joakime requested a review from gregw February 1, 2023 21:04
Copy link
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.

sorry still a niggle

public void testUnsafeAuthority(String authority)
{
HostPort hostPort = HostPort.unsafe(authority);
assertNotNull(hostPort);
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to test more here. We need to test if the port was correctly extracted or not. So I think we need to pass in an expected port

Copy link
Contributor Author

@joakime joakime Feb 2, 2023

Choose a reason for hiding this comment

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

Many will be port 0, this is a test of unsafe(String authority) against totally broken authorities that the normal (safe) flows will reject and not allow.

We have a separate test for valid authorities that use unsafe(String authority) which does test for valid splits (host + port)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, in unsafe(String authority) we don't even test to make sure that the port is valid (within range 1 thru 65535).

It could be parsed as -80, or 333444555 as its unsafe.

Copy link
Contributor Author

@joakime joakime Feb 2, 2023

Choose a reason for hiding this comment

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

Basically everything about using unsafe(String authority) is unsafe, it can easily allow conditions later that will never work (you cannot create a URL or URI from them, or a valid Location header, etc)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with it being totally unsafe, but we need to consistently and predictably in our unsafe handling. Currently if it looks like an IPv6 address we don't check for a : before posting the port. If it doesn't look like IPv6 then we do check for the colon. I think we should check in both cases. No colon then no port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworked the test cases and the implementation in HostPort.

@joakime joakime requested a review from gregw February 2, 2023 21:00
Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
@joakime joakime merged commit 016de2f into jetty-10.0.x Feb 3, 2023
@joakime joakime deleted the fix/jetty-10.0.x/configurable-unsafe-host branch February 3, 2023 14:30
@joakime joakime added the Specification For all industry Specifications (IETF / Servlet / etc) label Feb 3, 2023
@joakime joakime changed the title Jetty 10 - Configurable Unsafe Host Header Configurable Unsafe Host Header Behaviors Feb 3, 2023
gregpoulos pushed a commit to gregpoulos/jetty.project that referenced this pull request Feb 6, 2023
…x-documentation-operations-logging

* upstream/jetty-12.0.x: (42 commits)
  fixed style
  cleanup TODOs for decoration
  Issue jetty#9300 - Rename RetainableByteBufferPool to ByteBufferPool
  Removed TODOs that will not be done.
  Rename Handler Nested & Collection (jetty#9305)
  fix surefire jpms configuration
  fix merge
  fix merge
  Bump maven.surefire.plugin.version from 3.0.0-M5 to 3.0.0-M8 (jetty#9255)
  Rename RetainableByteBufferPool to ByteBufferPool
  Fixed merge
  Fix jetty#9285 use possibly wrapper response for redirection (jetty#9286)
  Issue jetty#9293 - Jetty 12 - Relax JPMS dependencies (quic) (jetty#9307)
  Issue jetty#9293 - Jetty 12 - Relax JPMS dependencies (fcgi) (jetty#9306)
  Jetty 10 - Configurable Unsafe Host Header (jetty#9283)
  Issue jetty#9293 - Jetty 12 - Relax JPMS dependencies. (jetty#9296)
  Issue jetty#9293 - Jetty 12 - Relax JPMS dependencies. (jetty#9299)
  fix dependency
  add used dependency
  this dependency is used in test scope
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Specification For all industry Specifications (IETF / Servlet / etc) Sponsored This issue affects a user with a commercial support agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants