Skip to content

test(e2e): decode the :status field instead of scanning for its digits - #1365

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/h2-sni-strict-off-421
Sep 20, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/h2-sni-strict-off-421

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

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:

88 0f 0d 01 '8' 40 07 "sozu-id" 1a "01M2Z5AGKTYKJM9MFQY89EJMJ9"

0x88 is indexed static 8 = :status 200. The old scan searched that whole block for b"421". The
Crockford alphabet is 0-9A-Z minus ILOU, so a three-digit needle hits an ordinary 200 roughly
once 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 421 hit landing in
that 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 the
mux — the only 421 call there. It is reachable solely from
RetrieveClusterError::SniAuthorityMismatch, constructed at exactly one site in
lib/src/protocol/mux/router.rs, seven lines after incr!(names::http::SNI_AUTHORITY_MISMATCH),
both inside the .filter(|_| context.strict_sni_binding) gate. DefaultAnswer::Answer421 has no
other constructor in lib/.

The failing run reported metric_stable=true: that counter did not move, therefore that block did
not execute, therefore no 421 was emitted. bar_reqs=1 confirms the request was proxied normally.

collect_response_frames is not implicated — it reads only this connection's socket, the test
opens 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 :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 with three unhuffmanned ASCII digits. It rejects the
001xxxxx dynamic-table-size-update prefix and Huffman-coded values. It fails closed: a real 421
it 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

[RED, unfixed helpers]
panicked at e2e/src/tests/h2_security_sni.rs:894:5:
a `Sozu-Id` carrying the digits 421 is not a 421 response
test result: FAILED. 0 passed; 1 failed

The regression test asserts both directions on captured blocks: a real 200 whose ULID contains 421
must 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_binding opt-out ignored and the SAN set ignored, i.e. the pre-coalescing
console-421-storm behaviour:

strict-off FAIL: infra_ok=true got_ok=false got_421=true metric_stable=false foo_reqs=0 bar_reqs=0

got_421=true on a genuine 421. The mutation was reverted; the final tree has zero lib/ diff.
Independently, e2e_h2_sni_authority_mismatch_blocked and
e2e_h2_sni_wildcard_authority_not_expanded both assert got_421 == true against the unmutated
proxy 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 scoped
tests::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 old
assertion with a real captured 200 block.

Documented, not listed as a flake

doc/testing.md gains two e2e conventions: decode a status, never scan for its digits; and a test
that only reddens under CI load is not automatically a flake — find the production site first.
e2e/COVERAGE.md states 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, is
a different mechanism — a 100 ms wall-clock budget on worker.wait_for_server_stop() — and is a
genuine flake candidate. Untouched here.

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
FlorentinDUBOIS force-pushed the fix/h2-sni-strict-off-421 branch from 92c759e to bbd46fb Compare September 20, 2026 12:03
@FlorentinDUBOIS
FlorentinDUBOIS merged commit c7ac070 into main Sep 20, 2026
59 of 61 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/h2-sni-strict-off-421 branch September 20, 2026 16:39
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.

e2e: h2 SNI strict-off test sees a 421 under CI load (got_421 with everything else correct)

1 participant