Skip to content

fix(parser): make Method::new case-sensitive per RFC 9110 §9.1 - #1474

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/method-case-sensitivity
Sep 23, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/method-case-sensitivity

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Method::new used compare_no_case, so a request line reading get /path HTTP/1.1 produced Method::Get. RFC 9110 §9.1 makes the method token case-sensitive, and the origin receives the original get bytes — so sozu and the backend could disagree about what method a request carries.

Long harmless, until is_idempotent began gating whether a request may be replayed on a fresh backend. A lowercase extension verb that sozu mapped to an idempotent variant became replayable while the origin was free to give it side effects of its own.

The gate that decided this could ship

The obvious risk of making the parser strict is metric cardinality: if Method::Custom(String) reaches a metrics label, a peer mints unbounded label values by varying case, and a correctness fix becomes a memory-growth vector. The lenient behaviour might have been what collapsed them.

It is not, and the reason is structural rather than incidental. Every incr! / count! / gauge! / time! / record_* in lib/, bin/ and command/ funnels through Subscriber::receive_metric (lib/src/metrics/mod.rs:322), count_add (:847), set_gauge (:851) and gauge_add (:855) — every one typed key: &'static str. Method::Custom(String) is heap-allocated and cannot coerce; there is no leak(), no transmute, no OnceLock<String> anywhere in lib/src, bin/src or command/src. http_status_code_metric_name (metrics/mod.rs:87-107) is a closed 18-code u16 match with _ => None. The only runtime label strings are cluster_id and backend_id, both operator-declared. OpenTelemetry is a separate path and carries only fixed-width trace and span ids (command/src/logging/access_logs.rs:134) — no span name, no attribute map, no method field.

A peer cannot mint a metric series by varying case, before or after this change.

Four observable consequences

  1. Routing, and it cuts both ways. MethodRule::new (lib/src/router/mod.rs:1450) classifies the frontend's declared method through the same Method::new, and matches is a plain ==. A frontend declaring method = "GET" no longer matches a client sending get (builtin 404); symmetrically, method = "get" stops answering canonical GET. Silent-never-match was already the documented failure mode for unrecognised methods — this extends it to known verbs, which is why the case note now lives at command/src/command.proto:874 and in bin/src/cli.rs's help, next to where an operator writes the value.
  2. Metric cardinality — unchanged, per the chain above.
  3. Access log — get is logged as get rather than GET (lib/src/protocol/mux/stream.rs:721), i.e. what the client actually sent. Already verbatim for every custom method.
  4. Response framing, and this one is a net improvement. Method::Head terminates the response parse at lib/src/protocol/kawa_h1/editor.rs:1117 and lib/src/protocol/mux/h2.rs:4674. A client sending head no longer hits that arm. Before, head → Method::Head → terminate-after-headers, so an RFC-conforming origin answering 405 with a body left unread bytes on a pooled keep-alive upstream — a desync, against the common case. After, framing follows Content-Length; against a case-folding origin answering HEAD-style, sozu waits for a body that never arrives and serves 504 at configured_backend_timeout (lib/src/protocol/mux/mod.rs:1521, :2185-2186) — a bounded stall holding one session and one backend connection, against the rare case. A desync against conforming origins is traded for a bounded 504 against non-conforming ones.

A fifth, non-observable to operators: debug logs render context.method through {method:?} at lib/src/protocol/mux/mod.rs:129, :1192 and lib/src/protocol/mux/router.rs:65, and Method's Debug redacts custom methods to Custom(bytes=N) (kawa_h1/parser.rs:61). So method=Some(Get) becomes method=Some(Custom(bytes=3)) — for exactly the population an operator will be debugging after this change. Recorded in the CHANGELOG rather than changed, since the redaction is deliberate.

Tests

Three added; two are falsifiable by reverting the Method::new body, and the third is honestly labelled:

test reverted role
lowercase_verb_is_custom_and_not_idempotent FAILS — parser.rs:390, left: Get, right: Custom(bytes=3) regression
method_rule_is_case_sensitive FAILS — router/mod.rs:2476, left: Some(Get), right: Some(Custom(bytes=3)) regression
canonical_verbs_keep_their_variant passes inverse guard against over-narrowing, not a regression test

Not test-shaped: the tests' lowercase literals appear zero times in the production hunk, and all eight uppercase literals the fix uses already existed on main as compare_no_case arguments. Method has exactly eight non-Custom variants and the tests cover all eight, so there is no ninth-verb gap.

What was deliberately not done

No case-insensitive fallback and no alias table preserving today's behaviour for known verbs — the issue rules that out by name, and it would reintroduce the divergence in a form harder to see. No load-time warning or validation on a declared method either; that is scope #1451 did not ask for, and it is worth noting that method is now the only case-sensitive string in a config file whose siblings fold (parse_redirect_policy and parse_redirect_scheme both document "(case-insensitive)").

Sweep

No fixture, e2e test, fuzz seed, doc example, TOML or JSON asset anywhere in e2e/, lib/, bin/, command/, fuzz/, doc/ or examples/ declares a non-canonical method literal. H1 e2e request lines are uppercase; H2 e2e uses static-table 0x82/0x83; the HPACK corpus holds indexed references, not literals. The H2 path converges on the same classifier with no H2-local normalization: pkawa.rs:827 folds the pseudo-header name, :831 validates the value against is_tchar only, :835 stores it verbatim.

One pre-existing disagreement closes for free: pkawa.rs:1011-1013 gated the :path * asterisk form on a raw m == b"OPTIONS" compare, already case-sensitive, so :method options + :path * was rejected while Method::new called it Method::Options. They now agree.

Also corrected here, both found by review: doc/configure_admin_ops.md cited configure.md:2998 for https.alpn.rejected.unsupported, ~26 lines off and in a line this branch shifted; and the two SAFETY: comments at lib/src/http.rs:849 and lib/src/https.rs:1242 cited parser.rs:133 for hostname_and_port, which is at :182. The policy question those raise — that file:line citations in Rust comments are outside the CI gate's scope entirely — is filed as #1473.

Closes #1451

`Method::new` compared with `compare_no_case`, so a request line reading
`get /path HTTP/1.1` produced `Method::Get`. RFC 9110 §9.1 makes the method
token case-sensitive and the origin receives the original `get` bytes, so
sozu and the backend could disagree about what method a request carries.

Long harmless, made load-bearing by the stale-upstream replay (#1442):
`is_idempotent` gates whether a request already written to a pooled upstream
may be replayed on a fresh one, and `Method::Custom` is deliberately not
idempotent. A lowercase `get` was therefore judged replayable while the
origin was free to treat the token as an extension method with side effects
of its own. The narrow scoping is not available: `context.method` is already
normalised by the time the replay decision runs, and the raw token is gone.

The match is now exact against the eight canonical spellings; anything else
is `Method::Custom`, carrying the token verbatim. No case-insensitive
fallback and no alias table: either would reintroduce the same divergence in
a form that is harder to see.

Metric cardinality was measured before changing, not after. No metric key or
label is derived from the method: the `http.status.*` keys come only from
`context.status: u16` through a closed eighteen-code list plus buckets, and
the only labels the emission sites pass are `cluster_id` and `backend_id`,
both operator-declared. A peer cannot mint label values by varying case,
before or after this change.

Routing cuts both ways, because `MethodRule::new` classifies a frontend's
declared `method` through the same `Method::new`. A frontend declared without
a `method` is unaffected. A frontend declared `method = "GET"` no longer
matches a client sending `get`; symmetrically one declared `method = "get"`
stops answering canonical `GET` requests, so a method declared in
non-canonical case must be corrected to the case the client sends.

Response framing changes in the direction worth having. `Method::Head` is
what terminates the response parse after the headers, and `head` no longer
reaches that arm. Before, an RFC-conforming origin answering `405` with a
body left that body unread on a pooled keep-alive upstream, desyncing the
next request on it — the common pairing. After, the cost lands only on the
rare non-conforming pairing, a case-folding origin answering `head` bodiless
with a `Content-Length`, where sozu serves 504 at `configured_backend_timeout`:
a bounded stall, not a hang.

Two smaller consequences: the access log echoes the token verbatim, as it
already did for every custom method, and `Method`'s `Debug` now renders a
lowercase verb as `Custom(bytes=N)` at the three sites that print
`context.method` with `{method:?}`.

`doc/configure.md` documented the old lenient behaviour explicitly, in both
the routing-rule and replay-eligibility sections, and is updated alongside
`mux/LIFECYCLE.md`, the `RequestHttpFrontend.method` proto field and the
`--method` CLI help.

Closes #1451.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit eac0409 into main Sep 23, 2026
45 of 47 checks passed
FlorentinDUBOIS added a commit that referenced this pull request Sep 23, 2026
`check_doc_citations.py` resolves `doc/**` and `**/LIFECYCLE.md`, so a
`path.rs:NNN` inside a `//`, `///` or `//!` comment was read by no rule at
all — not the existence floor, not the drift comparison, not once. The two
`SAFETY:` comments justifying `from_utf8_unchecked` in `lib/src/http.rs`
and `lib/src/https.rs` are how it surfaced (#1473): both cited a `Method`
match arm for `hostname_and_port`, and drifted there with CI green
throughout, until #1474 re-pointed them at the function.

The population was measured before the form was chosen, at main `19fd5d8c`:
90 citation tokens across 29 files, holding 113 line targets. Sixty-eight
of the 90 had drifted from the text they named at the commit that last
wrote or re-anchored them, and only 16 still land on a line that is neither
a bare delimiter, a blank, nor past end-of-file. The half-life decided it:
43 of those 68 broke on the very NEXT commit that touched the file they
point into, the median citation survived ONE such commit and zero days, and
65 of 68 were wrong inside a week. All 18 `h2.rs:NNN` tokens had drifted.

Extending the resolver over `**/*.rs` was the alternative, and it was
measured rather than argued: switched on at that revision it would have had
to reject those 68, plus 14 naming a basename that is ambiguous here — four
files are called `h2.rs`, nineteen `mod.rs` — plus two pointing into the
`kawa` dependency, which is not in this repository. A gate that fails on
most of the population it guards gets bypassed rather than satisfied, which
is the argument the script's own header makes about `--all-features`.

So `doc/README.md`'s three forms now govern Rust comments too, with one
narrowing: the symbol form only, and a comment that means one branch names
that branch in words. All 82 citations outside `lib/src/protocol/mux/` are
converted, across 25 files, each re-pointed at the symbol recovered by
reading the cited file AT THE COMMIT THAT WROTE THE CITATION rather than at
HEAD. The rule is also in `CLAUDE.md`'s code-style list.

Rewrapping the comments shifted lines in `e2e/src/tests/h2_correctness_tests.rs`,
and the drift rule caught two `doc/testing.md` citations pointing into it —
the guarded half of exactly the pair #1465 was about. They now name
`try_h2_large_gzipped_chunked_drains_fully` and
`try_h2_large_chunked_7mb_drains_fully`.

Two corrections fell out of recovering intent rather than trusting HEAD:
`h2_log_context_tests.rs` named `log_context_lite!` for a line that is
inside `log_module_context!` — only the latter renders the bare `MUX-H2`
tag the comment claims — and `e2e/src/tests/mod.rs` named two tests by a
line holding their `#[serial_test::serial]` attribute.

Comments and documentation only; no code, literal, attribute, assertion or
test name changed. The eight sites under `lib/src/protocol/mux/` are left
for a separate pass to keep this off a module under concurrent change; two
of them, into pinned `kawa` 0.7.1, are the one class here where a line
number genuinely cannot rot.

Refs #1473

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Sep 23, 2026
`check_doc_citations.py` resolves `doc/**` and `**/LIFECYCLE.md`, so a
`path.rs:NNN` inside a `//`, `///` or `//!` comment was read by no rule at
all — not the existence floor, not the drift comparison, not once. The two
`SAFETY:` comments justifying `from_utf8_unchecked` in `lib/src/http.rs`
and `lib/src/https.rs` are how it surfaced (#1473): both cited a `Method`
match arm for `hostname_and_port`, and drifted there with CI green
throughout, until #1474 re-pointed them at the function.

The population was measured before the form was chosen, at main `19fd5d8c`:
90 citation tokens across 29 files, holding 113 line targets. Sixty-eight
of the 90 had drifted from the text they named at the commit that last
wrote or re-anchored them, and only 16 still land on a line that is neither
a bare delimiter, a blank, nor past end-of-file. The half-life decided it:
43 of those 68 broke on the very NEXT commit that touched the file they
point into, the median citation survived ONE such commit and zero days, and
65 of 68 were wrong inside a week. All 18 `h2.rs:NNN` tokens had drifted.

Extending the resolver over `**/*.rs` was the alternative, and it was
measured rather than argued: switched on at that revision it would have had
to reject those 68, plus 14 naming a basename that is ambiguous here — four
files are called `h2.rs`, nineteen `mod.rs` — plus two pointing into the
`kawa` dependency, which is not in this repository. A gate that fails on
most of the population it guards gets bypassed rather than satisfied, which
is the argument the script's own header makes about `--all-features`.

So `doc/README.md`'s three forms now govern Rust comments too, with one
narrowing: the symbol form only, and a comment that means one branch names
that branch in words. All 82 citations outside `lib/src/protocol/mux/` are
converted, across 25 files, each re-pointed at the symbol recovered by
reading the cited file AT THE COMMIT THAT WROTE THE CITATION rather than at
HEAD. The rule is also in `CLAUDE.md`'s code-style list.

Rewrapping the comments shifted lines in `e2e/src/tests/h2_correctness_tests.rs`,
and the drift rule caught two `doc/testing.md` citations pointing into it —
the guarded half of exactly the pair #1465 was about. They now name
`try_h2_large_gzipped_chunked_drains_fully` and
`try_h2_large_chunked_7mb_drains_fully`.

Two corrections fell out of recovering intent rather than trusting HEAD:
`h2_log_context_tests.rs` named `log_context_lite!` for a line that is
inside `log_module_context!` — only the latter renders the bare `MUX-H2`
tag the comment claims — and `e2e/src/tests/mod.rs` named two tests by a
line holding their `#[serial_test::serial]` attribute.

Comments and documentation only; no code, literal, attribute, assertion or
test name changed. The eight sites under `lib/src/protocol/mux/` are left
for a separate pass to keep this off a module under concurrent change; two
of them, into pinned `kawa` 0.7.1, are the one class here where a line
number genuinely cannot rot.

Refs #1473

Signed-off-by: Florentin Dubois <[email protected]>
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.

Method::new is case-insensitive, so a lowercase verb is classified idempotent while the origin sees something else

1 participant