Verifying Webhook Signatures
API version
How signing works
Anyone who knows your endpoint URL could send it a request that looks like a BeeForm event. To tell the real ones apart, BeeForm signs every request with the endpoint’s signing secret, which only you and BeeForm know. Your server repeats the calculation and compares the result.
The signature is an HMAC with SHA-256 over the timestamp, a dot and the exact request body, keyed with the whole secret including its whsec_ prefix. It is sent as v1= followed by the result in lowercase hex.
signature = "v1=" + hex( HMAC_SHA256( secret, timestamp + "." + raw_body ) )Verify step by step
- Read the raw request body as bytes, before any JSON parsing. Re-encoding parsed JSON changes the bytes and breaks the signature.
- Read
X-BeeForm-TimestampandX-BeeForm-Signature. - Reject the request if the timestamp is more than five minutes from your clock. This stops someone replaying a request they captured.
- Compute the signature of
timestamp + "." + bodywith your secret. - Compare it with the header using a constant-time comparison. Reject the request with a
401if they differ. - Only now parse the JSON and handle the event. Use the event’s
idto skip one you have already processed.
Code samples
Each sample is a complete endpoint. Set BEEFORM_WEBHOOK_SECRET to the secret you copied when you added the endpoint.
import crypto from "node:crypto";
import express from "express";
const app = express();
const SECRET = process.env.BEEFORM_WEBHOOK_SECRET; // the whole whsec_... value
// Read the body as raw bytes: the signature covers exactly what BeeForm sent.
app.post("/webhooks/beeform", express.raw({ type: "application/json" }), (req, res) => {
const timestamp = req.get("X-BeeForm-Timestamp") ?? "";
const signature = req.get("X-BeeForm-Signature") ?? "";
// Reject old requests so a captured one cannot be replayed later.
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) {
return res.sendStatus(400);
}
const expected =
"v1=" +
crypto
.createHmac("sha256", SECRET)
.update(`${timestamp}.`)
.update(req.body)
.digest("hex");
const valid =
signature.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
if (!valid) return res.sendStatus(401);
const event = JSON.parse(req.body.toString("utf8"));
// Use event.id to skip an event you have already handled.
console.log(event.event, event.data);
res.sendStatus(200);
});
app.listen(3000);Test your code
Use this example to check your implementation without a live request. With the values below, your code should produce exactly this signature.
| Input | Value |
|---|---|
| Secret | whsec_test_secret |
| Timestamp | 1700000000 |
| Raw body | {"hello":"world"} |
| Signature | v1=86748dbec9cc87a9219f8a96632da703271bf5e85aa0afa2b310c37ba059d514 |
You can also click Send test event on the endpoint in the dashboard. The Events tab shows your server’s answer, so a 401 there means the check failed.
Rolling the secret
If a secret leaks, click Roll secret on the endpoint. BeeForm gives you a new secret, and the old one stops working at once. Events sent while your server still uses the old secret fail the check, so update your server straight away. BeeForm retries them, so nothing is lost if you are quick.
Common mistakes
- Parsing the body first. Frameworks that parse JSON for you often give you a re-encoded copy. Use the raw body.
- Leaving off the prefix. The key is the whole
whsec_…string, not just the part after the underscore. - Comparing with
==. Use the constant-time comparison your language provides. - A proxy changing the body. Anything that rewrites or compresses the body before your code sees it breaks the signature.