Repository navigation
fix(mux-h2): spare in-flight frames on a reset stream, discard CONTINUATION of dropped blocks - #1784
Merged
Merged
Conversation
After Sozu sent RST_STREAM on a stream, a frame the peer had sent before reading the reset was treated as a protocol error: a HEADERS frame was answered GOAWAY(STREAM_CLOSED), ending every other stream of the connection, and a DATA frame a second RST_STREAM(STREAM_CLOSED). RFC 9113 section 5.1 requires such frames to be ignored. H2StreamTable::remove now remembers the last 64 reset streams it evicts, and handle_read ignores the frames on a stream reset_by_us recognises: a HEADERS block is still decoded through H2State::Discard to keep the HPACK dynamic table in sync (section 4.3), a DATA payload is only credited to connection flow control (section 6.9), and each counts as a glitch. Repoint the h2.rs citations of doc/h2_mux_internals.md the insertion moved. Closes #1783 Signed-off-by: Florentin Dubois <[email protected]>
…t DATA A discarded header block without END_HEADERS, on a stream reset by this endpoint or refused at its HEADERS frame, left its CONTINUATION frames to be taken for standalone ones and answered GOAWAY(PROTOCOL_ERROR). The Discard arm now keeps the block's fragment in pending_discarded_block, so the CONTINUATION frames on that stream are discarded with it and the block is decoded whole for HPACK (RFC 9113 sections 4.3, 6.10); any other frame in between is a PROTOCOL_ERROR. Ignored DATA on a reset stream no longer counts a flood glitch while it fits the stream's receive window, what the peer may have had in flight (section 6.9); DATA beyond it still does, and header blocks do not. reset_by_us looks the evicted streams up in a set. Tests cover a trailer block split over CONTINUATION, the client-facing side, DATA on a reset stream still tracked, both sides of the DATA allowance, and a refused block's CONTINUATION. Narrow the docs to the frame types that are ignored. Refs #1783 Signed-off-by: Florentin Dubois <[email protected]>
Every header block on a stream reset by this endpoint was decoded and counted as in flight, so a peer could repeat them without bound and without a glitch. A reset stream now gets two header blocks for free, a trailer section or an interim and a final response (RFC 9113 section 8.1); each block beyond counts one glitch, so the glitch limit ends the connection with GOAWAY(ENHANCE_YOUR_CALM). The first fragment of a discarded block now counts toward max_header_list_size like an accepted one's (CVE-2024-27316). Put the record_glitch doc comment back on record_glitch. Refs #1783 Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
Reconcile with #1753, which also ignores frames on a stream this endpoint reset. One path remains: a single read-side branch of handle_header_state, keyed on was_reset_locally (rst_sent or #1753's ring of 256 retired streams, now indexed by a set), ignores DATA and HEADERS on a tracked or retired reset stream through #1753's discard_frame_payload, with this branch's glitch allowances (two header blocks, the stream's receive window of DATA). #1753's live-stream rst_sent check and closed-stream arms, and this branch's handle_data_frame check, are folded into it. discard_field_block keeps the CONTINUATION handling, so a dropped block without END_HEADERS on a reset stream, a stream reset for a stream error or a refused stream is discarded whole. Signed-off-by: Florentin Dubois <[email protected]>
…andling On a stream Sozu reset, in-flight frames no longer count a flood glitch, and a dropped header block without END_HEADERS is discarded with its CONTINUATION frames instead of ending the connection. Refs #1783 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
A response to HEAD only SHOULD NOT carry content (RFC 9110 section 9.3.2), unlike a 204 or a 304, which cannot (sections 15.3.5, 15.4.5). handle_data_frame now resets the backend stream only for a 204 or a 304, counted in h2.bodiless_response_data_reset, and drops the payload of a response to HEAD from the end of the stream buffer without queueing it. Kept behind storage.head, a payload larger than the buffer would remove READABLE from the backend connection before its END_STREAM. Such a stream stays linked until the backend's END_STREAM (#1776), so its DATA reaches these branches whether it arrives with the head or later. A frame-level test drives handle_data_frame through the reset, the discard and the forwarding of a GET 200. The e2e tests cover 204, 304 and HEAD with HEADERS and DATA in one write or apart, and HEAD with 20, 60 and 200 KB of DATA to an H1 and an H2 client and beside a second stream of the same backend connection. The raw H2 mock gains a single-write mode and honours sozu's flow-control windows. Repoint the h2.rs citations of doc/h2_mux_internals.md. A trailer HEADERS frame after the reset of a 204 or a 304 still gets a GOAWAY for the whole backend connection until #1784 lands. Refs #1772 Signed-off-by: Florentin Dubois <[email protected]>
Brings in #1787 and #1782; the only conflicts were pinned h2.rs line citations in doc/h2_mux_internals.md, repointed. Also fixes the merged reset-stream handling: - An empty DATA frame without END_STREAM on a stream this endpoint reset never reached handle_data_frame, so it skipped the empty-DATA flood counter (CVE-2019-9518) and fit any window allowance for free. The was_reset_locally branch now counts it toward that limit like a live stream does. - The DATA and header-block allowances are held for at most 512 reset streams: a stream refused or reset untracked stays in rst_sent and never enters the ring its allowances are dropped with. - The docs say "the stream's initial receive window", state how empty DATA counts, and note that a backend connection's allowances are bounded by the backend's own concurrency, not the emitted-RST cap. Refs #1783 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
A response to HEAD only SHOULD NOT carry content (RFC 9110 section 9.3.2), unlike a 204 or a 304, which cannot (sections 15.3.5, 15.4.5). handle_data_frame now resets the backend stream only for a 204 or a 304, counted in h2.bodiless_response_data_reset, and drops the payload of a response to HEAD from the end of the stream buffer without queueing it. Kept behind storage.head, a payload larger than the buffer would remove READABLE from the backend connection before its END_STREAM. Such a stream stays linked until the backend's END_STREAM (#1776), so its DATA reaches these branches whether it arrives with the head or later. A frame-level test drives handle_data_frame through the reset, the discard and the forwarding of a GET 200. The e2e tests cover 204, 304 and HEAD with HEADERS and DATA in one write or apart, and HEAD with 20, 60 and 200 KB of DATA to an H1 and an H2 client and beside a second stream of the same backend connection. The raw H2 mock gains a single-write mode and honours sozu's flow-control windows. Repoint the h2.rs citations of doc/h2_mux_internals.md. A trailer HEADERS frame after the reset of a 204 or a 304 still gets a GOAWAY for the whole backend connection until #1784 lands. Refs #1772 Signed-off-by: Florentin Dubois <[email protected]>
Resolve the closed-stream arms of ConnectionH2::handle_frame against #1756. This branch ignores the DATA and HEADERS a peer sent on a stream sozu reset in one earlier read-side branch, so main's was_reset_locally arms at this point (DATA if/else and HEADERS) are dropped in favour of this branch's structure. The RST_STREAM(STREAM_CLOSED) still sent for DATA on any other closed stream takes #1756's third enqueue_rst argument, RstOrigin::Local, as #1756 chose for the same site: that DATA is already counted as a glitch just above, which bounds it, and charging it to the provoked-RST cap too would count it twice. refuse_stream_and_discard and its four callers merged cleanly with #1756's origin parameter (RstOrigin::Local for every refusal). lib/src/protocol/mux/LIFECYCLE.md keeps main's rewritten RST-bound bullets and this branch's paragraph on recently reset streams; doc/h2_mux_internals.md citations are re-anchored to the merged code. Signed-off-by: Florentin Dubois <[email protected]>
header_blocks_on_a_reset_backend_stream_beyond_two_count_glitches and empty_data_frames_on_a_reset_backend_stream_count_toward_the_flood_limit flood a backend connection until GOAWAY(ENHANCE_YOUR_CALM), with a bounded number of frames sized for the flood defaults of the time. #1756 raised DEFAULT_MAX_GLITCH_COUNT and DEFAULT_MAX_EMPTY_DATA_PER_WINDOW from 100 to 2000, so after main was merged in neither flood reached its limit and both tests failed on their final GOAWAY assertion, while the counting they check still worked. Each test now sets the one limit it exercises to 100 through H2FloodConfig::from_optional, as unanswered_streams_do_not_dilute_the_reset_caps does, so it checks the counting logic whatever the defaults are. The empty-DATA test keeps the default glitch limit so its GOAWAY can only come from the empty-DATA count. No assertion changes. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
Bring in #1784; no conflict. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
…nload Bring in the base branch's merge of origin/main (#1784). Re-pin the `readable()`, `writable()` and `flush_output_to_socket()` code blocks of doc/h2_mux_internals.md to their lines in the merged h2.rs; `H2Shell::flush_tls_records` still calls `self.core.note_write_status(status)` then `self.record_write(status)`. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
…HEAD response's DATA (#1775) A response to HEAD, a 204 or a 304 has no content (RFC 9110 §6.4.1), but `ConnectionH2::handle_data_frame` forwarded a DATA payload on it. An H1 client read it after the head as the start of the next response, and an H2 client received it as DATA. - 204 and 304 cannot carry content (RFC 9110 §15.3.5, §15.4.5; RFC 9113 §8.1.1). The backend stream is reset with PROTOCOL_ERROR before the payload is queued, counted in the new `h2.bodiless_response_data_reset`. An H1 client that was already sent the head sees the connection close; one that was not gets a 502. - A response to HEAD only SHOULD NOT carry content (RFC 9110 §9.3.2). Its windows are credited, and its payload is never queued and is dropped from the end of the stream buffer. If the payload were kept in the buffer, it would only be freed when the frontend consumes a queued block, and nothing refers to it. A payload larger than the buffer would then stop the backend connection from being read before END_STREAM, stalling every stream on that connection. With #1778, such a backend stream stays linked until its END_STREAM, so its DATA reaches these branches whether it arrives with the head or later. Known limitation: after the PROTOCOL_ERROR reset of a 204 or a 304, a trailer HEADERS frame the backend had already sent on that stream still triggers a GOAWAY that ends every stream of the backend connection. This lasts until #1784 lands. Tests: - `a_backend_response_content_is_forbidden_for_204_and_304_and_discarded_for_head` (`h2.rs`) pins the classifier. - `a_204_response_carrying_data_resets_its_backend_stream_and_a_head_response_discards_it` (`h2.rs`) drives `handle_data_frame` through three cases: - the reset: RST_STREAM(PROTOCOL_ERROR) alone, no GOAWAY, payload not queued; - the HEAD discard: no frame, payload not queued, no byte left in the buffer; - a GET 200 that forwards its payload. - e2e in `e2e/src/tests/h2_security_header_injection.rs`: - `test_h2_bodiless_response_data_never_reaches_h1_client`: 204, 304 and HEAD, with HEADERS and DATA in one write or 200 ms apart. - `test_h2_head_response_with_large_data_completes`: HEAD with 20, 60 and 200 KB of DATA, to an H1 client with a keep-alive follow-up and to an H2 client. - `test_h2_head_response_with_large_data_keeps_the_backend_connection`: HEAD with 20 KB on stream 1 and a GET on stream 3 over one backend connection. - The raw H2 mock now honours sozu's flow-control windows. Documented in `lib/src/protocol/mux/LIFECYCLE.md` §8.4, `doc/configure.md` and `CHANGELOG.md`. Fixes #1772 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
…TA is ignored (#1807) The CHANGELOG entry and `lib/src/protocol/mux/LIFECYCLE.md` §8.4 from #1775 said that a trailer HEADERS frame a backend sends after the PROTOCOL_ERROR reset of a 204 or a 304 answers GOAWAY(STREAM_CLOSED) for the whole backend connection "until #1784 lands". #1784 is merged, so this PR checks that claim and rewrites the text. What the test shows: - On `2ce07244` (#1775's head before #1784), a trailer in **one HEADERS frame** was already ignored. The reset-stream branches from #1753 cover it, so the GOAWAY(STREAM_CLOSED) described there did not happen. - What did fail before #1784 was a trailer block **split over a CONTINUATION frame**: the CONTINUATION was taken for a standalone frame and answered GOAWAY(PROTOCOL_ERROR), ending every stream of the backend connection. - On `main`, both are ignored (RFC 9113 §5.1) and the backend connection stays up. Test: `a_trailer_after_the_reset_of_a_204_carrying_data_is_ignored` (`lib/src/protocol/mux/h2.rs`). It sends a 204 without END_STREAM, then DATA without END_STREAM, which is reset with PROTOCOL_ERROR. Then it sends the trailer block, once in one frame and once split over a CONTINUATION frame. For both, it asserts no GOAWAY, no RST_STREAM, and that the backend connection is still in `H2State::Header`. - Red on `2ce07244`: `split=true: ... got [(7, 0, 0, [0, 0, 0, 0, 0, 0, 0, 1])]`. The unsplit row passes there. - Red on this branch with the `pending_discarded_block` store in `ConnectionH2::handle_read` removed, with the same failure. - Green on this branch. Docs: the CHANGELOG entry for #1772 and `LIFECYCLE.md` §8.4 now describe the current behaviour and what changed with #1784, in place of the "until #1784 lands" known limitation. No production code changes. Commands run: - `cargo build --locked --all-features`: ok - `cargo clippy --all-features`: ok - `cargo test --locked --all-features -p sozu-lib --lib`: 1547 passed - `python3 .github/scripts/check_doc_citations.py --root .`: ok, also with `--base origin/main` - `cargo +nightly fmt --all -- --check`: ok `cargo clippy -p sozu-lib --all-targets --all-features -- -D warnings` fails only on the existing `chunks_exact(13)` in `h2.rs` tests, which is already on `main` (`chunks_exact_to_as_chunks`, local clippy 1.99). This PR doesn't touch it. Signed-off-by: Florentin Dubois <[email protected]>
This was referenced Oct 3, 2026
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 3, 2026
…1817) Fixes #1815 ## What A stream Sōzu refuses with `RST_STREAM(REFUSED_STREAM)` is never registered, and `ConnectionH2::enqueue_rst` only records registered streams, so the bounded recently-reset set (#1784) did not know it. #1798 documented the result as an accepted limitation. Frames the client sent on the stream before it read the refusal were not ignored: - request trailers ended the connection with `RST_STREAM(REFUSED_STREAM)`, `RST_STREAM(STREAM_CLOSED)`, `GOAWAY(PROTOCOL_ERROR)` (`GOAWAY(STREAM_CLOSED)` once a later stream was accepted), and every stream in flight went with it. A graceful drain could end with `PROTOCOL_ERROR` instead of `NO_ERROR`; - each DATA frame cost one glitch and one `RST_STREAM(STREAM_CLOSED)`. RFC 9113 §5.1 says those frames are ignored. The §5.1.1 `PROTOCOL_ERROR` reasoning only holds for ids the client skipped. ## Design `H2StreamTable::remember_refused` pushes a refused id onto the `recently_reset` ring. The push/evict block of `H2StreamTable::remove` moves into a shared private helper, so refused ids get the same bound (256), the same eviction, and their allowances are dropped along with them. It is called at every refusal: - `ConnectionH2::refuse_stream_and_discard`: draining, `SETTINGS_MAX_CONCURRENT_STREAMS`, buffer-pool exhaustion, and the oversized CONTINUATION block. That last one removes its stream before refusing it, so without this it would be the only refusal still unremembered; - the soft flood refusal branch, which calls `enqueue_rst` itself to skip SETTINGS back-pressure. HEADERS and DATA on a refused id now take the existing `was_reset_locally` branch of `handle_header_state`. HEADERS blocks are decoded so HPACK stays in sync. DATA is credited to the connection window (`skip_orphaned_data_payload`). The existing allowances apply: two header blocks, and DATA within the stream's initial window. Past them, each frame counts one glitch, and an empty DATA frame without END_STREAM still counts toward the empty-DATA limit. Unchanged: - HEADERS on a skipped id still gets `GOAWAY(PROTOCOL_ERROR)`. The ring lookup comes before that branch, and a skipped id is never in the ring (`headers_below_a_refused_stream_id_is_a_protocol_error` stays green). - RST_STREAM never enters the reset branch, so `flood_refused_streams` / `flood_refusal_ignored` detection works as before. - No id is added to `rst_sent`. ## Trade-offs - Refused ids share the 256-entry ring with reset streams. A burst of refusals can evict a reset stream's memory earlier. Its late frames then fall back to the closed-stream rules, which is what already happens past 256 resets. - A refused id evicted from the ring gets the old behaviour back: trailers on it cost `GOAWAY(PROTOCOL_ERROR)`. - Each refused stream gets the reset-stream allowance before frames count as glitches. Allowances are held for at most `RESET_ALLOWANCES_CAPACITY` (512) streams, and every refusal still costs its own glitch once SETTINGS are acknowledged. So a client opening refused streams to spend their allowances runs into the glitch budget first. ## Tests The red runs used the new tests on `origin/main` (`6c3b8e89`) production code: - `trailers_on_a_refused_stream_are_ignored`: red, `got [RST(5, REFUSED_STREAM), RST(5, STREAM_CLOSED), GOAWAY(PROTOCOL_ERROR)]`. Green: one RST on stream 5, no GOAWAY, streams 1 and 3 survive, a later PING is answered, only the refusal costs a glitch, and an entry indexed by the ignored trailer block resolves in the connection's HPACK decoder. - `data_on_a_refused_stream_is_ignored_and_credited`: 65535 bytes in 3×16384 + 16383. Red: one `RST_STREAM(STREAM_CLOSED)` per DATA frame. Green: no RST past the refusal, no glitch past the refusal, and stream-0 WINDOW_UPDATE credit exactly equal to the 65535 bytes ignored (a double credit fails). - `a_drain_with_a_refused_upload_carrying_trailers_ends_with_no_error`: red, the first GOAWAY is `PROTOCOL_ERROR`. Green: `NO_ERROR`. - `refused_streams_share_the_recently_reset_bound` (`h2_stream_table.rs`): bound, eviction, allowances dropped, dedupe. Mutation checks: - dropping the soft-refusal `remember_refused` call fails the first two tests; - dropping the call in `refuse_stream_and_discard` fails the drain test. Every existing #1784 / #1798 test stays green and unmodified. ## Validation - `cargo +nightly fmt --check`: ok - `cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings`: ok - `RUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib`: ok - `cargo +1.93.1 test -p sozu-lib --lib --all-features --locked`: 1592 passed - `cargo test -p sozu-e2e --locked --features opentelemetry,splice,simd -- --test-threads=4 h2_security flood rapid_reset goaway`: 128 passed, 1 failed. The failure was `test_h2_rapid_reset_triggers_goaway` (no GOAWAY read within the window) at a host load average of about 80. It also fails on `origin/main` under the same load (1 run out of 3), and it passed 3 runs out of 3 on this branch at load ~50. It is load-sensitive and not affected by this change, since RST_STREAM frames do not take the changed path. - Full e2e suite: not run, the host was too loaded. - `check_doc_citations.py --self-test` and `--root . --base origin/main`: ok (renumbered the `h2.rs` line citations in `doc/h2_mux_internals.md` that moved) Docs: `doc/configure.md`, `doc/h2_mux_internals.md`, `lib/src/protocol/mux/LIFECYCLE.md`, and `CHANGELOG.md`. The #1798 entry now points to this fix, and there is a new Fixed entry. Signed-off-by: Florentin Dubois <[email protected]>
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.
Builds on #1753, which made Sōzu ignore frames on a stream it reset (RFC 9113 §5.1). Two problems remained in that handling, and this PR fixes them.
max_header_list_size.There is one code path for these frames: a single branch of
handle_header_state, keyed onH2StreamTable::was_reset_locally. That coversrst_sentplus #1753's ring of 256 retired reset streams, now indexed by a set. The branch discards through #1753'sdiscard_frame_payload. #1753's separate live-stream and closed-stream arms are folded into it.Tests (
h2.rs), each seen failing before its fix:frames_on_a_backend_stream_sozu_reset_are_ignored(trailer in one HEADERS frame or split over CONTINUATION, then a second stream using the dynamic-table entry it added)frames_on_a_client_stream_sozu_reset_are_ignoreddata_on_a_reset_backend_stream_counts_a_glitch_beyond_its_window_onlydata_on_a_tracked_backend_stream_sozu_reset_is_ignoredheader_blocks_on_a_reset_backend_stream_beyond_two_count_glitchesa_continuation_of_a_refused_header_block_is_discarded_with_ita_refused_header_block_counts_its_first_fragment_toward_its_sizeempty_data_frames_on_a_reset_backend_stream_count_toward_the_flood_limitreset_stream_allowances_stay_bounded(h2_stream_table.rs)#1753's four e2e tests still pass. Documented in
lib/src/protocol/mux/LIFECYCLE.md,doc/h2_mux_internals.mdandCHANGELOG.md.Fixes #1783