Skip to content

github-ci(worker): a JSON null body crashes fetch — payload.repository dereferences null outside the try/catch, escaping the receiver-failed envelope #6946

Closed

Description

@dezren39

Problem

The github-ci Worker (pkgs/github-ci/worker/src/index.ts, #5693) parses the webhook body and then dereferences it outside its error envelope:

let payload: Record<string, unknown>;
try {
  payload = JSON.parse(raw);
} catch {
  return new Response("bad json", { status: 400 });
}
...
const repo = (payload.repository ?? {}) as Record<string, unknown>;

JSON.parse("null") succeeds and yields null, so a signed body of literally null passes the parse guard and then throws TypeError: null is not an object (evaluating 'payload.repository') at the payload.repository read — which sits before the try { ... } catch block that produces the worker's receiver failed: … 500 envelope. The exception escapes fetch entirely: Cloudflare returns its generic unhandled-exception 500, nothing is logged with the worker's event/repo context, and GitHub records a failed delivery it will retry — a poison delivery that can never succeed, for every event type (the deref happens before routing).

Other non-object JSON bodies survive only by accident of JS semantics: [], "str", and 123 box to objects with an undefined repository, land on repoName = "unknown", and exit through the normal skip/ignore paths. null is the one valid-JSON body that crashes — and it is exactly the case the shipped test suite does not cover (worker.test.ts posts objects only).

Evidence (verified this run, laptop @ 63f83be, probe ~/git/fleet/probe-ghci-snapshot)

Real pkgs/github-ci/worker/src/*.ts copied verbatim (md5-checked: index.ts 9b29537d…, sink.ts 487d63ee…) into the probe; worker.fetch driven directly with correctly HMAC-signed bodies (the probe signs with the same WebCrypto HMAC the worker verifies):

  • Control — body {} (event workflow_run, valid signature) → HTTP 200, {"ok":true,"skipped":"not_completed","repo":"unknown",…}.
  • Bug — body null (event workflow_run, valid signature) → worker.fetch THREW TypeError: null is not an object (evaluating 'payload.repository') — no Response at all.
  • Bug — body null (event push, valid signature) → same throw (crash precedes routing).
  • Control — body [] (event workflow_run) → HTTP 200 skip path.

Why it matters

A webhook receiver's one job is to turn any delivered bytes into a deliberate HTTP answer. A body shape that escapes the handler as an unhandled exception defeats the worker's own failure envelope and logging, produces a retryable 500 for a delivery that can never succeed, and — because the throw happens before the event routing — takes down every event type at once, not just one route. It is also the shape most likely to be hit by a misconfigured sender or a probe, precisely when a clean 400 matters most.

Acceptance criteria

  • A signed null JSON body (and any other non-object JSON body: array, string, number, boolean) gets a deliberate response — 400 is the natural choice — for every event type, with no exception escaping fetch.
  • Object bodies keep today's behavior byte-for-byte (ping → pong, workflow_run skip/store paths, push/PR/issues routing, 202 for unknown events).
  • Malformed JSON keeps returning the existing 400 bad json.
  • New worker tests pin the null-body case for at least workflow_run and one fleet-routed event (push), plus one non-object scalar/array body.

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
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    on Nov 7, 2026
  2. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  3. added
    effort/xsTrivial: expected under 30 minutes of work
    app/github-ciPackage/app: github-ci (pkgs/ or apps/ in this repo)
    on Nov 7, 2026
  4. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  5. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

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

  8. added
    priority/lowNice to have; do when convenient
    and removed
    priority/normalOrdinary priority (the default)
    on Nov 11, 2026
  9. added
    queue/claimedQueue worker lifecycle 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 11, 2026
  10. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (fixed_merged)

    Implemented direct (lane assignment returned direct; earlier opencode handoffs produced no PR). PR #8696: after JSON.parse, the github-ci worker now rejects any non-object payload (null/array/string/number/boolean) with a deliberate 400 bad payload for every event type, before any dereference; object-body routing and the bad-json 400 are unchanged. Four new signed-body tests (null × workflow_run/push, array, scalar). Verification on the laptop against the PR head: vitest 33 passed (4 files), tsc --noEmit clean.

  11. added a commit that references this issue on Nov 11, 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-ciPackage/app: github-ci (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions