Webhooks
Verifying signatures
Every webhook is signed with your endpoint’s secret using HMAC-SHA256. Verify each request before acting on it.
Signature scheme#
ARAF-Signature: t=1795600502,v1=5f1c0e2b…9a4d
ARAF-Timestamp: 1795600502
ARAF-Event-Id: evt_95L9ZTu48WZumW0FUOMXD8mIv1 is the lowercase hex HMAC-SHA256 of the string <t>.<raw request body>, keyed with your endpoint’s signing secret (the full whsec_… string):
v1 = hex( HMAC_SHA256( key = signing_secret, message = t + "." + raw_body ) )Verification steps#
- 1
Read the raw body
Use the exact bytes received. Parsing and re-serialising JSON changes whitespace and key order and breaks the signature. - 2
Parse the header
SplitARAF-Signatureon commas intotand one or morev1values. Reject if either is missing. - 3
Check the timestamp
Reject if|now − t| > 300seconds. This bounds replay attacks; keep your server clock in sync (NTP). - 4
Compute and compare
Compute the expected HMAC and compare with eachv1using a constant-time comparison. Accept if any matches. - 5
De-duplicate
Recordevent_idand skip events you have already processed.
Examples#
Drop-in verification for common stacks. The cURL tab shows how to send a correctly signed request to your own endpoint for local testing.
webhooks.js (Node + Express)
import crypto from 'node:crypto';
import express from 'express';
const TOLERANCE_SECONDS = 300;
export function verifyArafSignature(rawBody, header, secret, now = Math.floor(Date.now() / 1000)) {
if (!header) return false;
let timestamp = null;
const signatures = [];
for (const part of header.split(',')) {
const [key, value] = part.trim().split('=', 2);
if (key === 't' && /^\d+$/.test(value)) timestamp = Number(value);
else if (key === 'v1' && /^[0-9a-f]{64}$/.test(value)) signatures.push(value);
}
if (timestamp === null || signatures.length === 0) return false;
if (Math.abs(now - timestamp) > TOLERANCE_SECONDS) return false;
const expected = crypto.createHmac('sha256', secret).update(`${timestamp}.${rawBody}`).digest();
// During secret rotation the header carries one v1 per active secret: accept any match.
return signatures.some((sig) => {
const candidate = Buffer.from(sig, 'hex');
return candidate.length === expected.length && crypto.timingSafeEqual(candidate, expected);
});
}
const app = express();
// Use the RAW body: re-serialised JSON will not match the signature.
app.post('/webhooks/araf', express.raw({ type: 'application/json' }), async (req, res) => {
const raw = req.body.toString('utf8');
if (!verifyArafSignature(raw, req.get('ARAF-Signature'), process.env.ARAF_WEBHOOK_SECRET)) {
return res.status(400).send('Invalid signature');
}
const event = JSON.parse(raw);
if (await db.processedEvents.exists(event.event_id)) return res.sendStatus(200); // duplicate
await queue.add('araf-event', event); // process asynchronously, respond fast
await db.processedEvents.insert(event.event_id);
res.sendStatus(200);
});Test it in your browser
Secret rotation#
When you rotate an endpoint’s secret in the Partner portal, the new secret signs deliveries immediately and the previous secret keeps signing for 24 hours. During that window the header carries two v1 values — one per active secret:
ARAF-Signature: t=1795600502,v1=<signature with new secret>,v1=<signature with previous secret>Deploy the new secret within 24 hours. Code that accepts any matching v1 (as in the examples) works throughout the rotation.
Common mistakes#
- Verifying a re-serialised body (e.g.
JSON.stringify(req.body)) instead of the raw bytes. - Using
==/===to compare signatures (timing leak) instead oftimingSafeEqual,hmac.compare_digestorhash_equals. - Only checking the first
v1— breaks during secret rotation. - Skipping the timestamp check, or using milliseconds instead of seconds.
- Stripping the
whsec_prefix from the secret — the full string is the key.