diff --git a/pkgs/fleet/crates/fleet-queue/src/client.rs b/pkgs/fleet/crates/fleet-queue/src/client.rs index 9691f58088..302a87dc66 100644 --- a/pkgs/fleet/crates/fleet-queue/src/client.rs +++ b/pkgs/fleet/crates/fleet-queue/src/client.rs @@ -2183,6 +2183,18 @@ fn cmd_list(rest: &[String]) -> i32 { Ok(limit) => limit, Err(e) => die(2, &e), }; + // #9027: --not-before is validated with the same rule park and + // revive apply (#6426). Forwarded raw, a garbage value silently + // narrowed the listing on the Turso backend, whose TEXT + // comparison made the predicate false for every row carrying a + // not_before (or disabled the filter) with exit 0. + let not_before = match args.get("not-before") { + Some(nb) => match validate_not_before_flag(&nb) { + Ok(v) => Some(v), + Err(e) => die(2, &e), + }, + None => None, + }; // #7871: fetch in pages of LIST_PAGE_SIZE (see list_pages) — a // single oversized /list response comes back unusable and used // to render as a silent "(no tasks)". `--task ` narrows to @@ -2199,7 +2211,7 @@ fn cmd_list(rest: &[String]) -> i32 { "status": args.get("status"), "limit": page_limit, "offset": offset, - "not_before": args.get("not-before"), + "not_before": not_before, "lane": args.get("lane"), "worker": args.get("worker"), "task": args.get_i64("task"), @@ -7487,6 +7499,40 @@ mod tests { } } + #[test] + fn list_not_before_is_validated_before_the_call_9027() { + // #9027: cmd_list forwarded --not-before raw; on the Turso + // backend the TEXT comparison then silently narrowed the + // listing (a value sorting before every timestamp hid every + // row carrying a not_before; one sorting after disabled the + // filter) with exit 0. cmd_list now validates the flag with + // the park/revive rule and the /list body carries the + // validated value. + let src = include_str!("client.rs"); + let seg = src + .split("fn cmd_list(") + .nth(1) + .and_then(|s| s.split("fn cmd_").next()) + .unwrap_or(""); + assert!( + seg.contains("validate_not_before_flag(&nb)"), + "cmd_list validates --not-before before the /list call" + ); + assert!( + seg.contains("\"not_before\": not_before"), + "the /list body carries the validated value, not the raw flag" + ); + assert!( + !seg.contains("\"not_before\": args.get(\"not-before\")"), + "the raw flag must not reach the /list body" + ); + // The exact garbage shapes from the finding die at the + // validator the client now applies: + for bad in ["0", "!", "banana"] { + assert!(validate_not_before_flag(bad).is_err(), "{bad} must be rejected"); + } + } + #[test] fn well_formed_invocation_is_unchanged() { // Control (#5939 acceptance): list --queue alpha records diff --git a/pkgs/fleet/crates/fleet-queue/src/queue_broker.rs b/pkgs/fleet/crates/fleet-queue/src/queue_broker.rs index 8ea708385b..0c1dd6303d 100644 --- a/pkgs/fleet/crates/fleet-queue/src/queue_broker.rs +++ b/pkgs/fleet/crates/fleet-queue/src/queue_broker.rs @@ -611,13 +611,15 @@ fn validate_durations(path: &str, req: &Value) -> Result<(), String> { /// The not_before gate (#6426): /park and /revive carry a raw /// not_before that dispatch forwards to the RPC (or the turso -/// backend) — validate it BEFORE either, with the same rule the +/// backend), and /list carries one as a filter (#9027 — unvalidated, +/// a garbage value silently narrowed the Turso listing) — validate +/// it BEFORE either, with the same rule the /// packet validator applies on /enqueue (validate_packet runs /// inside both /enqueue handlers ahead of their RPC call). An /// absent or null not_before is untouched; a present one must be a /// non-empty RFC 3339 timestamp no more than 366 days out. fn validate_request_not_before(path: &str, req: &Value) -> Result<(), String> { - if !matches!(path, "/park" | "/revive") { + if !matches!(path, "/park" | "/revive" | "/list") { return Ok(()); } match req.get("not_before").filter(|v| !v.is_null()) { @@ -1699,7 +1701,7 @@ mod tests { // RPC unchecked. The dispatch gate rejects garbage and // far-future values; absent/null and valid values pass, and // other verbs are untouched by the gate. - for path in ["/park", "/revive"] { + for path in ["/park", "/revive", "/list"] { for bad in [ json!("banana"), json!(""),