SSolace PlatformDOCS
Open console →
Guides›Signatures

Signatures

Check that an event really came from Solace.

Verify every event

Solace-Signature is t=<unix seconds>,v1=<hex>, where v1 is the HMAC-SHA256 of "<t>.<raw body>" keyed with your signing secret (whsec_…, under Developers → Webhook endpoints). Recompute it over the body exactly as it arrived (before any JSON parsing), compare in constant time, and reject a timestamp more than a few minutes old so a captured event can't be replayed.

Node
import crypto from 'node:crypto';

// rawBody: the request body exactly as received, before JSON parsing.
export function verify(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = Object.fromEntries(
    header.split(',').map((p) => p.trim().split('=')),
  );
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
  const expected = crypto
    .createHmac('sha256', secret)
    .update(`${t}.${rawBody}`)
    .digest('hex');
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1 ?? '');
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}