Repository navigation
fix(http): tighten HTTP/2 version guessing so arbitrary binary is not taken for a DATA frame - #1153
Merged
Merged
Conversation
… taken for a DATA frame Since #1138 any nine octets with a small enough Length are a self-consistent HTTP/2 frame, so the fall-through in HTTP._guess_version labelled zero-heavy binary as HTTP/2: nine zero octets parsed as DATA on stream 0. - Gate the HTTP/2 trial on _test_http2_frame: an RFC 9113 frame type, no undefined flag, reserved bit clear, and the stream that type is sent on. - Explicit version=2 parsing is unchanged. - test_tcp_http_dispatch_unit's fixture was a stream-0 DATA frame; it is now an empty DATA frame on stream 1. Two test_http_unit cases that drove the HTTP/2 arm with non-frame bytes now use frame headers that pass the gate. Closes #1141
This was referenced Oct 6, 2026
Owner
Author
|
Cross-review verdict on
Inaccurate PR claim: |
Contributor
|
Coverage: 88.76% (unit tier, Python 3.14,
Per-file detail: the |
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.
Please follow the guide below
http.py, no new messages; isort--check-onlyon all four files)make testpasses, and a test case covers the change (per module only, listed below)What is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
Closes #1141 (option 2). The fall-through in
HTTP._guess_versionnow runs its HTTP/2 trial only if_test_http2_framepasses. That check requires an RFC 9113 frame type, no undefined flag, the reserved bit clear, and the stream that type is sent on (DATA, HEADERS, PRIORITY, RST_STREAM, PUSH_PROMISE and CONTINUATION on a non-zero stream; SETTINGS, PING and GOAWAY on stream 0; WINDOW_UPDATE on either). Explicitversion=2parsing is unchanged.Probe: nine zero octets went from
HTTP/2 type=0toProtocolError: unknown HTTP version. A seeded zero-heavy fuzz (5000 buffers) went from 566 HTTP/2 labels to 101, and every one left is DATA on a non-zero stream, which is a legal frame. All 18 legal frames built with Scapy'scontrib.http2(all ten types, plus ACK, padded and priority variants) are still guessed as HTTP/2.Tests: the new
test_http_guess_http2_1141_unit.pypasses 5 of 5. Withhttp.pyreverted it fails 11 (9 rejected-header subtests, the nine-zero case and the fuzz). Scapy's frames are embedded as hex, because the test leg does not install Scapy. These modules pass:test_http_unit65,test_tcp_http_dispatch_unit3,test_http_runtime5, the threetest_httpv2_*_unitmodules,test_option_coverage_runtime3,test_option_roundtrip_unit6, andtests/project385 (1 skipped).Existing tests edited: the
test_tcp_http_dispatch_unitfixture was a stream-0 DATA frame, which is exactly the case this PR now rejects; it is now000000000000000001. Twotest_http_unitcases drove the HTTP/2 arm with non-frame bytes; they now use frame headers that pass the check, so they test the same thing as before.