Skip to content

Reject an HTTP/2 request with a non-numeric content-length - #1211

Open
arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:h2-content-length-digits
Open

arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:h2-content-length-digits

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

RFC 9110, section 8.6 defines the value of a content-length field as one or more digits, and RFC 9113, section 8.1.1 requires a request that is malformed to be treated as a stream error of type PROTOCOL_ERROR.

In HTTP/2 the value was parsed with Long.parseLong(), so a request with content-length: +3, -0 or -1 was accepted, and a negative value was treated as if the field was absent. HTTP/1.1 rejects the same values with a 400 response.

This checks the value in Stream.emitHeader() and resets the stream with PROTOCOL_ERROR if it is not made of digits.

Tested with a running Tomcat and a raw HTTP/2 client: without the change those requests are processed, with the change the stream is reset with PROTOCOL_ERROR. Valid values, including ones with leading zeros, are not affected.

…gits

RFC 9110, section 8.6 defines the content-length field value as one or
more digits and RFC 9113, section 8.1.1 requires a request that is
malformed to be treated as a stream error of type PROTOCOL_ERROR. The
value was parsed with Long.parseLong(), so a request with a value such
as +3, -0 or -1 was accepted. A negative value was treated as if the
field was absent. HTTP/1.1 rejects the same values with a 400 response.

Check the value when the header field is received.
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.

1 participant