Menu

Verify webhook signatures over the raw bytes, and three other rules for a receiver that holds up
📰

Verify webhook signatures over the raw bytes, and three other rules for a receiver that holds up

DEV Community: node·TEMST·3 days ago
#64JPHtNV
#devtonodejs#devto#dev#event#express
Long article (1022 words) — no AI summary yet.
Reading 0:00
15s threshold

Most webhook bugs we've run into in payment and swap integrations have nothing to do with the signature math. HMAC-SHA256 is one line in every language. The trouble starts around it: the body gets parsed before it's checked, the same event gets processed twice, or the handler does slow work before it answers.

Below is a small Express receiver and the four rules we follow when we build one. The examples assume a generic X-Signature header that carries a hex HMAC-SHA256 of the request body. Your provider may use a different header name or encoding, so check their docs before you copy anything.

1. Verify the raw body, not the parsed JSON

The provider signs the exact bytes it sends. If your framework parses the JSON first and you rebuild it with JSON.stringify , the key order, whitespace or unicode escaping can change. The HMAC stops matching, and the fix people tend to reach for at 2 a.m.…

Continue reading — create a free account

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