Express express.raw() Webhook Verification, Retry-After 429s & Idempotency Store
Fix the classic Express `express.json()` raw-body trap by mounting `express.raw({ type: 'application/json' })` before JSON middleware, plus timing-safe HMAC and RFC 429 headers.
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].
Mounting `app.use(express.json())` at the top of `server.js` is the single most common cause of Express Stripe/GitHub/Shopify webhook failures.
Alternatively, if using global `express.json({ verify: (req, res, buf) => { req.rawBody = buf; } })`, store `req.rawBody` cleanly without mutating encoding.
Never leak stack traces or expected HMAC values in 401 responses.
Common Production Pitfalls
Mounting `express.json()` before webhook routes, converting `req.body` into a parsed JS object.
Passing a non-Buffer string into `req.body` or forgetting `Buffer.from(..., 'utf8')` byte lengths.
Throwing unhandled `RangeError` from `timingSafeEqual` when an attacker sends a 1-byte signature header.
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.