Conversation
Split _reject_illegal_characters into a name half and a value half, and run the name half from validate_outbound_headers as well. The four name classes from RFC 9113 section 8.2.1 were checked on the inbound path only. Classes 2, 3 and 4 went out on the wire untouched; class 1 was normalised away by _lowercase_header_names with defaults, but not with normalize_outbound_headers=False. The value rules (NUL/LF/CR and surrounding whitespace) stay inbound-only: _strip_surrounding_whitespace already normalises the whitespace case on the outbound path. "Received uppercase header name" is now direction-neutral, since the check runs both ways. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Follow-up to #1325, as discussed there in #1325 (comment).
Cause
_reject_illegal_charactersis called fromvalidate_headersbut not fromvalidate_outbound_headers. Once #1325 lands it is the only check in the inbound chain with no outbound counterpart.It could not simply be added to the outbound chain, because it carries two value rules in addition to the four name classes of RFC 9113 section 8.2.1.
Change
_reject_illegal_charactersis split into_reject_illegal_name_characters(uppercase 0x41-0x5a,<= 0x20,>= 0x7f, colon after position 0) and_reject_illegal_value_characters(NUL/LF/CR, surrounding SP/HTAB).validate_headerscalls both in the previous order, so inbound behaviour is unchanged.validate_outbound_headerscalls the name half only, first in the chain, mirroring the inbound order.The value rules deliberately stay inbound-only:
_strip_surrounding_whitespacealready normalises the whitespace case before outbound validation, so enabling that half would only change behaviour fornormalize_outbound_headers=False.The uppercase message is made direction-neutral (
Uppercase header name present: ...) because the check now runs both ways; this also changes the inbound message.Received header value surrounded by whitespaceis left alone, as that rule is still inbound-only.Measured
Through
send_headers, decoding what reaches the wire:X-Foo(class 1)x-fooX-Foox-foofoo bar(class 2)foo\x7f(class 3)foo:bar(class 4)src/h2/utilities.pyis +21/-5. Seven of the eleven added tests fail against the unmodified file; the other four are regression guards that pass either way. Full suite 1673 passed,ruff check src/andmypy --strict-bytesclean.Note
This touches
validate_outbound_headersinutilities.py, the same function as #1325. Whichever lands second, I will rebase it.🤖 Generated with Claude Code