Menu

1 / 3

How to verify webhook HMAC signatures in PHP and Node.js

DEV Community: php·Stablevoy·3 days ago
#NIat7E26
#devto#dev#secret#request#event
Long article (2300 words) — no AI summary yet.
Reading 0:00
15s threshold

A webhook endpoint is a public URL that changes orders. Anyone who finds it can send it a request that says "invoice paid", so the only thing standing between a forged request and a shipped order is the signature check. This post builds that check in PHP and in Node.js, step by step, and runs it against a valid request, a forged one and a replayed one.

The examples use the Stablevoy header format, X-Stablevoy-Signature: t=<unix seconds>,v1=<hex> . Many payment providers sign webhooks the same way and differ only in the header name and the encoding, so the code carries over with small changes.

How a signed delivery works

The sender and your server share one secret. The sender never sends it: it uses the secret to compute an HMAC of the request and puts the result in a header. Your server computes the same HMAC from what it received. If the two match, the request came from someone who knows the secret and nobody changed it on the way.

One delivery.…

Continue reading — create a free account

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