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

Return "431 Request Header Fields Too Large" for long headers on HTTP/1 #4655

Merged
merged 2 commits into from
Feb 9, 2023

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Feb 7, 2023

Motivation:

Netty HTTP/1 codec raises TooLongHttpHeaderException if headers exceed the max length limit. However, Http1RequestDecoder does not take account into TooLongHttpLineException and returns "400 Bad Request" instead.

Modifications:

  • Make Http1RequestDecoder return 431 Request Header Fields Too Large if a Netty HttpRequest fails with TooLongHttpHeaderException

Result:

Motivation:

Netty HTTP/1 codec raises `TooLongHttpHeaderException` if headers exceed
the max length limit. However, `Http1RequestDecoder` does not take
account into `TooLongHttpLineException` and returns "400 Bad Request"
instead.

Modifications:

- Make `Http1RequestDecoder` return `431 Request Header Fields Too Large`
  if a Netty HttpRequest fails with `TooLongHttpHeaderException`

Result:

- "431 Request Header Fields Too Large" is now returned instead of
  `400 Bad Request` if the size of header exceeds
  `ServerBuilder.http1MaxHeaderSize()`.
- Fixes line#4609
@ikhoon ikhoon added the defect label Feb 7, 2023
@ikhoon ikhoon added this to the 1.22.0 milestone Feb 7, 2023
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Left a super minor comment! Thanks @ikhoon ! 🙇 👍 🙇

@@ -151,6 +152,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
final Throwable cause = nettyReq.decoderResult().cause();
if (cause instanceof TooLongHttpLineException) {
fail(id, null, HttpStatus.REQUEST_URI_TOO_LONG, "Too Long URI", cause);
} else if (cause instanceof TooLongHttpHeaderException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

double checked that TooLongHttpHeaderException is not related to TooLongHttpLineException, so it doesn't matter which if statement is checked first 👍

@@ -151,6 +152,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
final Throwable cause = nettyReq.decoderResult().cause();
if (cause instanceof TooLongHttpLineException) {
fail(id, null, HttpStatus.REQUEST_URI_TOO_LONG, "Too Long URI", cause);
} else if (cause instanceof TooLongHttpHeaderException) {
fail(id, null, HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, "Too Long Header Fields",
Copy link
Contributor

Choose a reason for hiding this comment

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

How about just using the default message for the http status?

Suggested change
fail(id, null, HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, "Too Long Header Fields",
fail(id, null, HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, "Request Header Fields Too Large",

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

👍 👍 👍

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Still looks good 👍

@jrhee17
Copy link
Contributor

jrhee17 commented Feb 9, 2023

Thanks @ikhoon ! 🙇 👍 🙇

@jrhee17 jrhee17 merged commit a43cfa2 into line:master Feb 9, 2023
@ikhoon ikhoon deleted the 431-header-length branch February 9, 2023 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return "431 Request Header Fields Too Large" when the header value exceeds
3 participants