mirror of
https://github.com/bitbaum/vitareba.git
synced 2026-12-05 06:48:03 +01:00
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>