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

Various cleanups in HttpParser (CVE-2023-40167) #10329

Merged
merged 6 commits into from Aug 18, 2023

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Aug 16, 2023

Various cleanups in HttpParser:

  • removed dead branches
  • improved efficiency of conversions (to address CVE-2023-40167)
  • parameterised tests

Various cleanups in HttpParser

Signed-off-by: gregw <gregw@webtide.com>
@gregw gregw requested a review from joakime August 16, 2023 23:03
Various cleanups in HttpParser

Signed-off-by: gregw <gregw@webtide.com>
@joakime joakime added the Bug For general bugs on Jetty side label Aug 17, 2023
@joakime joakime added this to the 10.0.x milestone Aug 17, 2023
Copy link
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.

Got a leftover printStackTrace there.

Various cleanups in HttpParser

Signed-off-by: gregw <gregw@webtide.com>
@gregw gregw requested a review from joakime August 17, 2023 04:27
if (c < '0' || c > '9')
throw new BadMessageException("Invalid Content-Length Value", new NumberFormatException());

value = Math.addExact(Math.multiplyExact(value, 10), c - '0');
Copy link
Contributor

Choose a reason for hiding this comment

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

addExact and multiplyExact throw ArithmeticException, that we should catch and convert to BadMessageException.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is already caught in parseNext and converted to a BadMessageException there. We don't need to catch inside a catch

Copy link
Contributor

Choose a reason for hiding this comment

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

@gregw before, NumberFormatException was caught here and converted, that's why I raised this comment.

Also, we can be more precise with the exception message saying "invalid content-length", rather than just an ArithmeticException with no message.

I'd prefer to catch and rethrow, but I can live as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sbordet I'd prefer to avoid the tiny cost of an extra try catch in critical path code to give a slightly better error message to a bad client.

update after review

Signed-off-by: gregw <gregw@webtide.com>
@gregw gregw requested a review from sbordet August 17, 2023 09:21
if (c < '0' || c > '9')
throw new BadMessageException("Invalid Content-Length Value", new NumberFormatException());

value = Math.addExact(Math.multiplyExact(value, 10), c - '0');
Copy link
Contributor

Choose a reason for hiding this comment

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

@gregw before, NumberFormatException was caught here and converted, that's why I raised this comment.

Also, we can be more precise with the exception message saying "invalid content-length", rather than just an ArithmeticException with no message.

I'd prefer to catch and rethrow, but I can live as is.

@gregw gregw added Enhancement and removed Bug For general bugs on Jetty side labels Aug 17, 2023
crime against formatting resolved

Signed-off-by: gregw <gregw@webtide.com>
@gregw gregw requested a review from sbordet August 17, 2023 14:36
Copy link
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.

Approved.
Don't forget to backport to 9.4.x

@gregw gregw merged commit 003e46c into jetty-10.0.x Aug 18, 2023
4 checks passed
@gregw gregw deleted the fix/10/cleanup-httparser branch August 18, 2023 07:09
@joakime joakime changed the title Various cleanups in HttpParser Various cleanups in HttpParser (CVE-2023-40167) Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants