Skip to content

fix(mux-h2): reject an out-of-range H2 listener threshold where it is stated - #1439

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/h2-flood-config-clamp
Sep 22, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/h2-flood-config-clamp

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

H2FloodConfig::new clamps every threshold to >= 1 and nothing in
production called it: get_h2_flood_config in lib/src/http.rs and
lib/src/https.rs built the struct with a raw literal, so only
Default::default()'s compile-time constants -- which never needed
validation -- went through the clamp, and every value an operator can
actually set bypassed it.

A 0 there does not disable a check. check_flood compares
count > threshold, so it makes the first event that counter sees a
violation, with no error at load time and no log explaining it. How far
that reaches depends on the knob. h2_max_header_list_size and
h2_max_header_fields are also the HPACK decode budget
pkawa::decode_headers_with_budget enforces, so 0 makes the first
header field of every block exceed it (name + value + the 32-octet
RFC 9113 6.5.2 overhead) and every request on the listener is refused
with ENHANCE_YOUR_CALM: per stream for a header block that fits one
HEADERS frame, and as a connection GOAWAY for one that spans
CONTINUATION frames, where record_continuation_frame lifts
accumulated_header_size above the zero threshold and
check_flood_or_return! fires ahead of the explicit size test.
h2_max_header_table_size is not in that class -- 0 there only zeroes
the HPACK encoder's dynamic table. The per-window and lifetime frame
counters are inert until a client sends the frame they count:
h2_max_rst_stream_per_window = 0 costs nothing on a connection that
never sends RST_STREAM, since 0 > 0 is false, and tears the connection
down on the first one that does.

A debug build fired H2FloodDetector::new's pre-condition assertion
instead -- an assertion whose comment blamed a "raw struct literal in a
future caller" that was already there. It now covers all thirteen
thresholds rather than five, because impl Default is itself an
in-module struct literal and a future DEFAULT_MAX_HEADER_LIST_SIZE = 0
would otherwise pass unnoticed.

Every door that STATES a listener configuration now refuses the value.
ListenerBuilder::to_http/to_tls return
ConfigError::H2ThresholdBelowMinimum, naming the listener, the key, the
value and the minimum; validate_h2_flood_knobs_http/_https already
refused it on UpdateHttp(s)Listener; and a raw protobuf
Add{Http,Https}Listener straight to the command socket -- which reached
neither, so ConfigState::add_http_listener cloned it in unvalidated and
every worker rewrote the 0 to 1 -- is now gated by
bin/src/command/requests.rs::validate_h2_knob_floors, before the
address is reserved. All five validators expand one shared list,
for_each_h2_knob_floor! in command/src/lib.rs, instead of keeping
five copies of the same fifteen knobs: adding a knob to one door and
forgetting another is how this bug would come back one level up, and it
is no longer expressible.

Replay is deliberately NOT one of those doors. LoadState skips an entry
its pre-dispatch validation rejects, and a skipped listener never binds,
so applying the rejection there would take every frontend behind an
already-serving listener offline -- an HTTPS listener takes its whole TLS
surface with it -- to prevent one clamped threshold. The other two gates
reject configurations that cannot function; an out-of-range threshold
builds, clamps, and serves. Be exact about the clamp's direction: flag
is count > threshold, so 0 trips on the FIRST counted event and the
clamped 1 on the second. The clamp loosens every knob it touches, by
exactly one event. That is still the right trade on replay, because 0
is not "no limit" and not a protection level anyone tuned -- what it
cannot do is switch detection off. validate_request therefore takes a
RequestOrigin: Authored enforces the floors, Replayed keeps the
listener and warns with the key to fix, counting
config.load_h2_knob_clamped. bin/src/cli.rs's
--h2-stream-shrink-ratio help said "must be >= 1" against a floor of 2,
on both the HTTP and the HTTPS update subcommand; with the floor now
single-sourced, the help agrees with it.

H2FloodConfig's thirteen fields become private with pub accessors,
matching hpack_state, h2_flow_control and h2_stream_table.
H2FloodConfig::from_optional -- the same shape as the adjacent
H2ConnectionConfig::from_optional that get_h2_connection_config
already uses -- resolves each None to its default and delegates to
new, and both listeners call it. The clamp is the backstop for the one
path that deliberately does not reject. A new per-field test in each
listener pins the thirteen positional arguments get_h2_flood_config
hands from_optional, where a transposition within the ten u32s or the
three u64s would otherwise compile silently.

Closes #1418

Signed-off-by: Florentin Dubois [email protected]

@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/h2-flood-config-clamp branch 2 times, most recently from 22fe193 to 76f431a Compare September 22, 2026 14:09
… stated

`H2FloodConfig::new` clamps every threshold to `>= 1` and nothing in
production called it: `get_h2_flood_config` in `lib/src/http.rs` and
`lib/src/https.rs` built the struct with a raw literal, so only
`Default::default()`'s compile-time constants -- which never needed
validation -- went through the clamp, and every value an operator can
actually set bypassed it.

A `0` there does not disable a check. `check_flood` compares
`count > threshold`, so it makes the first event that counter sees a
violation, with no error at load time and no log explaining it. How far
that reaches depends on the knob. `h2_max_header_list_size` and
`h2_max_header_fields` are also the HPACK decode budget
`pkawa::decode_headers_with_budget` enforces, so `0` makes the first
header field of every block exceed it (name + value + the 32-octet
RFC 9113 6.5.2 overhead) and every request on the listener is refused
with `ENHANCE_YOUR_CALM`: per stream for a header block that fits one
HEADERS frame, and as a connection `GOAWAY` for one that spans
CONTINUATION frames, where `record_continuation_frame` lifts
`accumulated_header_size` above the zero threshold and
`check_flood_or_return!` fires ahead of the explicit size test.
`h2_max_header_table_size` is not in that class -- `0` there only zeroes
the HPACK encoder's dynamic table. The per-window and lifetime frame
counters are inert until a client sends the frame they count:
`h2_max_rst_stream_per_window = 0` costs nothing on a connection that
never sends RST_STREAM, since `0 > 0` is false, and tears the connection
down on the first one that does.

A debug build fired `H2FloodDetector::new`'s pre-condition assertion
instead -- an assertion whose comment blamed a "raw struct literal in a
future caller" that was already there. It now covers all thirteen
thresholds rather than five, because `impl Default` is itself an
in-module struct literal and a future `DEFAULT_MAX_HEADER_LIST_SIZE = 0`
would otherwise pass unnoticed.

Every door that STATES a listener configuration now refuses the value.
`ListenerBuilder::to_http`/`to_tls` return
`ConfigError::H2ThresholdBelowMinimum`, naming the listener, the key, the
value and the minimum; `validate_h2_flood_knobs_http`/`_https` already
refused it on `UpdateHttp(s)Listener`; and a raw protobuf
`Add{Http,Https}Listener` straight to the command socket -- which reached
neither, so `ConfigState::add_http_listener` cloned it in unvalidated and
every worker rewrote the `0` to `1` -- is now gated by
`bin/src/command/requests.rs::validate_h2_knob_floors`, before the
address is reserved. All five validators expand one shared list,
`for_each_h2_knob_floor!` in `command/src/lib.rs`, instead of keeping
five copies of the same fifteen knobs: adding a knob to one door and
forgetting another is how this bug would come back one level up, and it
is no longer expressible.

Replay is deliberately NOT one of those doors. `LoadState` skips an entry
its pre-dispatch validation rejects, and a skipped listener never binds,
so applying the rejection there would take every frontend behind an
already-serving listener offline -- an HTTPS listener takes its whole TLS
surface with it -- to prevent one clamped threshold. The other two gates
reject configurations that cannot function; an out-of-range threshold
builds, clamps, and serves. Be exact about the clamp's direction: `flag`
is `count > threshold`, so `0` trips on the FIRST counted event and the
clamped `1` on the second. The clamp loosens every knob it touches, by
exactly one event. That is still the right trade on replay, because `0`
is not "no limit" and not a protection level anyone tuned -- what it
cannot do is switch detection off. `validate_request` therefore takes a
`RequestOrigin`: `Authored` enforces the floors, `Replayed` keeps the
listener and warns with the key to fix, counting
`config.load_h2_knob_clamped`. `bin/src/cli.rs`'s
`--h2-stream-shrink-ratio` help said "must be >= 1" against a floor of 2,
on both the HTTP and the HTTPS update subcommand; with the floor now
single-sourced, the help agrees with it.

`H2FloodConfig`'s thirteen fields become private with `pub` accessors,
matching `hpack_state`, `h2_flow_control` and `h2_stream_table`.
`H2FloodConfig::from_optional` -- the same shape as the adjacent
`H2ConnectionConfig::from_optional` that `get_h2_connection_config`
already uses -- resolves each `None` to its default and delegates to
`new`, and both listeners call it. The clamp is the backstop for the one
path that deliberately does not reject. A new per-field test in each
listener pins the thirteen positional arguments `get_h2_flood_config`
hands `from_optional`, where a transposition within the ten `u32`s or the
three `u64`s would otherwise compile silently.

Closes #1418

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/h2-flood-config-clamp branch from 76f431a to f65e88c Compare September 22, 2026 16:09
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 1a4ac51 into main Sep 22, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mux-h2: H2FloodConfig::new's threshold clamp has no production caller, so an operator-set zero threshold reaches the detector unvalidated

1 participant