Files
vitareba/lib/webhooks
g-butandClaude Opus 4.7 d3af4b1aaa fix(webhooks): reject stale Calendly signatures (replay protection)
The Calendly webhook computed HMAC over "<timestamp>.<rawBody>" but
never validated the timestamp itself. An attacker who captured one
valid webhook (leaked log, MITM on a misconfigured edge, etc.) could
replay it indefinitely to create duplicate booking rows or revive
canceled state.

Extracted verifyCalendlySignature() to lib/webhooks/calendly-signature.ts
so it is testable without spinning up an HTTP request, and added a
±5-minute timestamp tolerance check (matches Stripe's default and
Calendly's own documentation). Stale-future timestamps are also
rejected as a clock-skew abuse mitigation. The expensive HMAC
computation now runs only after the cheap timestamp check.

17 new unit tests cover every reject path (missing key, missing
header, malformed header, wrong body, wrong key, malformed hex,
stale, far-future) and every accept path (fresh, within tolerance,
small clock skew, exact boundary).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 18:24:17 +02:00
..