Repository navigation
test(e2e): decode the :status field instead of scanning for its digits - #1365
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 20, 2026 10:39
FlorentinDUBOIS
force-pushed
the
fix/h2-sni-strict-off-421
branch
from
September 20, 2026 11:23
6a700d2 to
92c759e
Compare
Closes #1353. `e2e_h2_sni_authority_mismatch_allowed_when_strict_binding_disabled` reported `infra_ok=true got_ok=true got_421=true metric_stable=true foo_reqs=0 bar_reqs=1` on a nightly cell, then passed on a re-run of the same commit. No 421 was ever emitted. `headers_status_matches` asked `payload.windows(3).any(|w| w == b"421")` of an HPACK field block, which is not text. Every Sōzu response carries `Sozu-Id`, the session's 26-character Crockford base-32 ULID (`lib/src/protocol/kawa_h1/editor.rs:1131`), and Kawa writes literal values with the Huffman bit clear, so it lands in the block as plain ASCII. That alphabet holds every decimal digit, so a 3-digit needle matches an ordinary 200 about once in 1400 responses. A capture of the passing case reads `88 0f 0d 01 '8' 40 07 "sozu-id" 1a 01M2Z5AGKTYKJM9MFQY89EJMJ9` — one indexed `:status 200`, a `content-length`, and the correlation id. The proxy is innocent by construction. The only 421 on this path is `set_default_answer(stream, front_readiness, 421, &answers)` (`lib/src/protocol/mux/mod.rs:1306`), reachable only through `RetrieveClusterError::SniAuthorityMismatch`, which is constructed at exactly one site (`lib/src/protocol/mux/router.rs:672`) immediately after `incr!(names::http::SNI_AUTHORITY_MISMATCH)` — and the failing run reported that counter unmoved next to a correct backend request count. `decode_status` reads the `:status` field that RFC 9113 §8.3.2 puts first in a response block, in the two shapes Kawa emits: an indexed static entry over indices 8..=14, or a literal over one of those name indices carrying three unhuffmanned ASCII digits. It joins `h2_utils`, which already held the frame helpers, alongside `headers_status_matches`, because the scan had three copies and the reported one was not the dangerous one: - `h2_security_sni.rs` — the #1353 site. A false positive turns a test red. - `listener_update_tests.rs::try_strict_sni_binding_toggle` — the same needle feeding `got_rejection_or_421`, which gates the `strict_sni_binding=true` *rejection* assertion. A false positive there turns a security test silently green, so a listener that had stopped rejecting would still have passed. Its `got_200` probe moves off `contains(&0x88)` in the same block, with the direction of its new false negative recorded: `decode_status` yields `None` on a size-update-prefixed block, and `got_200` enters `phase1_ok` as `|| !got_200`, so that one is fail-open rather than fail-closed. - `h2_tests.rs::try_h2_default_answer_terminates_stream` — `b"404"`. Its OR with a match on the answer body widened the needle rather than guarding it and is deleted; the test passes on the decoded `:status` alone. `headers_ok_response` goes through the same decode, and that half needed a third fixture to carry weight: a captured 421 block is pure ASCII, so it holds no `0x88` and cannot falsify the historical `payload.contains(&0x88)` body. Reverting that one function left the guard green. `stray_indexed_200` — a captured 421 with a trailing `0x88` — fixes that, and the property it pins is wire-reachable rather than theoretical: `0x88` in a block does not imply `:status 200`. RFC 7541 §5.1 writes a value length ≥ 127 as a 7-bit prefix plus continuation octets of `(len % 128) + 128`, so a 263-byte `Location`, `Set-Cookie` or CSP header encodes as `7f 88 01`, and a raw value byte ≥ `0x80` gets there too — `lib/src/protocol/mux/converter.rs:388-391` rejects only `0x00..=0x08 | 0x0A..=0x1F | 0x7F`. Since `headers_ok_response` runs on proxied responses with arbitrary backend headers, the old scan was falsifiable on the wire. Both mutations named in the `To SEE THIS RED:` block have been run and seen red. The ULID's leading ten characters are its generation timestamp in milliseconds, so a hit landing there repeats for every response in a window of 1 ms to ~17.5 minutes for the fast triples, and ~9.3 h to ~1.1 y for the slow head — those are not rarer per draw, their characters are simply fixed for a whole era. That is why two consecutive CI iterations reddened while sixteen serial local runs found nothing. This test is not a flake and does not belong on a flake list. Nineteen indexed-status byte probes of the same class survive and are inventoried in `e2e/COVERAGE.md`: 2 × `contains(&0x88)` and 17 × `contains(&0x8D)`, in `h2_security_header_injection.rs` (3) and `h2_security_tests.rs` (16). They are no longer rated low risk. Two things have to be settled before converting them: `0x8D` is static index 13 = `:status 404`, while all 17 sites and their comments call it 400 (index 12 = `0x8C`), so a mechanical rewrite would change behaviour; and several sit on the permissive side of an `||`. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/h2-sni-strict-off-421
branch
from
September 20, 2026 12:03
92c759e to
bbd46fb
Compare
This was referenced Sep 20, 2026
Closed
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.
Closes #1353. It is not a flake, and it is not a production defect — the assertion never read the
status at all.
Cause
CAUSE: lib/src/protocol/kawa_h1/editor.rs:1126 stamps every response with Sozu-Id = the session's 26-character Crockford base-32 ULID, and Kawa writes literal HPACK values with the Huffman bit clear -> the ULID lands as plain ASCII inside the response HEADERS field block -> headers_status_matches asked payload.windows(3).any(|w| w == b"421") of that block -> SYMPTOM: got_421=true on a plain proxied 200.The 200 OK response HEADERS payload, captured verbatim:
0x88is indexed static 8 =:status 200. The old scan searched that whole block forb"421". TheCrockford alphabet is
0-9A-ZminusILOU, so a three-digit needle hits an ordinary 200 roughlyonce in 1400 responses.
Why it failed twice consecutively, then passed on a re-run
A ULID's leading ten characters are its generation timestamp in milliseconds. A
421hit landing inthat prefix is not independent between runs — it holds for 32 ms, ~1 s, ~33 s or ~17.5 min
depending on which character triple carries it, and every response generated inside that window
carries it. That is exactly the observed signature: both CI iterations red, re-run of the same commit
green, and 16 serial local runs finding nothing (expected count ≈ 0.03).
The proxy is innocent by construction
Every 421 on the H2 path is one
set_default_answer(stream, front_readiness, 421, &answers)in themux — the only
421call there. It is reachable solely fromRetrieveClusterError::SniAuthorityMismatch, constructed at exactly one site inlib/src/protocol/mux/router.rs, seven lines afterincr!(names::http::SNI_AUTHORITY_MISMATCH),both inside the
.filter(|_| context.strict_sni_binding)gate.DefaultAnswer::Answer421has noother constructor in
lib/.The failing run reported
metric_stable=true: that counter did not move, therefore that block didnot execute, therefore no 421 was emitted.
bar_reqs=1confirms the request was proxied normally.collect_response_framesis not implicated — it reads only this connection's socket, the testopens one stream, sozu does no server push, and the frames returned were all stream 1.
The change (test crate only, zero
lib/diff)A new
decode_status(payload) -> Option<u16>reads the:statusfield that RFC 9113 §8.3.2 putsfirst in a response block, in the two shapes Kawa emits: an indexed static entry over indices 8..=14,
or a literal over one of those name indices with three unhuffmanned ASCII digits. It rejects the
001xxxxxdynamic-table-size-update prefix and Huffman-coded values. It fails closed: a real 421it could not decode would make the mismatch tests go red loudly, not silently green.
Red-then-green, and the assertion still catches a real 421
The regression test asserts both directions on captured blocks: a real 200 whose ULID contains
421must read 2xx and not 421; a real
0e 03 "421"block must read 421 and not 2xx.Tightening an assertion to make a failure disappear is only acceptable if the tightened assertion
still fires on the behaviour it exists to catch, so the proxy was deliberately broken — the
strict_sni_bindingopt-out ignored and the SAN set ignored, i.e. the pre-coalescingconsole-421-storm behaviour:
got_421=trueon a genuine 421. The mutation was reverted; the final tree has zerolib/diff.Independently,
e2e_h2_sni_authority_mismatch_blockedande2e_h2_sni_wildcard_authority_not_expandedboth assertgot_421 == trueagainst the unmutatedproxy and both stay green with the new decoder.
Validation
BUILD=0 CLIPPY=0 TEST=0 FMT=0,test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 429 filtered out— the scopedtests::h2_security_sni::module, i.e. every consumer of both changed helpers.The original CI red was not reproduced on the wire; that needs a ULID that happens to contain
421,a ~1-in-1400 draw. The mechanism is proved instead by the byte capture, the single-emission-site
enumeration against
metric_stable=true, and a deterministic unit test that reddens the oldassertion with a real captured 200 block.
Documented, not listed as a flake
doc/testing.mdgains two e2e conventions: decode a status, never scan for its digits; and a testthat only reddens under CI load is not automatically a flake — find the production site first.
e2e/COVERAGE.mdstates explicitly that #1353 must not go on a flake list.tests::tests::test_issue_810_timeout, observed failing under parallel load in the same session, isa different mechanism — a 100 ms wall-clock budget on
worker.wait_for_server_stop()— and is agenuine flake candidate. Untouched here.