Verify the signature
Prove that a webhook request really came from dCal: recompute the HMAC-SHA256 of the raw body with your signing secret and compare it with the X-Slate-Signature header in constant time. Node.js and Py
Every delivery dCal sends carries an X-Slate-Signature header. Your endpoint recomputes that signature with the webhook's signing secret and rejects any request that does not match. This page shows how the signature is built and gives you code to copy for Node.js and Python.
No screenshots here: everything happens on your server.
How the signature is built
Algorithm
HMAC-SHA256
Key
The webhook's whole signing secret, including the whsec_ at the start
Message
The raw request body, byte for byte, exactly as received
Header
X-Slate-Signature
Format
sha256= followed by the lowercase hex digest
Example header:
X-Slate-Signature: sha256=9f2b6c1d3e4a5b6c7d8e9f0a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4eTwo things matter when you verify:
Use the raw body. Compute the HMAC over the bytes you received, before any JSON parsing. A framework that parses and re-serializes JSON can change spacing or key order, and the digest no longer matches. Read the raw body, verify it, then parse it.
Compare in constant time. Use your language's timing-safe comparison (
crypto.timingSafeEqualin Node.js,hmac.compare_digestin Python) instead of==, so nobody can guess the signature one character at a time.
Node.js (Express)
const crypto = require("node:crypto");
const express = require("express");
const app = express();
const SECRET = process.env.DCAL_WEBHOOK_SECRET; // the whsec_ signing secret, as dCal showed it
// Keep the body raw: verify BEFORE parsing the JSON.
app.post("/webhooks/dcal", express.raw({ type: "application/json" }), (req, res) => {
const received = req.get("X-Slate-Signature") || "";
const expected =
"sha256=" + crypto.createHmac("sha256", SECRET).update(req.body).digest("hex");
const a = Buffer.from(received);
const b = Buffer.from(expected);
const valid = a.length === b.length && crypto.timingSafeEqual(a, b);
if (!valid) return res.status(401).send("invalid signature");
const message = JSON.parse(req.body.toString("utf8"));
// message.event is "booking.created", "booking.rescheduled", "booking.cancelled" or "ping"
console.log(message.event, message.data);
res.status(200).send("ok"); // any 2xx tells dCal the delivery landed
});
app.listen(3000);Python (Flask)
Test it with Ping
You do not need a real booking to try your code. On API and webhooks > Webhooks, click Ping on the webhook's row. The test message is signed with the same secret and the same scheme as a real delivery, so a verifier that accepts the ping accepts real events too. If the row then reads Failed, your endpoint answered with something other than a 2xx status: check whether your verifier rejected it.
Good practices
Keep the secret on your server only. Store it as a setting or a secret of your app, never in code you publish or in a browser.
Skip repeats. The signature proves who sent a request, but it carries no timestamp, so it does not tell you when. A delivery can also arrive more than once: every attempt of one delivery carries the same
X-Slate-Deliveryheader, so keep the IDs you already handled and ignore a second copy.Change the secret without losing events. dCal never shows a secret again and cannot rotate one. Add a second webhook for the same URL, let your endpoint accept both secrets for a while, then delete the old webhook and keep only the new secret.
โ ๏ธ Note: Answering
401, or any other status that is not 2xx, counts as a failed delivery and dCal keeps trying for up to 24 hours. When you change secrets, update your server first, so real deliveries are not rejected while you switch.
Related
Webhooks: add a webhook and copy its signing secret.
Payload reference: every field and header.
Security and privacy: how dCal stores secrets.
Last updated