atlas-search + fleet-search: parse_cursor panics on malformed cursors instead of returning 400
Evidence
parse_cursor decodes the client-supplied results-paging cursor by slicing
the string at byte offsets with no length or ASCII-hex gate:
pkgs/atlas-search/crates/atlas-search/src/server.rs:1723-1735
pkgs/fleet/crates/fleet-search/src/server.rs:1723-1735 (byte-identical twin)
let bytes: Result<Vec<u8>, _> = (0..cursor.len())
.step_by(2)
.map(|i| u8::from_str_radix(&cursor[i..i + 2], 16))
.collect();
The cursor arrives from the HTTP request (caller at server.rs:1632,
Some(c) => parse_cursor(c)?) in the results-paging handler. The connection
is served on a per-connection thread (server.rs:1980) with no
catch_unwind around routing, so a panic kills the thread and drops the
connection instead of producing the function's own documented
400 "malformed cursor" error.
Verified this run on the laptop at main 151c8e7e1c with a probe crate
(~/git/fleet/probe-cursor-hex, function copied verbatim, minimal
ServerError stub):
- control: valid
format_cursor(42) roundtrip → Ok(42)
- control: even-length non-hex
"zzzz" → Err(malformed cursor)
- control: empty string →
Err(malformed cursor)
- odd-length hex (valid cursor minus its last character) → PANIC
(slice index out of range at the final pair)
- single character
"a" → PANIC
- hex pair prefix + multibyte input (
"6162a\u{e9}") → PANIC
(slice at a non-char-boundary byte offset)
This is the same ungated-hex-parser class as #7750 (fixed in #7757 for
local_claims::hex_bytes): the sibling parsers there carry an
is_ascii_hexdigit gate per #2517; parse_cursor in both copies has none.
u8::from_str_radix also accepts a leading +, so even where a malformed
pair does not panic it is not validated as hex before decoding.
Why it matters
Any client (or any corrupted/proxied request) that sends an odd-length or
non-ASCII cursor query value crashes its connection thread with a panic
instead of receiving the designed 400. Panics on untrusted input are a
robustness/DoS surface and produce panic noise in server logs; the cursor
is explicitly documented as opaque client-held state, so malformed values
are expected input, not an internal invariant.
Acceptance criteria
- Both copies (
atlas-search and fleet-search server.rs) refuse a
cursor whose length is odd or that contains any non-ASCII-hexdigit
byte, returning Err(bad_request("malformed cursor")) — no panic on
any input, including multibyte UTF-8.
- Valid cursors produced by
format_cursor still roundtrip to the
same offset in both copies.
- Regression tests cover at least: odd-length hex, single character,
multibyte/non-boundary input, even-length non-hex, and the valid
roundtrip — in both crates (or in the crate(s) where the handler
lives, with the twin kept byte-identical in behavior).
- No other behavior of the results-paging handler changes (offset
beyond end still returns its existing 400).