Skip to content

fix(security)!: sign the webhook delivery id and event, dedupe GitHub deliveries on the signed body - #694

Merged
ajianaz merged 3 commits into
developfrom
security/webhook-replay
Nov 13, 2026
Merged

ajianaz merged 3 commits into
developfrom
security/webhook-replay

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

A captured webhook delivery can no longer be replayed as a new delivery under a fresh id. Native deliveries now sign the delivery id and the event (scheme v2). GitHub deliveries, which sign only the body, are deduplicated on the signed body instead of the unsigned delivery header.

Why

#678 (audit of #594): webhook::verify returned the id from X-Tole-Delivery / X-GitHub-Delivery, and neither signature covered it. Idempotency (hook_seen) was keyed on that attacker-chosen id. So one captured request fired the route's cron job again under each new id:

  • native deliveries: within the 300 s window;
  • GitHub deliveries: forever, since GitHub signs no timestamp.

The events allowlist also read unsigned headers.

Changes

  • tole_core::webhook, native scheme:
    • The native signature is X-Tole-Signature: v2=<hex>, an HMAC-SHA256 over v2\n<timestamp>\n<delivery id>\n<event>\n<body>. The event is the X-Tole-Event value, empty when the header is absent. The 300 s window is unchanged.
    • The fields cannot shift into each other: the id and the event are validated ([A-Za-z0-9._:-] and [A-Za-z0-9._-]), so neither contains a newline. An invalid event header is 400 (Reject::BadEvent).
    • The v1 form (sha256= over <timestamp>.<body>) is refused with 401 (Reject::OutdatedScheme), with a reason naming the v2 form.
  • tole_core::webhook, GitHub scheme: the idempotency key is gh: plus the SHA-256 of the body, the only signed material.
  • tole_core::webhook, API:
    • verify returns Verified { key, delivery, event }. key is what the ledger records; delivery is the header id, used in answers and the run's context.
    • sign takes the delivery id and the event.
    • Headers gains event, which reads X-Tole-Event or X-GitHub-Event.
  • tole serve:
    • records verified.key;
    • uses the verified event for the events list;
    • answers with the received delivery id;
    • insecure loopback routes keep their unsigned id, with the event validated.
  • tole hook test --fire signs v2.
  • Docs: threat-model webhook row (narrowed residual), automation-design.md §6, a README note on events, and a BREAKING CHANGELOG entry with a migration note.

Decisions to check

  • v1 is refused, not accepted alongside v2. Accepting both would keep the hole for anyone who strips v2. Native senders must update; tole hook test --fire already signs v2.
  • GitHub residual (documented):
    • After the 7-day hook_seen retention, a capture verifies again, because GitHub signs no timestamp.
    • X-GitHub-Event stays unsigned, so events is a convenience for GitHub routes, not a boundary; filter (on the signed body) is the boundary.
    • Two distinct GitHub deliveries with byte-identical bodies count as one. GitHub bodies carry unique fields (ids, timestamps, SHAs), so this is rare in practice.
    • The threat model recommends the native scheme and TLS in front of tole serve for allow_writes routes.
  • 400 before the signature check. A missing or invalid native delivery id is now reported as 400 before the signature is computed, because the id is part of the signed message. The status codes are unchanged.

Testing

  • webhook_core::a_captured_delivery_cannot_be_replayed_under_a_new_id (the audit's reproduction):
    • Native: the captured headers with a new id get BadSignature.
    • GitHub: a new id yields the same key, and the ledger answers duplicate, one day later.
  • webhook_core::the_native_event_is_signed_and_the_fields_cannot_shift:
    • A relabelled, removed or added event fails the signature.
    • Shifting . between the id and the event fails.
    • An event containing a newline gets BadEvent (400).
  • webhook_core::a_v1_native_signature_is_refused_as_outdated.
  • Existing webhook, serve and hook tests are moved to v2 (webhook_core, serve_hooks, serve_hook_fire, hook_cli).
  • serve_hooks::a_signed_delivery_is_accepted_once_even_across_a_restart gains an end-to-end replay check against the real tole serve:
    • the GitHub capture re-sent with a fresh id gets 200 duplicate;
    • the native capture with a fresh id gets 401.
  • Red on develop and mutation checks (both run, both failed as expected):
    • Signing an empty id in place of the delivery id fails the replay test.
    • Keying GitHub deliveries on the header id fails the replay test, the GitHub signature test and the serve end-to-end test.
  • Gates on the merged head: cargo fmt --all --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace, cargo test -p tole-core --no-default-features, the no-mcp CI profile, and cora review --no-llm --base origin/develop (no issues).

Closes #678

@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 57fffd9 into develop Nov 13, 2026
19 checks passed
@ajianaz
ajianaz deleted the security/webhook-replay branch November 20, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(webhooks): delivery id is not signed, so a captured delivery replays under new ids

2 participants