Guide

Verifying webhooks

Check the signature on every webhook before you trust it — with a tester that signs a sample for you.

Every webhook we send carries an X-CXPay-Signature header. Verify it before acting on the event to authenticate its timestamp and raw body.

The signature

The header looks like this:

cURL
1X-CXPay-Signature: t=1744054500,v1=3a1f9c2b8e7d...e9
  • t — the unix timestamp (seconds) when we signed.
  • v1 — HMAC-SHA256(secret, "{t}.{rawBody}"), hex-encoded.

The secret is your endpoint's signing secret (whsec_...), used as raw UTF-8. Do not Base64-decode it like an API request-signing secret. Reject anything whose timestamp is more than 5 minutes off. This limits the replay window; the same signed delivery can still verify within it. Persistently deduplicate the verified event's id before applying its effects, as shown in the embedded form fulfillment guide.

Sign over the raw request body bytes, exactly as received. Don't parse and re-stringify the JSON first — re-serializing changes whitespace and key order, and the signature won't match.

Verify it

Verify a webhook
1import crypto from "crypto";
2
3// req.body must be the RAW bytes — configure your framework to not pre-parse JSON.
4function verifyWebhook(rawBody, signatureHeader, secret) {
5 const parts = Object.fromEntries(signatureHeader.split(",").map((p) => p.split("=")));
6 const timestamp = parts.t;
7 const signature = parts.v1;
8
9 // Reject anything outside the 5-minute tolerance (replay protection).
10 if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) {
11 throw new Error("Webhook timestamp too old");
12 }
13
14 const expected = crypto
15 .createHmac("sha256", secret)
16 .update(`${timestamp}.${rawBody}`)
17 .digest("hex");
18
19 const a = Buffer.from(signature);
20 const b = Buffer.from(expected);
21 if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
22 throw new Error("Invalid signature");
23 }
24
25 return JSON.parse(rawBody); // safe to parse only after verifying
26}

Test your verifier

Set your webhook signing secret in the Developers panel, then generate a signed sample. POST the body with the header to your endpoint — or paste them into the verifier above — and confirm it's accepted. Then change one byte of the body and confirm it's rejected. Everything here runs in your browser; nothing is sent anywhere.

Webhook signature testerlocal

Set a in the Developers panel to sign and verify locally. Nothing leaves your browser.

Only the timestamp and the raw body are signed — not the other headers. As long as t and v1 arrive intact and the body is byte-identical, verification passes.

Next

Powered by CX Pay