Verify a webhook signature
Before you act on a webhook, confirm that ZilloData sent it and that the body wasn’t changed on the way. Each delivery carries a header like this:
x-zd-signature: t=1793720528,v1=3b8f0c...e41aThe check works like this:
- Split the header into
t(Unix seconds) andv1(hex digest). - Reject the request if
tis more than 300 seconds from your clock. - Compute HMAC-SHA256 over the string
<t>.<raw body>, using your full webhook secret (including thewhsec_prefix) as the key. - Hex-encode the result and compare it to
v1with a constant-time comparison.
Each handler below reads the secret from ZILLODATA_WEBHOOK_SECRET, which is
the value returned once when you created the webhook.
Express (Node.js)
import express from "express";import { createHmac, timingSafeEqual } from "node:crypto";
const app = express();const secret = process.env.ZILLODATA_WEBHOOK_SECRET;
function verify(header, rawBody) { const match = /^t=(\d+),v1=([0-9a-f]+)$/.exec(header ?? ""); if (!match) return false; const [, t, received] = match; if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const expected = createHmac("sha256", secret) .update(`${t}.`) .update(rawBody) .digest("hex"); const a = Buffer.from(received); const b = Buffer.from(expected); return a.length === b.length && timingSafeEqual(a, b);}
// express.raw keeps the body as a Buffer, exactly as it was sent.app.post("/hooks/zillodata", express.raw({ type: "application/json" }), (req, res) => { if (!verify(req.get("x-zd-signature"), req.body)) { return res.status(401).send("invalid signature"); }
const event = JSON.parse(req.body.toString("utf8")); console.log(event.event, event.data.job.id, event.data.job.result_count);
// Hand the job ID to a queue, then answer right away. res.sendStatus(200);});
app.listen(3000);FastAPI (Python)
import hashlibimport hmacimport jsonimport osimport reimport time
from fastapi import FastAPI, HTTPException, Request
app = FastAPI()SECRET = os.environ["ZILLODATA_WEBHOOK_SECRET"].encode()SIG_RE = re.compile(r"t=(\d+),v1=([0-9a-f]+)")
def verify(header: str, raw_body: bytes) -> bool: match = SIG_RE.fullmatch(header or "") if not match: return False t, received = match.groups() if abs(time.time() - int(t)) > 300: return False expected = hmac.new(SECRET, t.encode() + b"." + raw_body, hashlib.sha256).hexdigest() return hmac.compare_digest(received, expected)
@app.post("/hooks/zillodata")async def zillodata_hook(request: Request): raw_body = await request.body() if not verify(request.headers.get("x-zd-signature", ""), raw_body): raise HTTPException(status_code=401, detail="invalid signature")
event = json.loads(raw_body) job = event["data"]["job"] # enqueue(job["id"]) and return quickly return {"received": event["event"], "job": job["id"]}Go (net/http)
package main
import ( "crypto/hmac" "crypto/sha256" "encoding/hex" "encoding/json" "io" "log" "net/http" "os" "strconv" "strings" "time")
var secret = []byte(os.Getenv("ZILLODATA_WEBHOOK_SECRET"))
func verify(header string, body []byte) bool { var t, received string for _, part := range strings.Split(header, ",") { if v, ok := strings.CutPrefix(part, "t="); ok { t = v } else if v, ok := strings.CutPrefix(part, "v1="); ok { received = v } } ts, err := strconv.ParseInt(t, 10, 64) if err != nil || received == "" { return false } if age := time.Now().Unix() - ts; age > 300 || age < -300 { return false } mac := hmac.New(sha256.New, secret) mac.Write([]byte(t + ".")) mac.Write(body) expected := hex.EncodeToString(mac.Sum(nil)) return hmac.Equal([]byte(received), []byte(expected))}
func hook(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(io.LimitReader(r.Body, 1<<20)) if err != nil || !verify(r.Header.Get("x-zd-signature"), body) { http.Error(w, "invalid signature", http.StatusUnauthorized) return }
var event struct { Event string `json:"event"` Data struct { Job struct { ID string `json:"id"` Status string `json:"status"` } `json:"job"` } `json:"data"` } if err := json.Unmarshal(body, &event); err != nil { http.Error(w, "bad payload", http.StatusBadRequest) return } log.Printf("%s for job %s", event.Event, event.Data.Job.ID) w.WriteHeader(http.StatusOK)}
func main() { http.HandleFunc("/hooks/zillodata", hook) log.Fatal(http.ListenAndServe(":3000", nil))}Testing your handler
You can sign a sample payload yourself to check the handler before a real job finishes:
SECRET="$ZILLODATA_WEBHOOK_SECRET"BODY='{"event":"job.succeeded","delivered_at":"2026-11-03T15:42:08.117Z","data":{"job":{"id":"3f6c1b2e-8d4a-4e7b-9a10-5c2d7e8f9b01","type":"batch_detail","status":"succeeded","result_count":3}}}'T=$(date +%s)SIG=$(printf '%s.%s' "$T" "$BODY" | openssl dgst -sha256 -hmac "$SECRET" -hex | sed 's/^.* //')
curl -i http://localhost:3000/hooks/zillodata \ -H "Content-Type: application/json" \ -H "x-zd-event: job.succeeded" \ -H "x-zd-signature: t=$T,v1=$SIG" \ --data-raw "$BODY"A 200 means the check passed. Change one character in BODY after signing
and you should get a 401.
Mistakes that break verification
- Hashing parsed JSON. Re-serializing the body can change spacing or key
order, and the digest won’t match. Always hash the raw bytes you received.
In Express that means
express.raw()on this route, notexpress.json(). - Dropping the secret’s prefix. The key is the entire secret string,
whsec_included. - Skipping the timestamp check. Without it, a captured request could be replayed later and still pass.
- Comparing with
==. UsetimingSafeEqual,hmac.compare_digest, orhmac.Equal. In Node, check that the two buffers are the same length first, becausetimingSafeEqualthrows when they differ. - Caching the timestamp from the first attempt. Retries are signed again
with a new
t, so verify every delivery on its own.