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

Issue #11659 - Properly ignore OWS before field values. #11661

Merged
merged 2 commits into from
Apr 19, 2024

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Apr 17, 2024

Update HttpParser.CACHE to handle UNMATCHED_VALUE scenarios (like Content-Length: 10) by restoring Jetty 9/10/11 behavior of header only matches from CACHE, allowing HttpParser.parseFields() to handle OWS properly.

Fixes #11659

@joakime joakime added Bug For general bugs on Jetty side Specification For all industry Specifications (IETF / Servlet / etc) labels Apr 17, 2024
@joakime joakime requested review from gregw and sbordet April 17, 2024 16:37
@joakime joakime self-assigned this Apr 17, 2024
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.

I think this is the wrong fix. The parser itself is meant to skip OWS, so the convertContentLength method should never see any such characters.

We need to investigate why the state machine in parseFields is not working correctly rather than cover up the problem afterwards

@gregw
Copy link
Contributor

gregw commented Apr 17, 2024

I think this is the wrong fix. The parser itself is meant to skip OWS, so the convertContentLength method should never see any such characters.

We need to investigate why the state machine in parseFields is not working correctly rather than cover up the problem afterwards

The problem looks to be an issue with the handling of a cached header look ahead. investigating....

@gregw
Copy link
Contributor

gregw commented Apr 17, 2024

It was broken by #10308,which changed HttpField so that the value could never be null. This breaks the HttpParser header cache, as it uses null values to indicate a header only cache item.

@sbordet Do you remember why you did that? There is a difference between a null value (i.e. not set) and an empty value.

The fix is either to revert this change OR to update HttpParser to test for blank values rather than null values in it's cache handling... but then that will need careful handling of line termination handling to really handle empty values.

Also it is a little bit of a worry that our tests didn't detect this. I think we need a better tests for OWS that cover: cached header; cached header with no value; cached header with unknown value; cached header and value.

@sbordet
Copy link
Contributor

sbordet commented Apr 18, 2024

@gregw HttpField null values were treated inconsistently, meaning that in 95% of the places they were assumed to be non-null and used without a null guard, possibly leading to NPEs.

Since it was the majority of the cases, and HTTP really does not have any meaning for a null value (it can only be the empty string), the change was made.

I think it would be better to change HttpParser as it is more of a private class (HttpField is exposed to applications, and we don't really want users to create an HttpField with a null value).

@gregw
Copy link
Contributor

gregw commented Apr 18, 2024

@joakime perhaps it would be best to create the cache with a special sentinel value for the header only cases so that value not set can be distinguished from a empty string value.

@joakime joakime changed the title Issue #11659 - Properly ignore OWS before Content-Length value. Issue #11659 - Properly ignore OWS before field values. Apr 18, 2024
@joakime joakime requested a review from gregw April 18, 2024 15:02
@joakime
Copy link
Contributor Author

joakime commented Apr 18, 2024

@gregw @sbordet this is updated per your reviews.

  • reverted the changes to convertContentLength
  • implemented changes to CACHE and parseFields to handle OWS properly for all UNMATCHED_VALUE headers.
  • added 3 new OWS test cases (that fail in 12.0.x HEAD btw) to handle this OWS case.

@joakime joakime merged commit 8b1c6bc into jetty-12.0.x Apr 19, 2024
10 checks passed
@joakime joakime deleted the fix/12.0.x/http-parse-content-length branch April 19, 2024 01:33
gregw added a commit that referenced this pull request May 18, 2024
Avoid adding the unknown marker into the CACHE index. Issue introduced in #11661 fixing #11659
gregw added a commit that referenced this pull request May 18, 2024
Avoid adding the unknown marker into the CACHE index. Issue introduced in #11661 fixing #11659
gregw added a commit that referenced this pull request May 19, 2024
Avoid adding the unknown marker into the CACHE index. Issue introduced in #11661 fixing #11659
gregw added a commit that referenced this pull request May 21, 2024
Avoid adding the unknown marker into the CACHE index. Issue introduced in #11661 fixing #11659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side Specification For all industry Specifications (IETF / Servlet / etc)
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

HTTP Fields with OWS (Optional WhiteSpace) in value are not properly parsed in Jetty 12
3 participants