Skip to content

Verify signatures

Anyone can send a request to your endpoint. The Supportaka-Signature header proves a delivery came from Supportaka and wasn’t changed on the way:

Supportaka-Signature: t=1795681200,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
  • t is when it was signed (Unix seconds).
  • v1 is the hex HMAC-SHA256 of "<t>.<raw body>", keyed with your endpoint’s secret (whsec_…).
  • Right after you rotate the secret there are two v1 values, one per secret. Accept the delivery if any of them matches.
  1. Read the raw request body, exactly as received. Don’t parse it and re-serialise it first: any change in spacing breaks the signature.
  2. Split the header on , and take t and every v1.
  3. Compute HMAC-SHA256(secret, t + "." + rawBody) as lowercase hex.
  4. Compare it with each v1 using a constant-time comparison.
  5. Check t is recent (within 5 minutes) to stop old deliveries being replayed at you.
import crypto from 'node:crypto';
import express from 'express';
const secret = process.env.SUPPORTAKA_WEBHOOK_SECRET;
function verify(rawBody, header, toleranceSeconds = 300) {
const parts = Object.groupBy(header.split(','), (p) => p.split('=')[0]);
const t = parts.t?.[0]?.slice(2);
const signatures = (parts.v1 ?? []).map((p) => p.slice(3));
if (!t || !signatures.length) return false;
if (Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;
const expected = crypto.createHmac('sha256', secret).update(`${t}.`).update(rawBody).digest('hex');
return signatures.some(
(s) => s.length === expected.length && crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected)),
);
}
const app = express();
// Keep the raw body for this route.
app.post('/webhooks/supportaka', express.raw({ type: 'application/json' }), (req, res) => {
if (!verify(req.body, req.get('Supportaka-Signature') ?? '')) return res.status(400).send('bad signature');
const event = JSON.parse(req.body);
res.sendStatus(200); // answer first…
handle(event).catch(console.error); // …then do the work (better: put it on a queue)
});
  • Using the parsed body. Frameworks often parse JSON before your code runs. Use the raw bytes (express.raw, request.get_data(), php://input).
  • Wrong secret. Each endpoint has its own secret, and rotating it shows a new one. Check you deployed the right one.
  • Clock skew. If your server’s clock is off by minutes, the time check fails. Keep it synced (NTP).