Repository navigation
Fix BZ 70366 - HTTP/2 content length read while headers are modified - #1266
Open
arturobernalg wants to merge 1 commit into
Open
arturobernalg wants to merge 1 commit into
arturobernalg wants to merge 1 commit into
Conversation
arturobernalg
force-pushed
the
bz70366-h2-content-length
branch
2 times, most recently
from
November 21, 2026 18:37
70d9078 to
8db8ed7
Compare
The content length of an HTTP/2 request was looked up in the request headers when a DATA frame was received on the connection thread, until a value had been found. At that point the container thread may already be processing the request and modifying the same, unsynchronised, MimeHeaders instance. RemoteIpValve removes and restores headers, so the lookup could return the value of another header, which reset a valid request with PROTOCOL_ERROR, or miss the header, which disabled the check required by RFC 9113, section 8.1.1. Resolve the content length once the request headers have been received, before the stream is passed to a container thread, and use that value for the checks made as the request body is received.
arturobernalg
force-pushed
the
bz70366-h2-content-length
branch
from
November 21, 2026 18:37
8db8ed7 to
d6a5a6c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70366
When a DATA frame is received,
Stream.receivedData()looks upcontent-lengthin the request headers on the connection thread (until a value has been found and cached), while the container thread may already be modifying the sameMimeHeaders(RemoteIpValveremoves and restoresX-Forwarded-For). The lookup can return the next header's value, which resets a valid request with PROTOCOL_ERROR, or miss the header, which disables the RFC 9113, section 8.1.1 check.The content length is now resolved in
receivedEndOfHeaders(), before the stream is passed to a container thread, and that value is used while the body is received. As a side effect, an invalid or duplicate content-length is rejected at the end of the headers instead of on the first DATA frame.Testing:
TestStream.testContentLengthIndependentOfHeaderChanges: a valve removes the header and the client sends 256 bytes for a declared 128. On main the request is accepted (200); with the fix the stream is reset with PROTOCOL_ERROR.RemoteIpValve, 32 concurrent POSTs withX-Forwarded-For: 2 of 10 five-second runs were reset withNumberFormatException: For input string: "Java-http-client/27"(the User-Agent value). With the fix, 0 of 20.org.apache.coyote.http2tests pass.