Skip to Content
API reference · Webhooks

Verify signatures

Check the Altruon-Signature header on every webhook with HMAC-SHA256 and the signing secret of the endpoint. Algorithm and code.

Altruon signs every webhook delivery with the signing secret of the endpoint, the whsec_... value shown once when you create the endpoint. Verify the signature before you trust a payload.

The Altruon-Signature header

Altruon-Signature: t=1752498420,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
tinteger

Unix timestamp, in seconds, of when the delivery was signed.

v1string

Hex-encoded HMAC-SHA256 of the string {t}.{raw request body}, keyed with the signing secret of the endpoint.

While a secret rotation overlaps, the header can contain two v1 entries. The signature is valid if any of them matches.

Verify a delivery

  1. Parse t and every v1 value from the header.
  2. Reject the request if t is more than 5 minutes (300 seconds) away from the current time. This protects against replays.
  3. Compute HMAC-SHA256(secret, "{t}." + rawBody) over the raw request body, before any JSON parsing.
  4. Compare your hex digest with each v1 value, using a constant-time comparison.
  5. If none matches, respond with 400 and stop. If one matches, respond with a 2xx and process the event.

Code samples

server.js
const crypto = require('crypto');
const express = require('express');

const app = express();
const TOLERANCE_SECONDS = 300;

function verifyAltruonSignature(rawBody, signatureHeader, secret) {
  const elements = (signatureHeader || '').split(',');
  const timestamp = elements.find((e) => e.startsWith('t='))?.slice(2);
  const signatures = elements.filter((e) => e.startsWith('v1=')).map((e) => e.slice(3));

  if (!timestamp || signatures.length === 0) return false;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > TOLERANCE_SECONDS) return false;

  const expected = crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`)
    .digest('hex');

  return signatures.some((sig) => {
    try {
      return crypto.timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(sig, 'hex'));
    } catch {
      return false;
    }
  });
}

// express.raw keeps the body as received. Do not use express.json on this route.
app.post('/webhooks/altruon', express.raw({ type: 'application/json' }), (req, res) => { 
  const rawBody = req.body.toString('utf8');
  const valid = verifyAltruonSignature(
    rawBody,
    req.headers['altruon-signature'],
    process.env.ALTRUON_WEBHOOK_SECRET,
  );

  if (!valid) return res.status(400).send('Invalid signature');

  const event = JSON.parse(rawBody);
  // Queue the event for processing. Deduplicate on event.id.
  res.sendStatus(200);
});

Test your verification

Open the endpoint under Settings > Webhooks and click Send Test. Altruon sends a signed webhook.ping, so you can check your code end to end.

The test ping sent by Send test event while you create an endpoint is unsigned, because the endpoint has no secret yet. Do not use it to test verification.

Common mistakes

MistakeWhat happensFix
Hashing the parsed JSON instead of the raw bodyParsing and serialising again changes the bytes, so the digest never matchesRead the raw request body and verify before you parse it
Using the secret of another endpointEach endpoint has its own whsec_... secretUse the secret of the endpoint that receives the delivery
Checking only the first v1 valueDeliveries fail during a secret rotationAccept the delivery if any v1 matches
Skipping the timestamp checkAn old delivery can be replayedReject when t is more than 5 minutes from the current time
Comparing digests with ==The comparison leaks timing informationUse a constant-time comparison such as crypto.timingSafeEqual or hmac.compare_digest
Verifying the unsigned test ping from the create flowIt has no valid signatureTest with Send Test on the endpoint detail page