Repository navigation
Validate HTTP/2 response header fields and pseudo-headers - #504
Merged
Merged
Conversation
A :status value that isn't an integer, such as "abc" or "200 ", raised
ArgumentError from String.to_integer/1 inside stream/2, so a server could
crash the process streaming the response. Uppercase or otherwise invalid
field names, values containing NUL, CR or LF, undefined pseudo-headers,
duplicate :status fields, pseudo-headers after regular fields and
pseudo-headers in trailers were all delivered to the caller as if they
were regular headers.
Response header blocks are now checked against RFC 9113 8.2.1 and 8.3
before they're interpreted. A malformed block is a stream error: the
stream is reset with PROTOCOL_ERROR and the caller gets
{:invalid_status_header, value}, {:invalid_header_name, name},
{:invalid_header_value, name, value} or {:protocol_error, debug_data}.
A 1xx block after the final response is now reported as a pseudo-header
in trailers, which made the dedicated check for it unreachable.
Coverage Report for CI Build 388Coverage increased (+0.2%) to 88.627%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
ericmj
marked this pull request as ready for review
September 19, 2026 22:30
ericmj
marked this pull request as draft
September 19, 2026 23:03
ericmj
marked this pull request as ready for review
September 19, 2026 23:18
whatyouhide
approved these changes
Sep 21, 2026
ericmj
added a commit
that referenced
this pull request
Oct 25, 2026
* Validate HTTP/2 request methods, targets and header fields Mint.HTTP2.request/5 lowercased the header names it was given and HPACK-encoded everything else as is, and stream_request_body/3 did the same for trailers. A method, :path, CONNECT target, header name or header value containing CR, LF or NUL, a header name containing a space or a colon, or a value with leading or trailing whitespace was sent to the server unchanged. Mint.HTTP1 rejects all of these, and Mint.HTTP2 rejects them in responses since #504, so the behaviour of a request depended on which protocol ALPN negotiated. RFC 9113 8.2.1 forbids these characters in field names and values and says a sender must not generate such a message. HTTP/2 framing isn't confused by them, but an intermediary that forwards the request over HTTP/1.1 without re-validating the fields turns an injected CRLF into request header injection or request splitting on its back-end connection, so an application that is safe against an HTTP/1 origin isn't once the origin or a CDN in front of it enables HTTP/2. Requests and trailers are now validated before a stream is opened, with the field rules already used for responses: the method must be a token (RFC 9110 9.1), :path and the CONNECT :authority must be non-empty field values (RFC 9113 8.3.1), pseudo-header names passed by the caller must be valid field names, and trailers can't carry pseudo-headers (RFC 9113 8.1). Invalid input fails with :invalid_request_method, :invalid_request_target, :invalid_header_name or :invalid_header_value, like in Mint.HTTP1, and the connection stays open without the request taking up a stream. The messages for the two header errors no longer mention the response, since they now apply to requests as well. * Validate caller-supplied HTTP/2 method fields * Clarify HTTP/2 request field validation documentation --------- Co-authored-by: Eric Meadows-Jönsson <eric.meadows.jonsson@gmail.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.
A
:statusvalue that isn't three digits, such as"abc"or"200 ", reachedString.to_integer/1insidestream/2and raisedArgumentError. Those two calls are the only place inMint.HTTP2where server-controlled bytes reach a raising function outside the throw-based error channel, so the exception escapesMint.HTTP.stream/2rather than coming back as{:error, conn, reason, responses}. Responses already decoded for other streams in the same call go with it, and so does theconnholding the advanced HPACK decode table, so a caller that rescues is left with a connection that fails with{:compression_error, {:index_not_found, _}}on the next header block.The same pass now checks the rest of RFC 9113 8.2.1 and 8.3 on responses: uppercase and otherwise invalid field names, values containing NUL, CR or LF or surrounded by SP or HTAB, undefined pseudo-headers, a repeated
:status, pseudo-headers after regular fields, and pseudo-headers in trailers. All of those were delivered to the caller as ordinary headers before.A malformed block is a stream error, so the stream is reset with PROTOCOL_ERROR, the connection stays open, and the caller gets one of
{:invalid_status_header, value},{:invalid_header_name, name},{:invalid_header_value, name, value}or{:protocol_error, debug_data}. The 1xx-after-final-response branch is removed because a 1xx block arriving after the final response is a pseudo-header in trailers, which the new check catches first.Each of these is a MUST. RFC 9113 8.2.1 gives the four field-validity rules as "the following minimal validation of field names and values" that implementations MUST perform, and states that a response containing a field violating any of them MUST be treated as malformed. 8.3 says the same for undefined or invalid pseudo-header fields, a repeated pseudo-header field name, a pseudo-header field appearing after a regular field line, and pseudo-header fields in a trailer section; a
:statusthat isn't a three-digit code is an invalid value for the one pseudo-header 8.3.2 defines for responses, since it carries the status code from RFC 9110 15. 8.1.1 then requires that malformed responses be treated as a stream error of type PROTOCOL_ERROR, and that "Clients MUST NOT accept a malformed response", which is what Mint was doing by handing these to the caller.The one check not on that list is the empty field name, which 8.2.1 covers at SHOULD strength by way of
field-name = tokenin RFC 9110 5.1. Going the other way, the field-name check stays with the character ranges 8.2.1 enumerates and doesn't reject the non-tcharvisible characters that 5.1 also prohibits, so it's short of fulltokenvalidation rather than past it.