- Where
- Your webhook receiver
- Who can do it
- Developers
- Plans
- Webhooks is included in Growth, Scale and Enterprise
In detail
Anyone who learns your endpoint's address can post to it. The signature is what tells a real event from a forged or replayed one, so check it on every request before you act on the body.
The header
The header looks like X-YallaRoute-Signature: t=1764670000000,v1=5f2b.... t is the time of signing in milliseconds since 1970 (Unix time in milliseconds). v1 is the hexadecimal HMAC-SHA256 of the text t, a full stop, and the raw body, keyed with the signing secret of the endpoint.
Step by step
- Read the body exactly as it arrived, as text or bytes, before any JSON parsing. Parsing and re-encoding changes the bytes and breaks the check.
- Split the header on the comma into t and v1.
- Compute the HMAC-SHA256 of t, a full stop and the raw body, with your signing secret as the key, as hexadecimal.
- Compare it with v1 using a constant-time comparison.
- Reject the request if they differ, or if t is more than five minutes away from your clock.
- Only then parse the JSON and act on it.
import { createHmac, timingSafeEqual } from "node:crypto";
// rawBody: the request body exactly as received, before JSON parsing
export function verify(rawBody, header, secret, toleranceMs = 5 * 60 * 1000) {
const parts = Object.fromEntries(
String(header ?? "").split(",").map((p) => p.trim().split("=")),
);
const t = Number(parts.t);
if (!Number.isFinite(t) || !parts.v1) return false;
if (Math.abs(Date.now() - t) > toleranceMs) return false;
const expected = createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
const a = Buffer.from(expected, "hex");
const b = Buffer.from(parts.v1, "hex");
return a.length === b.length && timingSafeEqual(a, b);
}import hashlib, hmac, time
def verify(raw_body: bytes, header: str, secret: str, tolerance_ms: int = 300_000) -> bool:
parts = dict(p.strip().split("=", 1) for p in header.split(",") if "=" in p)
t, v1 = parts.get("t"), parts.get("v1")
if not t or not v1 or not t.isdigit():
return False
if abs(time.time() * 1000 - int(t)) > tolerance_ms:
return False
signed = t.encode() + b"." + raw_body
expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, v1)Replacing the secret
Choose Replace signing secret on the endpoint's menu. A new secret is made and the old one stops signing at once, so put the new secret on your server first, or accept both for the few minutes it takes to deploy. Showing the current secret again is possible for owners and is recorded in the audit log.