Content Delivery · Webhooks
Signature
Every call is signed with a secret held only by you and us. Check it before trusting the body.
The header
X-Spectatr-Signature: t=1795155856,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd| Part | Meaning |
|---|---|
t | When we signed it, in Unix seconds. |
v1 | HMAC-SHA256 of {t}.{raw body} with the shared secret, as lowercase hex. |
Verifying
- 1Read the raw request body as bytes, before any JSON parsing. Re-serialised JSON will not match.
- 2Split the header into
tandv1. - 3Compute HMAC-SHA256 over
t, a., then the raw body, using the secret. - 4Compare the result with
v1in constant time. - 5Reject the call if
tis more than 300 seconds from your clock. This stops replays.
| Parameter | Value | Notes |
|---|---|---|
| Algorithm | HMAC-SHA256 | |
| Key | The shared secret | Used as the UTF-8 string we give you |
| Message | {t}.{raw body} | The raw bytes of the body |
| Output | Lowercase hex | 64 characters |
| Tolerance | 300 seconds | Between t and your clock |
A retry is signed again, so t and v1 change. The body stays the same.
Reference implementations
import hashlib, hmac, re, time
def verify(secret: str, raw_body: bytes, header: str, tolerance: int = 300) -> bool:
match = re.fullmatch(r"t=(\d+),v1=([0-9a-f]{64})", header or "")
if not match:
return False
timestamp, signature = int(match.group(1)), match.group(2)
if abs(time.time() - timestamp) > tolerance:
return False
expected = hmac.new(secret.encode(), f"{timestamp}.".encode() + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature)const crypto = require("crypto");
function verify(secret, rawBody, header, toleranceSeconds = 300) {
const match = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(header || "");
if (!match) return false;
const timestamp = Number(match[1]);
if (Math.abs(Date.now() / 1000 - timestamp) > toleranceSeconds) return false;
const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.`).update(rawBody).digest();
return crypto.timingSafeEqual(expected, Buffer.from(match[2], "hex"));
}