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=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bdtintegerUnix timestamp, in seconds, of when the delivery was signed.
v1stringHex-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
- Parse
tand everyv1value from the header. - Reject the request if
tis more than 5 minutes (300 seconds) away from the current time. This protects against replays. - Compute
HMAC-SHA256(secret, "{t}." + rawBody)over the raw request body, before any JSON parsing. - Compare your hex digest with each
v1value, using a constant-time comparison. - If none matches, respond with
400and stop. If one matches, respond with a2xxand process the event.
Code samples
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
| Mistake | What happens | Fix |
|---|---|---|
| Hashing the parsed JSON instead of the raw body | Parsing and serialising again changes the bytes, so the digest never matches | Read the raw request body and verify before you parse it |
| Using the secret of another endpoint | Each endpoint has its own whsec_... secret | Use the secret of the endpoint that receives the delivery |
Checking only the first v1 value | Deliveries fail during a secret rotation | Accept the delivery if any v1 matches |
| Skipping the timestamp check | An old delivery can be replayed | Reject when t is more than 5 minutes from the current time |
Comparing digests with == | The comparison leaks timing information | Use a constant-time comparison such as crypto.timingSafeEqual or hmac.compare_digest |
| Verifying the unsigned test ping from the create flow | It has no valid signature | Test with Send Test on the endpoint detail page |