Repository navigation
fix(mux-h2): reject an out-of-range H2 listener threshold where it is stated - #1439
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 22, 2026 09:15
FlorentinDUBOIS
force-pushed
the
fix/h2-flood-config-clamp
branch
2 times, most recently
from
September 22, 2026 14:09
22fe193 to
76f431a
Compare
… 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
force-pushed
the
fix/h2-flood-config-clamp
branch
from
September 22, 2026 16:09
76f431a to
f65e88c
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.
H2FloodConfig::newclamps every threshold to>= 1and nothing inproduction called it:
get_h2_flood_configinlib/src/http.rsandlib/src/https.rsbuilt the struct with a raw literal, so onlyDefault::default()'s compile-time constants -- which never neededvalidation -- went through the clamp, and every value an operator can
actually set bypassed it.
A
0there does not disable a check.check_floodcomparescount > threshold, so it makes the first event that counter sees aviolation, with no error at load time and no log explaining it. How far
that reaches depends on the knob.
h2_max_header_list_sizeandh2_max_header_fieldsare also the HPACK decode budgetpkawa::decode_headers_with_budgetenforces, so0makes the firstheader 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 oneHEADERS frame, and as a connection
GOAWAYfor one that spansCONTINUATION frames, where
record_continuation_frameliftsaccumulated_header_sizeabove the zero threshold andcheck_flood_or_return!fires ahead of the explicit size test.h2_max_header_table_sizeis not in that class --0there only zeroesthe 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 = 0costs nothing on a connection thatnever sends RST_STREAM, since
0 > 0is false, and tears the connectiondown on the first one that does.
A debug build fired
H2FloodDetector::new's pre-condition assertioninstead -- 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 Defaultis itself anin-module struct literal and a future
DEFAULT_MAX_HEADER_LIST_SIZE = 0would otherwise pass unnoticed.
Every door that STATES a listener configuration now refuses the value.
ListenerBuilder::to_http/to_tlsreturnConfigError::H2ThresholdBelowMinimum, naming the listener, the key, thevalue and the minimum;
validate_h2_flood_knobs_http/_httpsalreadyrefused it on
UpdateHttp(s)Listener; and a raw protobufAdd{Http,Https}Listenerstraight to the command socket -- which reachedneither, so
ConfigState::add_http_listenercloned it in unvalidated andevery worker rewrote the
0to1-- is now gated bybin/src/command/requests.rs::validate_h2_knob_floors, before theaddress is reserved. All five validators expand one shared list,
for_each_h2_knob_floor!incommand/src/lib.rs, instead of keepingfive 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.
LoadStateskips an entryits 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:
flagis
count > threshold, so0trips on the FIRST counted event and theclamped
1on the second. The clamp loosens every knob it touches, byexactly one event. That is still the right trade on replay, because
0is not "no limit" and not a protection level anyone tuned -- what it
cannot do is switch detection off.
validate_requesttherefore takes aRequestOrigin:Authoredenforces the floors,Replayedkeeps thelistener and warns with the key to fix, counting
config.load_h2_knob_clamped.bin/src/cli.rs's--h2-stream-shrink-ratiohelp 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 withpubaccessors,matching
hpack_state,h2_flow_controlandh2_stream_table.H2FloodConfig::from_optional-- the same shape as the adjacentH2ConnectionConfig::from_optionalthatget_h2_connection_configalready uses -- resolves each
Noneto its default and delegates tonew, and both listeners call it. The clamp is the backstop for the onepath that deliberately does not reject. A new per-field test in each
listener pins the thirteen positional arguments
get_h2_flood_confighands
from_optional, where a transposition within the tenu32s or thethree
u64s would otherwise compile silently.Closes #1418
Signed-off-by: Florentin Dubois [email protected]