Paste an incoming signature header to run constant-time verification.
Replay-Window & Clock-Skew Gate
42s age vs 300s max
PASS: WITHIN REPLAY WINDOW
Event age 42s is within <=300s tolerance window (258s remaining). Pair with Idempotency/Delivery ID cache. (126 UTF-8 bytes · Stripe signs `${t}.${rawBody}` with HMAC-SHA256 hex and enforces a 300-second default replay window.)
Run a live webhook endpoint & SLA audit on WebhookSLA Guard (webhook.runglab.dev), grab the turnkey $29 WebhookSLA Guard Kit (WebCrypto HMAC verifiers, replay-window store, RFC RateLimit-* middleware & DLQ runbooks) on Creem, or audit webhook OpenAPI specs on SpecDiff (spec.runglab.dev). Need a PayPal invoice? Email [email protected].
Run a live webhook endpoint & SLA audit on WebhookSLA Guard (webhook.runglab.dev), grab the turnkey $29 WebhookSLA Guard Kit (WebCrypto HMAC verifiers, replay-window store, RFC RateLimit-* middleware & DLQ runbooks) on Creem, or audit webhook OpenAPI specs on SpecDiff (spec.runglab.dev). Need a PayPal invoice? Email [email protected].
Run a live webhook endpoint & SLA audit on WebhookSLA Guard (webhook.runglab.dev), grab the turnkey $29 WebhookSLA Guard Kit (WebCrypto HMAC verifiers, replay-window store, RFC RateLimit-* middleware & DLQ runbooks) on Creem, or audit webhook OpenAPI specs on SpecDiff (spec.runglab.dev). Need a PayPal invoice? Email [email protected].
-- Atomic idempotency gate (PostgreSQL) before processing Stripe evt_* webhooks
CREATE TABLE IF NOT EXISTS webhook_deliveries (
provider TEXT NOT NULL,
event_id TEXT NOT NULL,
received_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (provider, event_id)
);
-- Inside transaction before fulfilling order:
INSERT INTO webhook_deliveries (provider, event_id)
VALUES ('stripe', $1)
ON CONFLICT (provider, event_id) DO NOTHING
RETURNING event_id;
Implementation Steps & Key Insights
Read the unmodified raw UTF-8 HTTP request body bytes before any JSON parser touches whitespace or key ordering.
Parse `t=` and `v1=` from `Stripe-Signature`, verify `now - t <= 300s`, and compare `HMAC_SHA256(secret, t + '.' + rawBody)` in constant time.
Insert `event.id` into an atomic idempotency table (`ON CONFLICT DO NOTHING`) so duplicate deliveries never double-provision seats.
Push downstream billing/email work onto a durable queue with DLQ alerting and return `200 OK` within 2 seconds.
Re-serializing `JSON.stringify(req.body)` destroys key order, Unicode escapes, and trailing newlines — breaking HMAC verification silently in production.
Stripe rotates signing secrets gracefully by emitting multiple `v1=` pairs during rotation windows; check any `v1` match against active secrets.
Pair HMAC verification with `webhook.runglab.dev` live endpoint checks to confirm TLS, replay rejection, and 429 `Retry-After` behavior.
Common Production Pitfalls
Using `===` string comparison instead of constant-time comparison (`crypto.timingSafeEqual`).
Running PDF invoice generation or third-party CRM sync synchronously inside the webhook HTTP handler, triggering Stripe timeouts.
Omitting an idempotency store, causing duplicate license keys or refunds during Stripe's 72-hour retry retries.
Validate GitHub Apps & repository webhooks with `X-Hub-Signature-256`, deduplicate using `X-GitHub-Delivery`, and obey GitHub's 10-second response SLA and rate-limit headers.
Why does Stripe sign `${timestamp}.${rawBody}` instead of just the raw body?
Binding the Unix timestamp `t` directly into the HMAC input guarantees an attacker cannot modify the timestamp on a captured request to bypass your 300-second replay window.
What HTTP status codes cause Stripe to stop vs retry delivery?
2xx responses mark delivery successful. Any 4xx/5xx or timeout triggers exponential backoff retries for up to 72 hours in live mode.
How can I audit my live Stripe webhook endpoint before launch?
Test signature generation & replay windows locally here, then run live endpoint header, replay, and rate-limit SLA checks at https://webhook.runglab.dev.