Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion pkgs/fleet/crates/fleet-queue/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <id>` narrows to
Expand All @@ -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"),
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions pkgs/fleet/crates/fleet-queue/src/queue_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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!(""),
Expand Down