Prevent webhook replay attacks: verify signed timestamps and event IDs
A webhook replay attack occurs when someone resends a previously valid request so that a receiver repeats a payment or state change. Defend with two checks: enforce an allowed age for signed request timestamps, and persistently claim each event ID atomically so its side effects run once. The timestamp check limits freshness; the ID record suppresses duplicate processing.
A webhook replay attack occurs when someone resends a previously valid request so that a receiver repeats a payment or state change. Defend with two checks: enforce an allowed age for signed request timestamps, and persistently claim each event ID atomically so its side effects run once. The timestamp check limits freshness; the ID record suppresses duplicate processing.
Providers sign different fields. Do not treat an unsigned timestamp or ID as trustworthy evidence. Check the provider’s contract, then combine freshness checks, deduplication, and business-level idempotency.
Replay attacks and normal retries
Providers may redeliver an event after a network problem or receiver outage. This legitimate retry is still a duplicate request at the receiver. An attacker may instead resend a captured request to cause another side effect. The receiver cannot tell which one occurred simply because the request is repeated.
When a duplicate is found, skip completed business effects and respond successfully according to the provider’s contract. For failed events, inspect processing state and resume only safe work. Use an atomic storage constraint so two concurrent copies cannot both proceed.
The controls solve different problems
| Control | What it addresses | Risk if omitted |
|---|---|---|
| Signature verification | Whether the request was produced with the provider’s secret or trusted signing key and whether signed content changed | A forged payload might be accepted |
| Signed timestamp and age window | Limits how long a captured signed attempt can be accepted | A captured request may be replayed much later |
| Durable event-ID record | Prevents the same ID from repeating business effects | A resent or concurrent request may duplicate work |
| Business idempotency | Handles different event IDs that could cause the same business action | The same order or payment may be applied twice through different event representations |
A signed timestamp is not enough: the same request can be resent several times inside the allowed window. Conversely, an ID record without a timestamp can suppress duplicate effects but still accept stale requests. If the ID is not included in the signature, an attacker may also change the header ID.
Apply a signed time window
Standard Webhooks signs the message ID, attempt timestamp, and raw payload, and recommends checking that the timestamp is within an allowed tolerance. GitLab signing tokens also use HMAC-SHA-256 over the unique webhook ID, request timestamp, and payload; GitLab documentation says to validate that the timestamp is recent before processing.
The Stripe signature header includes a timestamp and signature. The current Stripe Node SDK defaults its webhook verification tolerance to 300 seconds (five minutes). This is behavior of that SDK implementation, not a universal provider rule; confirm the version used in your integration. Prefer the provider SDK over parsing the signature header yourself.
A wider window permits older captured requests; a narrower one can reject legitimate retries or delayed deliveries. Keep server clocks synchronized and set the window to fit the provider’s delivery behavior and the risk of the operation. Reject malformed, stale, or disallowed future timestamps as the contract specifies. If the provider does not sign a timestamp, an arbitrary request header cannot establish freshness.
Even a time window leaves a replay opportunity within that window. Atomic event-ID deduplication is needed to stop the same event from repeating an effect.
Claim IDs atomically before processing
For a verified request:
Verify the provider’s signature and signed timestamp, then check event type and endpoint scope.
Atomically insert the signed event ID into persistent storage or detect that it already exists. Confirm from documentation whether the ID is covered by the signature.
Only the request that claims a new ID begins the business action. For an existing ID, inspect whether it is complete, in progress, or failed and recoverable.
Store the outcome under that ID and respond. Use a uniqueness constraint or atomic conditional write so only one concurrent request can claim the work.
An in-memory cache can lose its records on restart or fail to coordinate multiple server instances. Use shared durable storage and atomic writes in a multi-instance deployment. Keep IDs at least as long as the provider’s retry and manual-redelivery period, while considering retention requirements and storage cost. Preserve business idempotency after the record expires because an old event could reappear.
For a successfully processed duplicate, return success without repeating effects so the provider stops retrying. Do not permanently ignore every record that exists: an in-progress request must not start twice, while a failed event may need safe recovery.
Provider-specific limits
| Provider contract | Useful protection | Boundary |
|---|---|---|
| Standard Webhooks | Signed ID and attempt timestamp; combine a tolerance check with ID deduplication | Check the default tolerance and behavior of the actual library |
| GitLab signing token | HMAC covers webhook ID, timestamp, and raw body; validate a recent timestamp and deduplicate by ID | The legacy plaintext secret-token header does not provide signed freshness |
| Stripe | Verify the Stripe-Signature timestamp with the official SDK and persist the Stripe event ID | Confirm the SDK’s tolerance for your version; normal retries reuse an event and should be safely acknowledged as duplicates |
| GitHub | Record X-GitHub-Delivery to recognize a delivery and its redelivery, and verify the payload HMAC | GitHub documents the HMAC over the payload body, not the delivery-ID header. Use the header for operational deduplication, not as a value cryptographically bound to the body; also enforce business idempotency. |
Do not force these contracts into one assumed protocol. Trust only fields the provider actually signs.
Verification and recovery checklist
Test that invalid signatures, stale timestamps, and malformed IDs never begin business work.
Redeliver a valid request and confirm that its side effect occurs once while the duplicate receives a safe response.
Send concurrent copies and verify that the atomic ID claim lets only one proceed.
Check an old timestamp, changed body, missing signature, and reused ID. Use a nonproduction endpoint and test secret.
Monitor clock synchronization, duplicate IDs, processing states, and rejection reasons without logging secrets or sensitive raw bodies.
A failed verification can result from an attack, wrong endpoint secret, changed body, clock skew, or SDK configuration. Record a limited reason code and compare provider delivery records with server logs. Keep the boundary between the deduplication claim and business work clear so a partial failure cannot repeat the effect.
Sources
[Standard Webhooks specification 1.0.0](https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md)
[GitHub Docs: Best practices for using webhooks](https://docs.github.com/en/webhooks/using-webhooks/best-practices-for-using-webhooks)
[Stripe Node SDK: Webhook signature verification](https://github.com/stripe/stripe-node/blob/master/src/Webhooks.ts)
[GitLab Docs: Webhooks and signing tokens](https://docs.gitlab.com/user/project/integrations/webhooks/)
[GitLab 19.0 release notes: Secure webhooks with HMAC signing tokens](https://docs.gitlab.com/releases/19/gitlab-19-0-released/)