Skip to content

github-ci(worker): HMAC gate fails open when GITHUB_WEBHOOK_SECRET is unset — unsigned POSTs are processed and written to Turso #6936

Closed

Description

@dezren39

Problem

The github-ci Worker (pkgs/github-ci/worker/src/index.ts, #5693) is the GitHub webhook receiver: its header comment states the gate plainly — "Gate: HMAC-SHA256 over the raw body, X-Hub-Signature-256 header, verified with Web Crypto against GITHUB_WEBHOOK_SECRET … the HMAC is the gate" (:3-9), and the README calls it the "HMAC-SHA256 gate". The secret is a required deployment secret per wrangler.toml ("HMAC gate; NEW value minted for this Worker, vaulted in BWS").

The implementation only verifies when a secret happens to be present:

// src/index.ts:73-80 @ def55caf48
const secret = env.GITHUB_WEBHOOK_SECRET ?? "";
if (secret) {
  const given = (req.headers.get("x-hub-signature-256") ?? "").replace("sha256=", "");
  const expected = await hmacHex(secret, raw);
  if (!timingSafeEqual(given, expected)) {
    return new Response("bad signature", { status: 401 });
  }
}

When GITHUB_WEBHOOK_SECRET is empty or the binding is missing — a deploy before wrangler secret put lands, a renamed/mistyped binding, a preview/dev deployment (workers_dev = true in wrangler.toml) — the gate is skipped entirely and every POST is processed as if it were an authentic GitHub delivery, including the writes behind the gate:

  • workflow_run → INSERT OR IGNORE INTO ci_events in fleet-platform Turso (failure conclusions keep the raw forged payload for forensics),
  • fleet-repo push → advances agent_repo_snapshots.head_sha to an attacker-chosen SHA + appends a sink event,
  • fleet-repo pull_request / issues → sink event + dirty:<repo> watermark.

The sibling atlas-search Worker fails closed on the same condition (gateOk: if (!presented || !env.GATE_TOKEN) return false). This Worker fails open.

Evidence (verified this run, laptop @ def55ca)

Probe ~/git/fleet/probe-ghci-gate/probe.ts imports the real src/index.ts (bun) with a stub Turso pipeline server that records statements:

Controls — secret configured:

  • unsigned ping → 401 bad signature
  • validly signed ping → 200 pong
  • bad-signature ping → 401 bad signature

Defect — no signature presented at all:

  • GITHUB_WEBHOOK_SECRET: "", unsigned ping → 200 pong
  • secret binding missing entirely, unsigned ping → 200 pong
  • GITHUB_WEBHOOK_SECRET: "", unsigned completed workflow_run for developing-today/code → 200 {"ok":true,"repo":"developing-today/code","run_id":999,"conclusion":"success"}, and the stub recorded 1 pipeline call containing INSERT OR IGNORE INTO ci_events — an unauthenticated request reached the Turso write.

Existing tests (test/worker.test.ts) always run with the secret bound (vitest.config.ts bindings) and cover only the bad-signature case; there is no missing/empty-secret case.

Related: #5693 (the Worker's tracking issue), #6925 (same Worker's sink reachability).

Why it matters

A webhook receiver whose only authentication silently disables itself on a configuration miss is a forge-anything endpoint: CI history, repo snapshot heads, and agent events/watermarks are all downstream of these writes, and a forged push head_sha or failure workflow_run payload is indistinguishable from a real delivery once stored. The failure mode is silent — nothing logs that the gate was skipped — so a misconfigured deploy would not be noticed until forged data is found downstream. Fail-closed is the house pattern for exactly this condition (atlas-search gateOk, cold-store, pkgs/id fail-closed fixes).

Acceptance criteria

  • With GITHUB_WEBHOOK_SECRET unset or empty, every POST (including ping) is rejected with a 5xx configuration error (e.g. 500/503 "webhook secret not configured") and no Turso/sink write is attempted; the rejection is logged server-side without logging any credential value.
  • With the secret configured, behavior is unchanged: valid signature processes normally, missing/bad signature → 401 (existing tests keep passing).
  • The GET liveness response stays unauthenticated (it exposes no data and takes no writes) — or, if it is also gated, the README/wrangler notes say so explicitly.
  • New worker tests cover the unset-secret and empty-secret cases for at least ping and one writing event (workflow_run or push), asserting rejection and zero Turso pipeline calls.
  • Header comment / README wording and the code agree: the HMAC is the gate, unconditionally.

Activity

  1. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  2. added
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/highImportant and time-sensitive
    kind/securitySecurity issue or security hardening
    app/github-ciPackage/app: github-ci (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 7, 2026
  3. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. added
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 10, 2026
  5. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged

    • Agent: triage-step
    • State: triaged
    • Verdict: work kind task/small-fix · priority/high · effort/s · kind/security (as filed)
    • Priority why: priority/high retained from filing: a fail-open signature gate is a security exposure on a write path; brief line 1 class (broken sign-in/secrets route) and line 4.
    • First step: Find the webhook HMAC verification in the github-ci worker and confirm the unset-secret path processes the request.
    • Acceptance: Unset/empty secret rejects the webhook (fail closed) with a clear log line Correctly signed webhooks still process; wrongly signed are rejected Worker tests cover unset, wrong-secret, and correct-secret cases
    • Fix packet: repo-health:v1:fix:developing-today/code:issue:6936 → queue repo-health-code-pilot, task 14437 (enqueued by triage-step this run)
  6. 11 remaining items

  7. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    lane: code-e
    task: 14437
    issue: #6936
    state: handed_off
    execution_lane: opencode (lane row 5649)
    handoff_reason: scheduled shift is time-bounded; claimant is the persistent execution session
    next: claimant launches the bound opencode session

  8. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  9. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  10. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    state: done
    task: 14437
    lane: code-w
    issue: "#6936"
    pr: "#8233"

    Fixed by lane code-w (task 14437, direct per #8187) in PR #8233:

    • Resumed, not restarted: the task's existing branch (queue/14437-6936-hmac-fail-closed) held an uncommitted fix in its opencode worktree. This lane verified it against every acceptance criterion, added the missing coverage, and landed it.
    • src/index.ts: unset/empty/whitespace GITHUB_WEBHOOK_SECRET → logged configuration error (no credential value) + 503 "webhook secret not configured" before any body read or Turso/sink write. Configured behavior unchanged (valid → process; bad/missing signature → 401). GET liveness stays unauthenticated.
    • Tests: unset + empty cases for both workflow_run (writing event) and ping, asserting 503 and, via the fetchMock no-net-connect + no-pending-interceptors harness, zero Turso pipeline calls; wrong-secret 401 case added.
    • README gate wording updated so code, header comment, and README agree: the HMAC is the gate, unconditionally.
    • Verification: npm test 34/34 pass (4 files); npm run typecheck clean.

    Task 14437 completes as pr_opened (PR #8233, CI pending in the fleet stall).

  11. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 10, 2026
  12. dezren39 commented on Nov 12, 2026

    @dezren39
    MemberAuthor

    Suggestions-pass verification (2026-11-12): confirmed the fail-open branch in the current checkout. pkgs/github-ci/worker/src/index.ts:71-78 normalizes a missing binding to "" and only checks x-hub-signature-256 inside if (secret), so an empty/unbound secret skips authentication. The deployment docs say the secret is a required webhook secret (pkgs/github-ci/worker/README.md:52-56), and the worker header calls HMAC “the gate” (src/index.ts:4-8). Existing worker tests use the configured test binding (worker/vitest.config.ts) and cover bad signatures, but not the missing/empty binding path. No duplicate opened; this matches the existing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/github-ciPackage/app: github-ci (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/securitySecurity issue or security hardeningpriority/highImportant and time-sensitivesource/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