SANDBOX — simulated integrations, synthetic data, no real money moves · Docs describe the sandbox build
Skip to content

Webhooks

Verifying signatures

Every webhook is signed with your endpoint’s secret using HMAC-SHA256. Verify each request before acting on it.

Signature scheme#

Headers
ARAF-Signature: t=1795600502,v1=5f1c0e2b…9a4d
ARAF-Timestamp: 1795600502
ARAF-Event-Id:  evt_95L9ZTu48WZumW0FUOMXD8mI

v1 is the lowercase hex HMAC-SHA256 of the string <t>.<raw request body>, keyed with your endpoint’s signing secret (the full whsec_… string):

Signed payload
v1 = hex( HMAC_SHA256( key = signing_secret, message = t + "." + raw_body ) )

Verification steps#

  1. 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. 2

    Parse the header

    Split ARAF-Signature on commas into t and one or more v1 values. Reject if either is missing.
  3. 3

    Check the timestamp

    Reject if |now − t| > 300 seconds. This bounds replay attacks; keep your server clock in sync (NTP).
  4. 4

    Compute and compare

    Compute the expected HMAC and compare with each v1 using a constant-time comparison. Accept if any matches.
  5. 5

    De-duplicate

    Record event_id and 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

Paste a raw body, signature header and secret into the signature verifier. It runs entirely in your browser with WebCrypto — nothing is sent anywhere.

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:

text
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 of timingSafeEqual, hmac.compare_digest or hash_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.