Skip to navigation

Verifying webhook signatures

Prove that a delivery came from EVVA, was not changed, and is not a replay — before you act on it.

EVVA signs every delivery per Standard Webhooks. Verify each one on the raw request body, exactly as received — parsing and re-serialising the JSON changes the bytes and breaks the signature.

The headers

HeaderValue
webhook-idThe event’s eventId. Stable across retries and replays — your deduplication key.
webhook-timestampUnix seconds of this attempt. Refuse a timestamp more than 300 seconds from your clock.
webhook-signaturev1,<base64 HMAC-SHA256>. During a secret rotation there are two, space-separated, newest first.

The signed content is <webhook-id>.<webhook-timestamp>.<raw body>. The key is the base64-decoded part of your secret after the whsec_ prefix.

Verify with an SDK

Every official SDK verifies the signature, checks the timestamp window, checks that webhook-id equals the body’s eventId, deduplicates on it and tells you which status to answer: 204 handled or duplicate, 401 bad signature or timestamp, 400 bad payload, 500 your handler failed (EVVA retries a 500).

import { FileDedupStore, WebhookHandler } from '@evvahub/partner-sdk';
const webhooks = new WebhookHandler({
// Both secrets while a rotation overlaps; one otherwise.
secret: [process.env.EVVA_WEBHOOK_SECRET!, process.env.EVVA_WEBHOOK_SECRET_PREVIOUS!].filter(Boolean),
dedupStore: await FileDedupStore.open('./.evva/dedup.log'),
onEvent: async (event) => queue.push(event), // keep it short; the answer waits for it
});
// rawBody: the exact bytes of the request (for example express.raw()), never re-serialised JSON.
const result = await webhooks.handle({ headers: req.headers, body: rawBody });
res.status(result.status).end();

Use a durable, shared deduplication store. An in-memory store forgets after a restart, so a retry that arrives after a deploy would be handled twice.

Verify by hand

1

Read the raw body and the three headers

Header names are case-insensitive. A missing or empty header is a refusal.

2

Check the timestamp

webhook-timestamp must be plain decimal seconds within 300 seconds of your clock, in either direction.

3

Compute the expected signature

base64(HMAC-SHA256(key, "<webhook-id>.<webhook-timestamp>.<raw body>")), where key is the base64 decoding of your secret without its whsec_ prefix.

4

Compare in constant time

Split webhook-signature on spaces, keep the v1, entries, and accept if any of them equals your value — with a constant-time comparison, against every secret you currently hold.

5

Check the id and deduplicate

The body’s eventId must equal webhook-id. If you have already handled that id, answer 2xx and do nothing.

import { createHmac, timingSafeEqual } from 'node:crypto';
export function verifyEvvaWebhook(secrets, headers, rawBody, now = Math.floor(Date.now() / 1000)) {
const id = headers['webhook-id'];
const timestamp = headers['webhook-timestamp'];
const signatures = headers['webhook-signature'];
if (!id || !timestamp || !signatures) return false;
if (!/^\d+$/.test(timestamp.trim())) return false;
const ts = Number(timestamp.trim()); // the signed content uses the canonical integer
if (Math.abs(now - ts) > 300) return false;
const signed = Buffer.concat([Buffer.from(`${id}.${ts}.`), Buffer.from(rawBody)]);
const offered = signatures
.split(' ')
.filter((s) => s.startsWith('v1,'))
.map((s) => Buffer.from(s.slice(3), 'base64'));
return secrets.some((secret) => {
const key = Buffer.from(secret.trim().replace(/^whsec_/, ''), 'base64');
const expected = createHmac('sha256', key).update(signed).digest();
return offered.some((sig) => sig.length === expected.length && timingSafeEqual(sig, expected));
});
}

Rotating the signing secret

The agency rotates a secret in the Partner Hub (Rotate on the endpoint). The new secret is shown once, and for an overlap period — 24 hours by default, at most 7 days — EVVA signs every delivery with both secrets. Configure the new secret next to the old one, deploy, and remove the old one when the overlap ends: no delivery fails during the switch.

A signature proves the delivery is EVVA’s; it does not make the event fresh or unique. Always check the timestamp window and deduplicate on webhook-id — together they stop a captured request from being replayed.

The four SDKs are tested against the public Standard Webhooks reference vector and a shared set of EVVA vectors (rotation, tolerance edges, tampered headers, Unicode bodies), so they agree on every verdict.

Next steps