Verify signatures
Every request is signed as Standard Webhooks defines, so its official libraries verify it with your endpoint's secret as it is. Verify before you trust the body, and reject the request when the check fails.
With a library
The libraries take the whole whsec_… secret and the raw request bytes, before any JSON parsing, and refuse a request whose time is more than 5 minutes from your clock. Install one:
sh
npm install standardwebhooks # Node
pip install standardwebhooks # Python
go get github.com/standard-webhooks/standard-webhooks/librariesjs
import { Webhook } from 'standardwebhooks'
const webhook = new Webhook(process.env.FIATLESS_WEBHOOK_SECRET) // the whole whsec_… string
const event = webhook.verify(rawBody, request.headers) // throws unless the install signed itpy
from standardwebhooks.webhooks import Webhook
webhook = Webhook(os.environ["FIATLESS_WEBHOOK_SECRET"]) # the whole whsec_… string
event = webhook.verify(raw_body, request.headers) # raises unless the install signed itgo
// verifyWithTheLibrary returns nil only for a request the install signed in the last 5 minutes.
// secret is the endpoint's whole "whsec_…" string; body is the raw request bytes, before any parsing.
func verifyWithTheLibrary(secret string, headers http.Header, body []byte) error {
webhook, err := standardwebhooks.NewWebhook(secret)
if err != nil {
return err
}
return webhook.Verify(body, headers)
}A test of the install sends a real delivery and checks it with the official Go library, and checks that the library refuses it once a byte changes, its time is stale or it is signed the way the install did before.
The headers
| Header | Value |
|---|---|
webhook-id | The event's id. Deduplicate on it. |
webhook-timestamp | Unix time of this attempt, in seconds |
webhook-signature | v1, and the base64 HMAC-SHA256 of this attempt. The spec allows a space-separated list; the install sends one entry. |
Check a request by hand
Only where no library fits your language:
- Take the raw request bytes, before any JSON parsing.
- Take your secret without its leading whsec_, and decode the rest from base64: those bytes are the key.
- Compute HMAC-SHA256 over
<webhook-id>.<webhook-timestamp>.followed by the raw bytes, and encode it in base64. - Compare it in constant time with each space-separated entry of
webhook-signaturethat starts withv1,; one must match. - Reject the request when
webhook-timestampis more than 5 minutes from your clock, in either direction.
A retry is signed again when it is sent, with a new webhook-timestamp, so it passes these checks. Deduplicate on the event id, never on the signature.
mjs
import { createHmac, timingSafeEqual } from 'node:crypto'
// Standard Webhooks' check by hand, where no library fits. secret: the whole "whsec_…" string. headers: the
// request's, by lowercase name, as Node gives them. rawBody: the request bytes, before any parsing.
export function verifyFiatlessSignature(secret, headers, rawBody, now = Date.now() / 1000) {
const id = headers?.['webhook-id']
const timestamp = headers?.['webhook-timestamp']
const signatures = headers?.['webhook-signature']
if (!id || !/^\d+$/.test(timestamp ?? '') || !signatures) {
throw new Error('malformed signature')
}
const key = Buffer.from(String(secret).replace(/^whsec_/, ''), 'base64')
const expected = createHmac('sha256', key).update(`${id}.${timestamp}.`).update(rawBody).digest()
const matched = String(signatures).split(' ').some((entry) => {
const [version, signature] = entry.split(',')
const provided = Buffer.from(signature ?? '', 'base64')
return version === 'v1' && provided.length === expected.length && timingSafeEqual(provided, expected)
})
if (!matched) {
throw new Error('signature mismatch')
}
if (Math.abs(now - Number(timestamp)) > 300) {
throw new Error('signature expired')
}
return JSON.parse(Buffer.from(rawBody).toString('utf8'))
}py
import base64
import hashlib
import hmac
import json
import re
import time
def verify_fiatless_signature(secret, headers, raw_body, now=None):
"""Standard Webhooks' check by hand, where no library fits. secret: the whole "whsec_…" string.
headers: the request's, read by lowercase name. raw_body: the request bytes, before any parsing."""
msg_id = headers.get("webhook-id") or ""
timestamp = headers.get("webhook-timestamp") or ""
signatures = headers.get("webhook-signature") or ""
if not (msg_id and re.fullmatch(r"[0-9]+", timestamp) and signatures):
raise ValueError("malformed signature")
key = base64.b64decode(secret.removeprefix("whsec_"))
mac = hmac.new(key, f"{msg_id}.{timestamp}.".encode() + raw_body, hashlib.sha256).digest()
expected = base64.b64encode(mac)
entries = (entry.partition(",") for entry in signatures.split(" "))
if not any(version == "v1" and hmac.compare_digest(signature.encode(), expected)
for version, _, signature in entries):
raise ValueError("signature mismatch")
if abs((time.time() if now is None else now) - int(timestamp)) > 300:
raise ValueError("signature expired")
return json.loads(raw_body)go
// verifyFiatlessSignature returns nil only for a request the install signed, as Standard Webhooks checks one.
// secret is the whole "whsec_…" string; body is the raw request bytes, before any parsing.
func verifyFiatlessSignature(secret string, headers http.Header, body []byte, now time.Time) error {
key, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(secret, "whsec_"))
id, timestamp := headers.Get("webhook-id"), headers.Get("webhook-timestamp")
signedAt, errT := strconv.ParseInt(timestamp, 10, 64)
if err != nil || id == "" || errT != nil || headers.Get("webhook-signature") == "" {
return errors.New("malformed signature")
}
mac := hmac.New(sha256.New, key)
mac.Write([]byte(id + "." + timestamp + "."))
mac.Write(body)
expected := base64.StdEncoding.EncodeToString(mac.Sum(nil))
matched := false
for _, entry := range strings.Fields(headers.Get("webhook-signature")) {
version, signature, _ := strings.Cut(entry, ",")
matched = matched || version == "v1" && hmac.Equal([]byte(signature), []byte(expected))
}
if !matched {
return errors.New("signature mismatch")
}
if skew := now.Unix() - signedAt; skew > 300 || skew < -300 {
return errors.New("signature expired")
}
return nil
}The Node and Python functions raise an error unless the request is genuine, and return the parsed event.
Test your code
The real signer produced this request. Your code must accept it at its "now", and reject it once any byte of the body changes. To try a live request, call sendWebhookTestEvent: it sends one endpoint.test event to your endpoint, signed like every event.
json
{
"body": "{\"id\":\"9f1a2b3c-4d5e-4f60-8a71-b2c3d4e5f607\",\"type\":\"wallet.deposit_credited\",\"aggregate_type\":\"deposit_wallet\",\"aggregate_id\":\"1080986a-b3b8-458c-a9cb-855f77f0189a\",\"schema_version\":1,\"occurred_at\":\"2026-09-23T10:00:00Z\",\"data\":{\"amounts\":[{\"amount\":\"0.25\",\"asset_id\":\"311d52dc-f56b-40b3-b77d-b68fab806e29\"}],\"credit_id\":\"4f0b8d2e-6a71-4c95-8e3d-1b2a9c7f5e60\",\"external_id\":\"customer-42\",\"network_id\":\"7845483d-e3b5-4754-bcec-cc6c2019ad89\",\"wallet_id\":\"1080986a-b3b8-458c-a9cb-855f77f0189a\"}}",
"headers": {
"webhook-id": "9f1a2b3c-4d5e-4f60-8a71-b2c3d4e5f607",
"webhook-signature": "v1,WHZM+odnmEoj4Km+V/yMShmkr1o0VcB85aK7E9jztVA=",
"webhook-timestamp": "1700000000"
},
"now": 1700000100,
"secret": "whsec_XbkMtJaWEl1g/YhfqibUITvLmMPVnBdzPwxDXgUxTN8="
}Rotate the secret
rotateWebhookEndpointSecret returns a new secret, and the old one stops signing at once; the install signs with one secret at a time. A delivery already on its way when you rotate the secret, or disable the endpoint, can still arrive up to 2 × 10 s later, signed with the old one. Until your server uses the new one, deliveries fail its check and are retried. Rotate also when you have lost the secret: no call returns an endpoint's current one, and registering its URL again answers without it.
Danger
Anyone who holds the secret can sign events your server will trust. Keep it out of logs and source code. Any key with webhooks:manage can rotate it and receive the new one, so keep that scope with the service that holds the secret, and read a payment with getTransaction before you credit it.