feat: validate connection-specific headers and concatenate cookies (RFC 9114 §4.2, §4.2.1) - #364
Open
bhargavamakwana wants to merge 1 commit into
Conversation
…kies
Enforces RFC 9114 §4.2, §4.2.1, and §4.3 requirements on HTTP/3 field sections:
- RFC 9114 §4.2: Treat field sections containing connection-specific headers
('connection', 'keep-alive', 'proxy-connection', 'transfer-encoding', 'upgrade')
as malformed, and prevent generating them on outgoing headers.
- RFC 9114 §4.2: Reject 'te' header unless it is on a request and its value
is 'trailers'.
- RFC 9114 §4.2.1: Automatically concatenate multiple decoded 'cookie' lines
into a single byte string using '; '.
- RFC 9114 §4.3: Reject pseudo-headers appearing in trailer sections.
- Update duvet tracking: resolve todos in 4.2.toml and 4.2.1.toml, updating
snapshot to [implementation,test].
- Add unit tests covering all forbidden connection headers, valid and invalid
TE cases, cookie folding, and trailer pseudo-headers.
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
This PR implements RFC 9114 compliance for connection-specific field sections (§4.2), the
TEheader field (§4.2), cookie line concatenation (§4.2.1), and pseudo-header restrictions in trailers (§4.3).Resolves two pending Duvet tracking items:
.duvet/todos/rfc9114/4.2.toml.duvet/todos/rfc9114/4.2.1.tomlMotivation & Background
In HTTP/3, stream multiplexing is pushed down to QUIC, rendering HTTP/1.x connection management mechanisms obsolete and invalid:
RFC 9114 §4.2 (Connection-Specific Fields):
Previously,
Field::parse()and outgoing header builders (Header::request,Header::response,Header::trailer) permitted connection-specific headers (connection,keep-alive,proxy-connection,transfer-encoding,upgrade) without rejection.RFC 9114 §4.2 (The
TEHeader):tewas previously treated as a standard header, permitting invalid values (e.g.gzip) and invalid contexts (responses/trailers).RFC 9114 §4.2.1 (Field Compression - Cookie Folding):
Header::try_from()previously retained duplicate cookie lines as separate entries inHeaderMaprather than folding them with;.RFC 9114 §4.3 (Trailers):
Incoming trailers were not checked for pseudo-headers.
Detailed Changes
h3/src/proto/headers.rs:Field::parse():connection,keep-alive,proxy-connection,transfer-encoding, andupgradewithHeaderError::ConnectionSpecificHeader.tecontains only'trailers'(ignoring ASCII whitespace and case), returningHeaderError::InvalidTeHeaderotherwise.Header::request(),Header::response(), andHeader::trailer()to validate fields and returnResult<Self, HeaderError>to enforce the "MUST NOT generate" requirement.TErestriction:Header::into_response_parts()andHeader::into_trailer_parts()rejectteif present in responses or trailers.Header::try_from(), multipleCookieheaders are automatically concatenated into a single value using;.Header::into_trailer_parts(), ensuring trailer sections contain zero pseudo-headers and no illegal connection fields.rejects_connection_specific_headers()validates_te_header()concatenates_multiple_cookie_headers()rejects_pseudo_headers_in_trailers()h3/src/server/stream.rs:HeaderErrorfromHeader::response()insend_response()asStreamErrorwith codeH3_MESSAGE_ERROR.h3/src/connection.rs:Header::into_trailer_parts(), rejecting malformed trailers withH3_MESSAGE_ERROR.HeaderErrorfromHeader::trailer()insend_trailers()..duvet/todos/rfc9114/4.2.tomland.duvet/todos/rfc9114/4.2.1.toml..duvet/snapshot.txt: requirements transitioned fromtodoto[implementation,test].Verification & Testing
Unit & Integration Tests:
cargo test --workspace).Lints:
cargo clippy --workspace --all-targetsreports 0 warnings on modified code.Duvet Report:
duvet reportverified: 148 sources scanned, 570 citations parsed, with 0 regressions.