Menu

1 / 5

Verify Webhook Signatures in Node.js: Fix the Raw-Body Bug

DEV Community: node·ExtensionBooster·10 days ago
#PVNk9Izj
#devtonodejs#devto#dev#stripe#signature
Long article (1112 words) — no AI summary yet.
Reading 0:00
15s threshold

Originally published on Extenify .

To verify webhook signatures in Node.js, you hash the request body with a shared secret and compare the result to a header. It looks like five lines of code, yet the top Stripe error, "No signatures found matching the expected signature for payload", has close to 90,000 views on Stack Overflow, and the cause is nearly always the same: you hashed the wrong bytes. Here is what to get right, and how GitHub, Stripe and Standard Webhooks (used by Polar) differ.

The signature covers bytes, not data

Anyone who knows your webhook URL can POST to it. So the provider signs each delivery with HMAC-SHA256 using a secret only you two share. You recompute the value and compare.

The catch: HMAC works on exact bytes. If your framework parses the JSON and you call JSON.stringify on it, whitespace, escapes and number formatting can change, and the check fails even though the data looks identical.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.