The problem
A webhook arriving twice isn't an edge case — it's the normal behavior of at-least-once delivery, which is what every major provider actually guarantees. Retry a timeout, hit a race condition, and your handler gets called twice for the same event. If it isn't built for that, the failure mode is invisible until a customer gets charged twice or an email goes out twice.
What this implements
The same security scheme providers like Stripe use, built from scratch and implemented twice — independently, in Python and Node.js:
- HMAC-SHA256 signature verification — reject anything not actually signed by the sender's shared secret.
- Timestamp validation — reject stale or replayed requests outside an acceptable window.
- Idempotency-key deduplication — catch true duplicates even when the signature and timestamp both check out.
Where the two ecosystems actually differ
This is the part most "same thing in two languages" demos skip, and it's the part that actually matters if you're hiring across stacks:
Python's hmac.compare_digest tolerates comparing strings of different lengths — it just returns False. Node's crypto.timingSafeEqual throws an exception if the buffers aren't the same length. Naively porting the Python logic to Node means an unhandled exception on a malformed request instead of a clean 401. The Node implementation checks length before the constant-time comparison specifically because of this difference — documented in the README, not just discovered and silently patched.
What's tested
7 tests in Python (pytest), 7 in Node (node --test) — both passing locally before every push, both confirmed green in CI independently (two separate jobs: python-tests, node-tests).
Stack
Python, Node.js, HMAC-SHA256, pytest, node:test, GitHub Actions.
If you're integrating any payment, messaging, or SaaS webhook and "what happens if it arrives twice" isn't already answered in your code, this is the answer — in whichever of the two stacks you're running.