Skip to content

github-ci and github-backup webhook receivers buffer the whole body before verifying the HMAC signature #11335

Closed

Description

@dezren39

Evidence (origin/main cb96495)

  • pkgs/github-ci/worker/src/index.ts:76 (const raw = await req.text();) buffers the whole webhook body. The HMAC is computed only afterwards, at :78, and compared at :79. Auth fails closed on the secret (:70-74), but the body read runs before the signature check.
  • infra/github-backup/worker/src/index.js:44 (const body = await req.text();) has the same order. The secret check is at :41-43, the HMAC at :46, and the signature comparison at :50.
  • Neither handler checks Content-Length or caps the read. A grep of both src/ trees for content-length, 413 and size limits finds nothing.

Result: any unauthenticated POST to either receiver makes the Worker buffer an arbitrary body in memory before a 401 is returned. The platform request limit is the only bound. This is the same order-of-operations problem that #11331 and #11332 describe for other Worker routes.

Not reproduced at runtime. The claim is about the code path.

Why it matters

GitHub's webhook payloads are bounded (about 25 MB per GitHub's documented limit; confirm the exact figure before setting the cap). A legitimate delivery never needs more, so a cap can refuse oversized input cheaply without changing behaviour for real deliveries. Today an oversized or drip-fed unauthenticated body costs the Worker its full memory before the signature fails.

Fix shape

  • Reject with 413 when Content-Length is present and exceeds the cap, before reading the body.
  • For bodies without a length, read through a size-capped reader that stops at cap + 1 byte and returns 413.
  • Keep the existing HMAC check as the authoritative gate, unchanged in order after the bounded read.
  • Apply the same helper to both receivers rather than two copies.

Acceptance criteria

  • A POST whose declared Content-Length exceeds the cap returns 413 without reading the body, on both github-ci and github-backup.
  • A chunked POST larger than the cap stops reading at the cap and returns 413.
  • A correctly signed delivery under the cap is processed exactly as before (existing tests stay green).
  • A test covers the early reject and the chunked cap on each worker.

Dedupe

Searched open and closed issues for github-ci worker body, github-backup worker, webhook signature body, X-Hub-Signature, HMAC verify before read and buffers body before signature. Related but different: #6936 (fail-open secret, closed), #6946 and #6951 (JSON null bodies, closed), #9445 and #9454 (projector webhook intake design; the projector already caps at 10 MB and is a different component). No open issue or PR covers a body cap on these two workers.

Queue: repo-queue is not available in this environment, so no queue item was enqueued. Coverage needs a follow-up pass.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    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
    app/github-ciPackage/app: github-ci (pkgs/ or apps/ in this repo)
    on Nov 17, 2026
  2. developing-today commented on Nov 17, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    Current-main triage (2026-11-17): both receiver paths still buffer the full POST before HMAC. On origin/main a03c40960a6b938bf36258687f1305237da717e6, pkgs/github-ci/worker/src/index.ts:76 reads req.text() before HMAC computation/comparison at :78-79; infra/github-backup/worker/src/index.js:44 does the same before :46-50. No open PR matches #11335.

    Enqueued current-main triage task 20775 in repo-health-code-pilot to maintain live issue coverage and route the two-handler bounded-read fix with tests for declared and chunked bodies plus valid signed deliveries.

  4. added a commit that references this issue on Nov 17, 2026
  5. dezren39 commented on Nov 18, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: done
    task: 20775
    lane: code-i (OpenChamber scheduled lane, worker repo-worker-code)
    stage: claimed -> verified -> complete

    Current-main verification 2026-11-18 (origin/main, read via gh api): both webhook receivers now read through a capped reader before the HMAC check. pkgs/github-ci/worker/src/index.ts reads with readBodyUpTo and returns 413 when over the limit, and infra/github-backup/worker/src/index.js uses readBodyUpTo(req, MAX_WEBHOOK_BODY_BYTES) with 413 before hmacHex. The issue was already closed COMPLETED on 2026-11-17. No further fix needed; outcome already_done.

  6. dezren39 commented on Nov 18, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    lane: openchamber-scheduled-lane (code-j) · worker repo-worker-code · queue task 20807
    state: already_done (verified)
    Fresh origin/main 6a87937. Both receivers now read through a bounded helper before HMAC: pkgs/github-ci/worker/src/index.ts (readBodyUpTo before hmacHex) and infra/github-backup/worker/src/index.js (readBodyUpTo at line 75, hmacHex at 78). Fix landed in 563c3e2 via PR #11428 (merge 840a188). Tests cover declared oversized 413, chunked cap, and the helper (github-backup test/index.test.mjs:316,332; github-ci test/body.test.ts:21). Issue is CLOSED; no further work.

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 systemapp/github-ciPackage/app: github-ci (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)queue/queuedHas a queued queue tasksource/creatorFiled by the new-issue-creator jobstatus/triagedTriaged and routed (see agent note)status:donetask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions