Paid Plans4 min read· Updated 2026-11-18
Verify Webhook HMAC Signatures
Securely verify Omni Chat Stack X-OmniChat-Signature HMAC-SHA256 headers on incoming webhook deliveries using timing-safe comparison.
Signature verification handlers
Use constant-time comparison
Never compare signatures with === or ==. Always use crypto.timingSafeEqual (Node.js) or hmac.compare_digest (Python) to prevent timing side-channel attacks.
Verify X-OmniChat-Signature
const crypto = require('crypto');
const express = require('express');
const app = express();
app.post('/webhooks/omnichat', express.raw({ type: 'application/json' }), (req, res) => {
const secret = process.env.OMNICHAT_WEBHOOK_SECRET;
const headerSig = req.header('X-OmniChat-Signature') || '';
const expected = 'sha256=' + crypto
.createHmac('sha256', secret)
.update(req.body)
.digest('hex');
const valid =
headerSig.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(headerSig), Buffer.from(expected));
if (!valid) return res.status(401).send('Invalid signature');
const event = JSON.parse(req.body.toString('utf8'));
// Process event asynchronously after 200 ACK
res.status(200).json({ received: true });
});