Verify a webhook signature
Prove that every delivery comes from Botello and has not been tampered with, with ready-to-copy code in Node.js, PHP and Python.
- Plans
- All plans
- Roles
- Owner, Admin
- In the admin
- Integrations › Webhooks
Anyone can send a request to your webhook address. The signature proves that the delivery really comes from Botello, that it was not modified in transit and that it is not being replayed later. Every delivery is signed in two formats: the Botello format and the open Standard Webhooks format. Verify either one.
Any receiver exposed to the Internet: your API, a serverless function, a PHP server. With Zapier, Make or n8n, verification is optional but recommended if the tool supports it.
Before you start
- You have the webhook secret, which starts with
whsec_: IntegrationsWebhooks, webhook menu, Show signing secret. - Your server can read the raw body of the request, before any JSON parsing.
- Your server clock is accurate (NTP).
The two formats
| Botello format | Standard Webhooks | |
|---|---|---|
| Headers | X-Botello-Timestamp, X-Botello-Signature | webhook-id, webhook-timestamp, webhook-signature |
| Signed text | <timestamp>.<raw body> | <webhook-id>.<timestamp>.<raw body> |
| Algorithm | HMAC-SHA256, output in hexadecimal | HMAC-SHA256, output in base64 |
| Header value | sha256=<hex> | v1,<base64> |
| HMAC key | The whole secret, including whsec_, as is | The part after whsec_, base64-decoded |
| Ready-made library | no | yes (Node.js, Python, PHP, Go, Ruby…) |
In both formats:
- the timestamp is in Unix seconds, and it is part of the signed text: a captured request cannot be replayed with a new timestamp;
- reject a timestamp more than 5 minutes (300 seconds) away from your current time;
- during a secret rotation, the header contains two signatures separated by a space, the new one first. Accept the delivery if either of them is valid;
- compare in constant time (
timingSafeEqual,hash_equals,hmac.compare_digest), never with==.
webhook-id is the event identifier (evt_…), the same as id in the body.
Always use the raw body
Compute the signature on the exact bytes received. If your framework has already parsed the JSON, re-encoding it changes the whitespace or key order, and the signature no longer matches.
Verify the Botello format
Read the headers and the raw body
Get X-Botello-Timestamp, X-Botello-Signature and the raw body, without parsing it.
Check freshness
Reject if the difference between the timestamp and your current time exceeds 300 seconds.
Recompute and compare
Compute sha256= + the hexadecimal HMAC-SHA256 of <timestamp>.<raw body>, with the whole secret as the key. Split the received header on spaces and accept if one of the values is equal, in constant time.
Respond quickly
Respond 2xx in under 10 seconds, then process the event. Respond 401 if the signature is invalid.
import express from 'express';
import crypto from 'node:crypto';
const app = express();
const SECRET = process.env.BOTELLO_WEBHOOK_SECRET; // "whsec_…", the whole string is the key
const TOLERANCE_SECONDS = 300;
function verifyBotello(rawBody, timestampHeader, signatureHeader) {
const timestamp = Number(timestampHeader);
if (!Number.isFinite(timestamp)) return false;
if (Math.abs(Date.now() / 1000 - timestamp) > TOLERANCE_SECONDS) return false;
const expected =
'sha256=' + crypto.createHmac('sha256', SECRET).update(`${timestamp}.${rawBody}`).digest('hex');
// During a rotation the header carries two signatures, space-separated.
return (signatureHeader ?? '').split(' ').some((given) => {
const a = Buffer.from(given);
const b = Buffer.from(expected);
return a.length === b.length && crypto.timingSafeEqual(a, b);
});
}
// express.raw keeps the exact bytes: do NOT use express.json() on this route.
app.post('/webhooks/botello', express.raw({ type: 'application/json' }), (req, res) => {
const rawBody = req.body.toString('utf8');
if (!verifyBotello(rawBody, req.get('X-Botello-Timestamp'), req.get('X-Botello-Signature'))) {
return res.status(401).send('invalid signature');
}
const event = JSON.parse(rawBody);
res.sendStatus(200);
// Process after answering; dedupe on event.id.
console.log('Botello event', event.type, event.id);
});
app.listen(3000);Verify the Standard Webhooks format
The HMAC key is not the secret as is: remove the whsec_ prefix, then base64-decode the rest. This is the rule of the Standard Webhooks specification, and the one Botello follows.
With the official library (Node.js)
The library applies these rules itself (prefix, decoding, 5-minute tolerance, multiple signatures).
import express from 'express';
import { Webhook } from 'standardwebhooks';
const app = express();
const wh = new Webhook(process.env.BOTELLO_WEBHOOK_SECRET); // "whsec_…"
app.post('/webhooks/botello', express.raw({ type: 'application/json' }), (req, res) => {
let event;
try {
event = wh.verify(req.body.toString('utf8'), req.headers); // throws if invalid
} catch {
return res.status(401).send('invalid signature');
}
res.sendStatus(200);
});Other languages have their own library: see standardwebhooks.com.
Without a library
import crypto from 'node:crypto';
// The key: the part after "whsec_", base64-decoded.
// Buffer.from(…, 'base64') also reads the URL-safe alphabet of older secrets.
function standardKey(secret) {
return Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
}
export function verifyStandard(secret, rawBody, headers) {
const id = headers['webhook-id'];
const timestamp = Number(headers['webhook-timestamp']);
const header = headers['webhook-signature'] ?? '';
if (!id || !Number.isFinite(timestamp)) return false;
if (Math.abs(Date.now() / 1000 - timestamp) > 300) return false;
const expected =
'v1,' + crypto.createHmac('sha256', standardKey(secret)).update(`${id}.${timestamp}.${rawBody}`).digest('base64');
return header.split(' ').some((given) => {
const a = Buffer.from(given);
const b = Buffer.from(expected);
return a.length === b.length && crypto.timingSafeEqual(a, b);
});
}Secret rotation
When you click Regenerate secret, Botello signs with the new secret and the old one for 24 hours. Each signature header then contains two values separated by a space, the new one first:
X-Botello-Timestamp: 1791364200
X-Botello-Signature: sha256=9f1c…(new secret) sha256=4ab2…(old secret)
webhook-signature: v1,Qm9…(new secret) v1,Zx7…(old secret)The code above already accepts both. Recommended procedure:
- Click Regenerate secret and copy the new secret.
- Replace the secret on your server and redeploy. In the meantime, the old secret keeps validating deliveries.
- Click Send a test event to check.
After a leak, use Revoke immediately instead: the old secret stops signing right away.
Test your code
- The sandbox receives your webhooks and shows a verdict: Valid signature, Valid (previous secret), Invalid signature, Not signed or Too old. It shows you what a correct receiver should conclude.
- For a unit test, sign a body yourself with a test secret and verify it with your function. Change one character of the body: verification must fail.
Troubleshooting
| What you see | Likely cause | Fix |
|---|---|---|
| Signature always invalid (Botello format) | The key used is the decoded part of the secret | For X-Botello-Signature, the key is the whole secret, including whsec_ |
| Signature always invalid (Standard Webhooks) | The key used is the secret as is | Remove whsec_, then base64-decode |
| Signature invalid on every delivery | The body was parsed and re-encoded | Use the raw body (express.raw, php://input, request.get_data()) |
| Signature invalid “now and then” | Clock drift or rotation in progress | Sync the time. Accept the delivery if one of the space-separated signatures is valid |
| The Standard Webhooks library rejects an old secret | Secrets created before v2 use the URL-safe base64 alphabet (- and _) | Regenerate the secret: new secrets use standard base64 |
| “Too old” in the sandbox | The request is more than 5 minutes old, or your tool is replaying it | Expected for a replayed request: reject it |