Enforce HTTP/2 MAX_CONCURRENT_STREAMS with REFUSED_STREAM - #40
Open
ulfjack wants to merge 2 commits into
Open
Conversation
For locally-served chunked requests the only size guard compared
maxDecodedBodyBytes against ChunkedBodyScanner.decodedByteCount(), which counts
only chunk DATA bytes. Chunk-extension (SIZE_EXT), trailer, and unrecognized
size-line bytes are consumed uncounted while every raw byte is still forwarded
to LocalHttpRequestStage's unbounded bodyBuffer, so an endless chunk-extension
("1;AAAA...") or trailer buffers to OutOfMemoryError regardless of the
configured ceiling — one unauthenticated connection crashes the JVM.
Have ChunkedBodyScanner track rawByteCount() (framing + data) alongside
decodedByteCount(), and enforce a total raw-byte ceiling in
HttpServerStage.readBody next to the decoded one: 2x maxDecodedBodyBytes + 8 KiB
(finite, proportional so it does not false-positive on legitimate many-chunk
bodies; off when the policy is unlimited). Per-element caps alone don't suffice
— many tiny data chunks each with a capped extension still aggregate past the
decoded ceiling; a raw bound covers all framing variants. Also give the SIZE
state a terminal else so a non-hex size-line byte errors (400) instead of being
silently consumed.
Tests: ChunkedBodyScannerTest.invalidCharInSizeLine_setsError and
rawByteCount_countsFramingAndData;
ChunkedBodyIntegrationTest.chunkedFramingBytesBoundedBy413 (20 KB extension
under an 8-byte policy -> 413).
Verification (background; SKIP_PRECOMMIT=1, inline coverage exceeds the 2-min
foreground limit):
* bazel test //... 18/18 (--flaky_test_attempts=3)
* coverage-gate 92.43% (7837/8479) >= 90%
* bazel run //:format.check clean
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
We advertise SETTINGS_MAX_CONCURRENT_STREAMS=100 but never enforced it, so a peer that ignores the advertised limit could open unbounded streams and grow the streams map (and, transitively, heldRequests) without limit. Refuse a HEADERS frame that would exceed the limit with RST_STREAM (REFUSED_STREAM, retryable) instead of opening the stream (RFC 9113 §5.1.2). The streams map holds exactly the open/half-closed streams that count toward the limit, and heldRequests entries are a subset of open streams, so both are now bounded. HPACK is decoded first so the connection-global dynamic table stays in sync whether or not the stream is refused. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ulfjack
force-pushed
the
ulfjack/sec-hardening-2
branch
from
August 10, 2026 17:16
1e0f663 to
e48d13d
Compare
ulfjack
force-pushed
the
ulfjack/sec-hardening-3
branch
from
August 10, 2026 17:16
51d3caf to
412a3e5
Compare
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.
We advertise SETTINGS_MAX_CONCURRENT_STREAMS=100 but never enforced it, so
a peer that ignores the advertised limit could open unbounded streams and
grow the streams map (and, transitively, heldRequests) without limit.
Refuse a HEADERS frame that would exceed the limit with RST_STREAM
(REFUSED_STREAM, retryable) instead of opening the stream (RFC 9113 §5.1.2).
The streams map holds exactly the open/half-closed streams that count toward
the limit, and heldRequests entries are a subset of open streams, so both are
now bounded. HPACK is decoded first so the connection-global dynamic table
stays in sync whether or not the stream is refused.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com