http/2: bound incoming header blocks with max-header-list-size - #1216
Open
pjfanning wants to merge 1 commit into
Open
http/2: bound incoming header blocks with max-header-list-size#1216pjfanning wants to merge 1 commit into
pjfanning wants to merge 1 commit into
Conversation
Motivation: The HTTP/2 header decompression stage had no upper bound on the incoming side. The HPACK decoder was constructed with Http2Protocol.InitialMaxHeaderListSize (Int.MaxValue) and the header block fragments of a HEADERS frame and its CONTINUATION frames were accumulated until END_HEADERS was seen, so the memory used for a single header block was limited only by what the peer chose to send. Neither endpoint advertised SETTINGS_MAX_HEADER_LIST_SIZE, so a peer had no way of knowing what it may send either. Modification: Add a `max-header-list-size` setting (64 KiB by default) to `pekko.http.server.http2` and `pekko.http.client.http2` and pass it to `HeaderDecompression`, which now * constructs the HPACK decoder with that limit and checks the truncation result of `Decoder.endHeaderBlock()`, which was previously ignored, * applies the same limit to the accumulated header block fragments, accounting each fragment with its frame header size so that the number of empty CONTINUATION frames per header block is bounded as well, * fails the connection with GOAWAY(ENHANCE_YOUR_CALM) when the limit is exceeded. The configured value is advertised to the peer in the initial SETTINGS frame. Result: The memory used for a single incoming header block is bounded by the configured limit on both the server and the client side, and peers are told about the limit up front. Tests: - sbt "http2-tests/testOnly org.apache.pekko.http.impl.engine.http2.Http2ServerSpec" - pass, 5 new tests - sbt http2-tests/test - pass - sbt http-core/test - pass (HostConnectionPoolSpec flaked in the full run, passes on its own) - sbt +http-core/mimaReportBinaryIssues - pass - sbt http-core/scalafmt http2-tests/Test/scalafmt - clean - sbt http-core/headerCreateAll - no changes References: None - bounds the memory used for incoming HTTP/2 header blocks
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.
Motivation
The HTTP/2 header decompression stage has no upper bound on the incoming side. The HPACK decoder is constructed with
Http2Protocol.InitialMaxHeaderListSize(Int.MaxValue) and the header block fragments of a HEADERS frame and its CONTINUATION frames are accumulated until END_HEADERS is seen, so the memory used for a single header block is limited only by what the peer chooses to send. Neither endpoint advertisesSETTINGS_MAX_HEADER_LIST_SIZE, so a peer has no way of knowing what it may send either.Modification
Add a
max-header-list-sizesetting (64 KiB by default) topekko.http.server.http2andpekko.http.client.http2and pass it toHeaderDecompression, which nowDecoder.endHeaderBlock(), which was previously ignored (it carried aTODO),GOAWAY(ENHANCE_YOUR_CALM)when the limit is exceeded.The configured value is advertised to the peer in the initial SETTINGS frame.
The limit counts header name and value bytes only, while peers add the 32 octets per field that RFC 9113 section 6.5.2 prescribes, so the effective limit for a well-behaved peer is a little stricter than the configured number. 64 KiB is well above what is seen in practice (Netty and Jetty default to 8 KiB) and below what HTTP/1.1 accepts here today (
max-header-count×max-header-value-length), but I am happy to change the default if you would prefer another value.Scala and Java DSL settings are in parity,
@since 2.0.0is on the new public methods, and MiMa filters are added for the new trait members (needed on Scala 3).Result
The memory used for a single incoming header block is bounded by the configured limit on both the server and the client side, and peers are told about the limit up front. HTTP/1.1 paths are untouched: the setting and the new checks live entirely in the HTTP/2 hpack stage, and the h2c upgrade path picks the limit up from the same server settings.
Tests
sbt "http2-tests/testOnly org.apache.pekko.http.impl.engine.http2.Http2ServerSpec"- pass; 5 new tests covering an unfinished header block that grows past the limit, an unfinished header block made of empty CONTINUATION frames, a header block that decodes past the limit, a within-limit request that still succeeds, and the SETTINGS advertisementsbt http2-tests/test- passsbt http-core/test- pass (HostConnectionPoolSpecflaked in the full run and passes on its own)sbt +http-core/mimaReportBinaryIssues- passsbt http-core/scalafmt http2-tests/Test/scalafmt- cleansbt http-core/headerCreateAll- no changesReferences
None - bounds the memory used for incoming HTTP/2 header blocks