fix(api): reject GitHub webhook deliveries whose signature does not match
Summary
webhooks.verify(body, signature) from @octokit/webhooks returns false on an HMAC mismatch and only throws when the signature is empty. The route awaited it inside a try/catch and discarded the boolean, so any request carrying a well-formed x-hub-signature-256: sha256=<64 hex> header was accepted and fully processed (webhook_events → PR mirror → automation_events → dispatch). Pre-existing since 99920ed1a; surfaced by the trigger-provider audit.
Fix: capture the result and 401 when it is not true.
Test plan
- typecheck + biome
- Deliver a real GitHub ping → 200; same body with the last hex digit changed → 401
Summary by cubic
Rejects GitHub webhook deliveries when the HMAC signature does not match, preventing unverified events from entering the pipeline. Previously, the route awaited @octokit/webhooks verify() inside a try/catch and ignored its boolean result, so any well-formed x-hub-signature-256 header was accepted; now we check the return value and return 401 on mismatch.
- Behavior change: mismatched or missing signatures now return 401 and the event is not stored, mirrored, or dispatched.
- Required: ensure the GitHub webhook secret matches the server’s configured secret; validate with a GitHub “ping” delivery.
- Rollout: monitor 401s on the GitHub webhook endpoint after deploy.
Summary by CodeRabbit
- Bug Fixes
- Improved webhook signature validation to consistently reject requests with invalid signatures.
- Requests are now rejected whether verification fails explicitly or encounters an error, helping prevent unauthorized webhook processing.