Menu

How to verify HMAC-SHA256 signed webhooks in Node and Python
📰

How to verify HMAC-SHA256 signed webhooks in Node and Python

DEV Community: node·delay.run·22 days ago
#LCWN8RIK
#devtonodejs#devto#dev#timestamp#body
Long article (1015 words) — no AI summary yet.
Reading 0:00
15s threshold

If your app exposes an endpoint that another service calls (a webhook, a scheduled job URL, a callback), anyone who discovers the URL can call it too. Signed requests fix that. The sender computes an HMAC of the request with a shared secret, sends it in a header, and you recompute it and compare. Here's how to do it correctly, including the parts most implementations get wrong.

How HMAC signing works

You and the sender share a secret, for example a long random string.

For each request, the sender computes HMAC-SHA256(secret, message) , where the message is usually a timestamp plus the raw request body.

The sender puts the signature (and the timestamp) in headers.

You compute the same HMAC over the same message and compare.

If someone changes the body, or doesn't know the secret, the signatures won't match.

The exact header names and message format vary by sender, so check their docs.…

Continue reading — create a free account

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