Verifying Webhook Unix Timestamps to Stop Replay Attacks

Written by Raheel Ikram | Updated December 5, 2026 | Reading time: 5 minutes

Checking only a cryptographic signature on an incoming payment webhook leaves your server exposed to replay attacks. If an attacker captures a valid signed HTTP request and resends it two days later, your endpoint could unlock orders or issue credits twice unless you verify the signed Unix timestamp.

How the Stripe-Signature Timestamp Header Works

Payment platforms like Stripe include a Stripe-Signature header formatted like t=1764892800,v1=5257a869..., where t is a 10-digit Unix timestamp in seconds. As explained in the Stripe Webhook Signature documentation, the sender signs timestamp + "." + raw_request_body using HMAC-SHA256.

Verification Steps to Block Replay Attacks

  1. Extract t and v1 from the signature header.
  2. Compute the expected HMAC-SHA256 using your raw unparsed HTTP body bytes and webhook secret. Never parse and re-stringify JSON first, or whitespace changes will break the hash.
  3. Compare signatures in constant time using crypto.timingSafeEqual() to prevent timing attacks.
  4. Enforce a timestamp tolerance window: Official Stripe SDKs reject webhooks older than 300 seconds (5 minutes) by comparing Math.abs(nowSeconds - t) <= 300.
const nowSec = Math.floor(Date.now() / 1000);
if (Math.abs(nowSec - Number(headerTimestamp)) > 300) {
  throw new Error("Webhook timestamp outside 5-minute tolerance");
}
About the Author: Raheel Ikram

Creator of Timestamp Converter, writing practical guides on timekeeping, SQL schema design, and web utilities. Read full bio.