ValystrumHelp
Sign in

Check a webhook delivery's signature

Plans
Every plan
Where
Settings
Updated

Every webhook delivery is signed with HMAC-SHA256 under the signing secret you gave when you added the endpoint. Your endpoint should check the signature, and the time inside it, before it trusts the event.

What a delivery looks like

Valystrum sends a POST with a JSON body and these headers:

HeaderValue
Content-Typeapplication/json
X-Valystrum-EventThe event type, for example finding.created
X-Valystrum-Attempt1 for the first try, up to 5
X-Valystrum-Signature-256t=<unix seconds>,v1=<hex signature>

The signature is the hex HMAC-SHA256, under your signing secret, of the timestamp, a full stop, and the raw body: <t>.<body>. Each attempt is signed afresh, so a retry carries a new timestamp.

Check it

  1. Read the raw request body as bytes, before any JSON parsing changes it.
  2. Split X-Valystrum-Signature-256 into t and v1.
  3. Refuse the delivery if t is more than five minutes away from your clock.
  4. Compute HMAC-SHA256 of t + "." + body with your signing secret and compare it with v1 in constant time.
  5. Answer with a 2xx status only when both checks pass.

A Node.js example:

import { createHmac, timingSafeEqual } from "node:crypto";

export function verify(rawBody, header, secret, now = Date.now()) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const t = Number(parts.t);
  if (!Number.isFinite(t) || Math.abs(now / 1000 - t) > 300) return false;
  const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`, "utf8").digest("hex");
  const a = Buffer.from(expected, "hex");
  const b = Buffer.from(String(parts.v1 || ""), "hex");
  return a.length === b.length && timingSafeEqual(a, b);
}