Prompt
What should I use for webhook signature verification and replay protection?
Latest observation
Nov 21, 2026
OpenAI APIWeb search: off
Use both of these:
- Signature verification to prove the webhook came from the sender and wasn’t modified.
- Replay protection to stop an attacker from re-sending a valid old webhook.
Recommended approach
1) Verify the raw request body with HMAC
- Have the provider sign the exact raw payload using a shared secret.
- Recompute the signature on your side from the raw bytes, not parsed JSON.
- Compare signatures using a constant-time comparison.
Typical choice:
- HMAC-SHA256 over the raw request body
Why:
- Simple
- Widely supported
- Good security when implemented correctly
2) Include a timestamp in the signature
Use a header like:
X-Webhook-TimestampX-Webhook-Signature
Then:
- Reject requests with timestamps outside a small window, e.g. 5 minutes
- This limits replay of captured requests
3) Use a unique event ID for deduplication
Best practice is to include a unique identifier like:
event_iddelivery_idwebhook_id
Store processed IDs in a database or cache with a TTL:
- If you see the same ID again, ignore it
This is the strongest replay defense because:
- Timestamp checks stop old replays
- ID deduplication stops duplicate deliveries and repeated attacks within the time window
Best-practice combo
Use:
- HMAC-SHA256 signature
- Timestamp header
- Unique event/delivery ID
- Constant-time signature comparison
- Raw body verification
Example verification flow
- Read raw request body
- Get timestamp and signature from headers
- Reject if timestamp too old/new
- Recompute expected signature from
timestamp + "." + raw_bodyor whatever canonical format the provider specifies - Compare signatures in constant time
- Check whether the event ID was already processed
- If new, process and store the ID
Important implementation notes
- Don’t parse and reserialize JSON before verifying
- Don’t use
==for signature comparison - Don’t rely on IP allowlists alone
- Rotate secrets periodically if supported
- If the provider supports it, prefer a scheme with:
- versioned signatures
- timestamp
- event IDs
If you want a concrete recommendation
For most systems:
- HMAC-SHA256 + timestamp + event ID dedupe is the right choice
If you want, I can give you:
- a sample implementation in Node.js, Python, Go, or Java
- a recommended header format
- a webhook verification checklist