Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

Most webhook tutorials verify signatures wrong — here's the one that matches Stripe/GitHub/Shopify specs

Webhook signature verification is one of those things everyone copies from a blog post and nobody actually checks against the provider's spec. The failure modes are subtle and they all end the same way: your endpoint acc

Webhook signature verification is one of those things everyone copies from a blog post and nobody actually checks against the provider's spec. The failure modes are subtle and they all end the same way: your endpoint accepts forged events.

I keep finding the same four bugs in webhook code:

  1. Wrong signed payload. Stripe doesn't sign the raw body — it signs timestamp.body. Copy a generic HMAC example and your Stripe verification will never match, or worse, you'll "fix" it by disabling verification.
  2. No timestamp tolerance. A captured valid signature replays forever. Stripe's t= prefix exists precisely so you can reject old events — most tutorials skip it.
  3. Non-constant-time compare. === on hex strings leaks timing. Providers' SDKs use constant-time compare for a reason.
  4. Verifying the re-serialized body. Parse JSON then re-stringify and the bytes changed — the signature was computed over the raw bytes.

What correct looks like per provider

  • Stripe: header is t=timestamp,v1=signature; signed payload is t + "." + rawBody; reject if |now - t| > tolerance
  • GitHub: X-Hub-Signature-256: sha256=<hex hmac of raw body>
  • Shopify: X-Shopify-Hmac-Sha256 is base64, not hex — a classic copy-paste trap
  • Generic: hex HMAC-SHA256 of raw body, if that's what your provider does

Proof, not vibes

I packaged the verifier that implements all four schemes plus a fixture generator — webhook_verify.py --make-fixtures ./fixtures --secret test produces a test set for YOUR endpoint: valid headers for each scheme, an expired timestamp, a bad signature, and a tampered body. Run your endpoint against it before you ship.

Verified behavior: valid fixtures → verified:true exit 0; 407-second-old timestamp → rejected; bad sig → rejected; one-byte body tamper → rejected.

Honest limits: HMAC-SHA256 schemes only — not RSA-signed enterprise providers, JWT-embedded signatures, or mTLS. And the manual layer still matters: read the raw body (not re-serialized), make event handling idempotent, and decide your failure policy before an attacker tests it for you.

$16, stdlib-only Python, fixtures included:

https://wesleygitari2-cloud.github.io/nexus-store-redirect/p/webhook-verify-kit

What does your webhook endpoint do when verification fails — reject silently, log, or alert?

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.