Skip to content

github-backup(worker): /queue/ack body is shape-trusted — null/non-JSON/string-ids crash the handler, a top-level array fakes acked:0, non-string ids delete wrong keys; and one corrupt KV value crashes every GET /queue #6882

Closed

Description

@dezren39

Problem

The github-backup queue Worker's two authenticated drainer endpoints parse JSON with no shape guard, so a malformed request or a single corrupt queue entry crashes the handler (an unhandled throw in a Worker = a bare 500) or, worse, reports a successful ack that deleted nothing / the wrong keys.

File: infra/github-backup/worker/src/index.js (verified on main 8a5cd8ea75)

1. POST /queue/ack — the request body is shape-trusted (:87-88)

const { ids } = await req.json();
const keys = (ids || []).map((id) => "ev:" + id);

Verified with the real file verbatim (probe ~/git/fleet/probe-ghb-worker-ack, node v24, stubbed KV; control {ids:["a","b"]} → 200 {acked:2}, deletes ev:a,ev:b):

Body Result today
null throws TypeError: Cannot destructure property 'ids' ... as it is null
non-JSON (not json) / empty body throws SyntaxError from req.json()
{"ids":"abc"} / {"ids":123} throws TypeError: (ids || []).map is not a function
top-level array ["a","b"] 200 {"acked":0} — a fake success: the caller's ids are silently dropped, nothing is deleted
{"ids":[123,null]} 200 {"acked":2} — deletes the wrong keys ev:123 / ev:null and reports success for ids that never existed
{} (missing ids) 200 {"acked":0} — indistinguishable from a legitimate empty ack

The ack is the drainer's delete path (infra/github-backup/bin/drain_queue.py ack_events, :86-97): events are acked only once the mirror reflects them (#3219 discipline), so an ack response that lies about what it deleted undermines the one signal the drainer has that the queue actually shrank.

2. GET /queue — one corrupt KV value crashes every poll (:76)

if (v) events.push(JSON.parse(v));

Verified: with one stored value not-json{, GET /queue throws SyntaxError and returns nothing — every event on the page is lost to the drainer, and because listing is what feeds the ack path, the corrupt entry can never be acked away through the API. The values are normally written by this Worker's own webhook handler (:46-52, whose JSON.parse is guarded — the in-file twin), but KV is shared, mutable state: a manual edit, a future writer, or a partial write leaves a permanent poison pill in the queue. This is the Worker-side mirror of the drainer-side poison pill in #6575.

The existing test suite (infra/github-backup/worker/test/index.test.mjs) covers only well-shaped ack bodies ({ids:["a","b","c"]}) and well-formed KV values — none of the cases above.

Why it matters

  • A malformed ack (a buggy/manual caller, a truncated request) produces an opaque 500 instead of a 400 the caller can act on.
  • The top-level-array and non-string-id cases are worse than a crash: they return 200 with a count that does not describe what was deleted, so a drain can believe events were retired when they were not (or that foreign keys were).
  • One corrupt KV entry wedges the whole queue for the drainer: no listing, no acking, no self-healing path through the API.

Acceptance criteria

  • POST /queue/ack with a non-JSON, empty, JSON-null, or non-object body returns a 4xx with a clear error message; no exception escapes the handler and no KV delete is attempted.
  • POST /queue/ack with ids missing, not an array, or containing a non-string/empty entry returns a 4xx naming the ids field; a well-formed {ids:[...]} behaves exactly as today (bulk-chunked deletes, {acked: n}).
  • An ack response's acked count always equals the number of keys actually deleted.
  • GET /queue with one corrupt (non-JSON) KV value does not lose the whole page: either the well-formed events are returned with the corrupt key named/signalled in the response, or the endpoint fails with an error naming the corrupt key — never a bare SyntaxError 500. (Either disposition is acceptable; silently dropping the entry without any signal is not.)
  • New cases in infra/github-backup/worker/test/index.test.mjs cover: null body, non-JSON body, string ids, top-level array body, non-string id entries, and a corrupt KV value on GET /queue; the existing 5 tests still pass.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    on Nov 7, 2026
  2. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  3. added
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    effort/sSmall: expected under 2 hours of work
    app/github-backupinfra/github-backup estate mirror system
    on Nov 7, 2026
  4. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: filed

    • Agent: new-issue-creator job (new-issue-creator-code-a)
    • Session / ID: new-issue-creator-code-a run 2026-11-07 07:05 CST
    • Found via: filed this run
    • Task: File a verified defect: the github-backup queue Worker's /queue/ack body and GET /queue KV values are shape-trusted (worker/src/index.js:87, :76)
    • Expectation: effort/s — done when ack rejects malformed bodies with a 4xx, acked counts match actual deletes, and a corrupt KV value no longer crashes the whole queue page (see acceptance criteria)
    • Links: probe ~/git/fleet/probe-ghb-worker-ack (laptop, real file verbatim, md5 931e7df4)
  5. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: picked-up

  6. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 8, 2026
  7. 1 remaining item

  8. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: handed-off

  9. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 8, 2026
  10. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: parked

  11. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · blocked — already done

  12. added
    queue/blockedQueue or user escalation state
    status/blockedQueue or user escalation state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/github-backupinfra/github-backup estate mirror systemeffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)queue/blockedQueue or user escalation statesource/creatorFiled by the new-issue-creator jobstatus/blockedQueue or user escalation statestatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted testswork/assignedQueue worker lifecycle state

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions