Fix substring check used instead of equality for cookie header name#1313
Open
bysiber wants to merge 2 commits intopython-hyper:masterfrom
Open
Fix substring check used instead of equality for cookie header name#1313bysiber wants to merge 2 commits intopython-hyper:masterfrom
bysiber wants to merge 2 commits intopython-hyper:masterfrom
Conversation
The `in` operator on `bytes` performs substring search, not equality. `header[0] in b"cookie"` matches any header name that is a substring of "cookie" (e.g. b"co", b"ok", b"e"), not just b"cookie" itself. This means short header names that happen to be substrings of "cookie" get incorrectly promoted to NeverIndexedHeaderTuple when their value is under 20 bytes, potentially affecting HPACK compression behavior. Changed both occurrences to use `==` for exact comparison: - Line 91: cookie header check in _secure_headers - Line 350: :method pseudo-header check in _reject_pseudo_header_fields
Member
|
Thanks! This might be a left-over from the time when we had bytes and strings to compare against. |
- Add test data with header names that are substrings of 'cookie' but not equal to 'cookie' to verify they are not treated as sensitive - Add test for extract_method_header to verify substring names like ':me' do not falsely match ':method'
Author
|
Added regression tests:
All 324 tests in the affected files pass. |
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.
Summary
Fix
_secure_headersincorrectly matching header names that are substrings of"cookie".Problem
In
_secure_headers, the cookie header check uses:The
inoperator onbytesperforms substring search, not equality. This means any header name that is a byte-level substring ofb"cookie"will match:Any such header with a value shorter than 20 bytes will be incorrectly promoted to a
NeverIndexedHeaderTuple, which tells HPACK to never add it to the dynamic compression table. While the security impact is minimal (the wrong headers are over-protected, not under-protected), it changes the HPACK encoding behavior in unexpected ways and could affect compression efficiency.The same pattern exists in
_reject_pseudo_header_fieldsfor the:methodcheck, though it is harmless in practice because only validated pseudo-headers reach that point.Fix
Change both
inchecks to==for exact equality: