Repository navigation
Description
H2FloodConfig::new clamps every per-window threshold to at least 1. Nothing in production calls it.
git grep "H2FloodConfig::new" -- lib/ bin/ returns exactly one hit, and it is a comment mentioning
the function. The two paths that actually build a flood config from operator settings —
lib/src/http.rs's get_h2_flood_config and its https.rs sibling — use a raw struct literal:
fn get_h2_flood_config(&self) -> crate::protocol::mux::H2FloodConfig {
let defaults = crate::protocol::mux::H2FloodConfig::default();
crate::protocol::mux::H2FloodConfig {
max_rst_stream_per_window: self
.config
.h2_max_rst_stream_per_window
.unwrap_or(defaults.max_rst_stream_per_window),
...So Default::default()'s compile-time constants are the only values that ever see validation, and
they never needed it. Every value an operator can actually set bypasses the clamp.
The defence that exists already knows about this, and has the tense wrong
H2FloodDetector::new carries a debug_assert! with this comment:
Pre-condition: thresholds are already validated (clamped to >= 1 by
H2FloodConfig::new). A zero
per-window threshold would trip on the first counted frame; assert it here so a config that bypassed
new(raw struct literal in a future caller) is caught in debug.
The future caller is already here. get_h2_flood_config predates the comment, and it is not some
hypothetical — it is the only way listener configuration reaches the detector.
Which means the pre-condition the assertion documents has never held on the path that matters, and the
comment's premise — "thresholds are already validated" — is false as written.
What actually happens
An operator setting h2_max_rst_stream_per_window = 0 (or any of the other per-window thresholds) in
their listener configuration gets it through unclamped.
- Debug, test and fuzz builds:
H2FloodDetector::new's assertion fires at connection setup. - Release builds: the assertion is compiled out, the threshold stays zero, and
check_floodtrips
on the first counted frame of every H2 connection — the proxy answersENHANCE_YOUR_CALMand
tears down, for every client, immediately.
This is fail-closed and operator-triggered rather than attacker-reachable, which is the right failure
direction. But it is a total outage for that listener produced by a single number in a config file,
with no error at load time and no log explaining it, and the code already contains the clamp that would
have prevented it.
Resolution — the choice is where to validate, not whether
Call the constructor. Change get_h2_flood_config (and the https.rs sibling) to build through
H2FloodConfig::new so the clamp applies. Smallest change, and it makes the existing debug_assert!'s
comment true for the first time.
Or validate at config load, and reject rather than clamp. A threshold of zero is almost certainly a
mistake rather than an intent, and silently rewriting it to 1 hides the mistake from the operator. This
is where an error message can name the key and the value, and it is consistent with how other
cross-field configuration constraints are handled in command/src/config.rs.
Doing both is defensible: reject at load for the operator's benefit, clamp at construction so no future
caller can reintroduce the gap.
Whichever is chosen, the debug_assert!'s comment needs correcting — it currently asserts a
pre-condition that does not hold.
Related, and the reason the struct is shaped this way
H2FloodConfig's fields are fully pub precisely so http.rs/https.rs can build it by literal.
That was reasonable when it was written and it is why the extraction of the flood detector into
lib/src/protocol/mux/h2_flood_detector.rs deliberately kept them public rather than widening that
changeset's blast radius into the listener code. Every sibling module extracted in that series
(hpack_state, h2_flow_control, h2_stream_table) made its fields private, and doing so is what
turned a documented invariant into a compile error in one of them. This is the one that did not, and
this issue is the cost of that.
What I verified, and what I did not
Verified by reading at 595920e91c4528f0554410b904b45d543c88e467: that H2FloodConfig::new has no
production caller, that get_h2_flood_config builds by struct literal from
self.config.h2_max_* options, that H2FloodDetector::new's debug_assert! covers
max_rst_stream_per_window, max_ping_per_window, max_settings_per_window,
max_continuation_frames and max_glitch_count, and the text of the comment quoted above.
Not verified: no runtime reproduction with an actual TOML setting a zero threshold was attempted.
The release-build consequence above is read from check_flood's comparisons, not observed.
Activity
fix(command): reject and structurally clamp command_buffer_size > max…
fix(mux-h2): reject an out-of-range H2 listener threshold where it is…
fix(command): reject and structurally clamp command_buffer_size > max…
fix(command): reject and structurally clamp command_buffer_size > max…
fix(mux-h2): reject an out-of-range H2 listener threshold where it is…
fix(mux-h2): reject an out-of-range H2 listener threshold where it is…
fix(cli): name the load-balancing values the parser actually accepts (#…
fix(mux-h2): reject an out-of-range H2 listener threshold where it is…