Verifying signatures
Every webhook NuacemOne sends, workflow events and transcript deliveries alike, is signed the same way. Check the signature before you trust the body.
The scheme
Section titled “The scheme”Each request has two headers:
| Header | Value |
|---|---|
X-VoiceCX-Timestamp |
The Unix time in seconds when the request was signed, for example 1763889302. |
X-VoiceCX-Signature |
v1= followed by 64 lower-case hex characters. |
The signature is:
v1= hex( HMAC-SHA256( key = signing secret, message = "<timestamp>." + raw body bytes ) )To verify:
- Take the raw request body, exactly as received. Do not parse and re-serialise it.
- Build
"<timestamp>."from the timestamp header, and append the raw body. - Compute the HMAC-SHA256 with your signing secret, as lower-case hex, and prefix
v1=. - Compare it with the header using a constant-time comparison. The header may hold more than one comma-separated signature; accept the request if any
v1=value matches. - Reject the request if the timestamp is more than 5 minutes from your clock. This stops an old, captured request from being replayed.
The same scheme, with your workspace’s inbound secret, signs requests you send to a signed workflow hook.
const crypto = require('node:crypto');
function verifySignature(secret, rawBody, timestamp, signatureHeader, toleranceSeconds = 300) { const ts = Number.parseInt(timestamp, 10); if (!Number.isFinite(ts) || Math.abs(Date.now() / 1000 - ts) > toleranceSeconds) return false; const expected = Buffer.from( 'v1=' + crypto.createHmac('sha256', secret).update(`${ts}.`).update(rawBody).digest('hex'), ); return String(signatureHeader || '').split(',').some((part) => { const given = Buffer.from(part.trim()); return given.length === expected.length && crypto.timingSafeEqual(given, expected); });}With Express, use express.raw() so req.body is the exact bytes that were signed:
const express = require('express');const app = express();
app.post('/webhooks/nuacemone', express.raw({ type: 'application/json' }), (req, res) => { const ok = verifySignature(process.env.NUACEMONE_WEBHOOK_SECRET, req.body, req.get('X-VoiceCX-Timestamp'), req.get('X-VoiceCX-Signature')); if (!ok) return res.sendStatus(401); const event = JSON.parse(req.body.toString('utf8')); queue.add(event); // do the work later res.sendStatus(204); // answer quickly});import hashlibimport hmacimport time
def verify_signature(secret: str, raw_body: bytes, timestamp: str, signature_header: str, tolerance_seconds: int = 300) -> bool: try: ts = int(timestamp) except (TypeError, ValueError): return False if abs(time.time() - ts) > tolerance_seconds: return False expected = "v1=" + hmac.new(secret.encode(), f"{ts}.".encode() + raw_body, hashlib.sha256).hexdigest() return any(hmac.compare_digest(expected, part.strip()) for part in (signature_header or "").split(","))With FastAPI, read the raw body with await request.body():
import jsonimport os
from fastapi import FastAPI, Request, Response
app = FastAPI()
@app.post("/webhooks/nuacemone")async def nuacemone_webhook(request: Request) -> Response: raw = await request.body() if not verify_signature(os.environ["NUACEMONE_WEBHOOK_SECRET"], raw, request.headers.get("X-VoiceCX-Timestamp", ""), request.headers.get("X-VoiceCX-Signature", "")): return Response(status_code=401) event = json.loads(raw) await queue.put(event) # do the work later return Response(status_code=204)The SDKs have the same check built in: NuacemOne.webhooks.verify(secret, rawBody, timestamp, signature) in Node and verify_webhook(secret, raw_body, timestamp, signature) in Python.
Common mistakes
Section titled “Common mistakes”- Verifying parsed JSON. Frameworks that parse JSON first lose the exact bytes. Read the raw body.
- Wrong secret. Each workflow webhook endpoint and each transcript webhook destination has its own secret. Agents’ Transcript Webhooks use the workspace’s agent webhook secret.
- Plain string comparison. Use
crypto.timingSafeEqualorhmac.compare_digest. - Server clock drift. Keep your clock in sync (NTP), or valid requests will fail the 5-minute check.
After verifying
Section titled “After verifying”- Answer
2xxquickly, within a few seconds. Queue the work. - Deduplicate: workflow events on
X-VoiceCX-Event-Id, transcripts onX-VoiceCX-Delivery. Retries resend the same id with a new timestamp and signature. - Retries follow a fixed schedule: see workflow event retries and transcript delivery retries.