HomeGuidesHow to Securely Verify Webhook Signatures with HMAC-SHA256
Security & Privacy7 min readUpdated 2026-11-05

How to Securely Verify Webhook Signatures with HMAC-SHA256

Protect payment and event callbacks from Stripe, GitHub, and Shopify by implementing constant-time HMAC signature verification.

Need to do this immediately?

Use our free, private client-side browser tool with zero installation.

Launch Webhook HMAC Signature Verifier
When integrating payment providers like Stripe or developer platforms like GitHub, your application exposes public HTTP POST endpoints to receive asynchronous event notifications. Without cryptographic verification, an attacker can forge fake 'payment_succeeded' events, gaining unauthorized access to products. HMAC-SHA256 signatures are the industry defense standard.

How Hash-Based Message Authentication Codes (HMAC) Work

When the provider sends a webhook, they compute a cryptographic hash of the raw HTTP request body combined with a shared secret key using HMAC-SHA256. This signature is placed in a custom header (e.g. Stripe-Signature or X-Hub-Signature-256).

Your server receives the payload, computes the identical HMAC locally with your secret, and compares the two hashes. If they match, the payload is authentic and was not altered in transit.

The Danger of String Equality: Timing Attacks

Comparing signatures using standard string comparison (signature === expected) is vulnerable to side-channel timing attacks. Standard comparisons return false on the first mismatched byte, allowing attackers to measure microsecond response variations to brute-force valid signatures.

Always use constant-time comparison algorithms like Node.js crypto.timingSafeEqual().

Pro Tip:Always compute HMAC over the raw unparsed request body buffer; parsing and re-stringifying JSON mutates key ordering and breaks verification.

Step-by-Step Tutorial

1

Input Raw Webhook Payload

Paste the raw, unparsed JSON payload exactly as received in the HTTP body.

2

Provide Secret Key & Received Header

Enter your webhook signing secret and the signature header provided by the service.

3

Verify Cryptographic Authenticity

DocSwift computes the HMAC-SHA256 hash locally in your browser to verify integrity.

Ready to Try It Yourself?

DocSwift processes everything directly on your device. Fast, safe, and completely free forever.

How helpful was this guide?

Rated 4.9 / 5 by 3,420+ users worldwide

Share with Colleagues & Friends

Help others protect their document privacy

Frequently Asked Questions

Why does JSON.stringify(req.body) cause HMAC verification to fail?

JSON parsers do not guarantee deterministic key order and strip whitespace. Cryptographic hashing is bit-exact: any altered character produces a completely different hash.

How do webhook providers prevent replay attacks?

Providers like Stripe include a timestamp in the signature header (t=...). Servers must verify that the timestamp is within a 5-minute tolerance of the current system clock.