fix: ignore the reserved bit of an incoming HTTP/2 stream identifier - #1261
Open
pjfanning wants to merge 1 commit into
Open
fix: ignore the reserved bit of an incoming HTTP/2 stream identifier#1261pjfanning wants to merge 1 commit into
pjfanning wants to merge 1 commit into
Conversation
Motivation: `Http2FrameParsing` read the stream identifier with a plain `readIntBE()`, keeping the reserved high bit, and carried a TODO saying the bit should be checked. RFC 9113 5.1.1 says the bit is reserved and MUST be ignored when receiving. Keeping it means a peer that sets it produces a negative stream id, which never matches the stream the frame is really for: `streamFor` treats it as closed and the connection is failed with a GOAWAY instead of the frame being handled on its stream. Modification: Mask the reserved bit off (`& 0x7FFFFFFF`) when reading the identifier and replace the TODO with the rule it was standing in for. Result: A frame whose stream identifier carries the reserved bit is handled on the stream it names, as the spec requires, rather than failing the connection. Tests: - sbt "http2-tests/testOnly org.apache.pekko.http.impl.engine.http2.Http2ServerSpec org.apache.pekko.http.impl.engine.http2.Http2ClientSpec org.apache.pekko.http.impl.engine.http2.framing.Http2FramingSpec" - pass (189 tests); a new test sends HEADERS for stream 1 with the reserved bit set and expects the request to be dispatched. Verified it fails with the fix stashed (the connection is failed instead). - sbt http-core/mimaReportBinaryIssues - pass (internal impl.engine.http2 change, no public API). References: None - ignores the reserved stream identifier bit per RFC 9113 5.1.1
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.
Motivation
Http2FrameParsingread the stream identifier with a plainreadIntBE(), keeping the reserved high bit, and carried a TODO saying the bit should be checked:RFC 9113 §5.1.1 says the bit is reserved and MUST be ignored when receiving. Keeping it means a peer that sets it produces a negative stream id, which never matches the stream the frame is really for:
streamFortreats it as closed and the connection is failed with a GOAWAY instead of the frame being handled on its stream.Modification
Mask the reserved bit off (
& 0x7FFFFFFF) when reading the identifier, and replace the TODO with the rule it was standing in for.Result
A frame whose stream identifier carries the reserved bit is handled on the stream it names, as the spec requires, rather than failing the connection.
Tests
sbt "http2-tests/testOnly org.apache.pekko.http.impl.engine.http2.Http2ServerSpec org.apache.pekko.http.impl.engine.http2.Http2ClientSpec org.apache.pekko.http.impl.engine.http2.framing.Http2FramingSpec"— pass (189 tests). A new test sends HEADERS for stream 1 with the reserved bit set and expects the request to be dispatched. Verified it fails with the fix stashed (the connection is failed instead).sbt http-core/mimaReportBinaryIssues— pass (internalimpl.engine.http2change, no public API).scalafmton the changed files — clean.References
None - ignores the reserved stream identifier bit per RFC 9113 §5.1.1
🤖 Generated with Claude Code