API reference Webhooks
Verify webhook signatures
Check the Pipory-Signature header on every Pipory webhook delivery with an HMAC-SHA256 of the timestamp and the raw body.
Every delivery is signed with your endpoint's signing secret (whsec_...), so you can reject requests that did not come from Pipory and replays of old ones.
The header
Pipory-Signature: t=1762783391,v1=5f2b8c...e91a
tis the Unix time in seconds when the attempt was signed. It is also sent asPipory-Timestamp.v1is the hex HMAC-SHA256, keyed with your signing secret, of the string<t>.<raw request body>.- For 24 hours after you rotate the secret, the header carries two
v1=values: one signed with the new secret, one with the old. Accept the delivery if anyv1matches.
How to verify
- Read the raw request body as bytes, before any JSON parsing. Re-serialising the JSON changes the bytes and breaks the signature.
- Split the header on
,, then each part on the first=. Taketand everyv1. - Reject the request if
tis more than 5 minutes from your clock. - Compute the HMAC-SHA256 of
t, a dot, and the raw body, with your signing secret as the key, as lowercase hex. - Compare it with each
v1in constant time. Accept if one matches. - Answer
2xxquickly, then do the work. Deliveries time out after 10 seconds.
Node.js
import crypto from "node:crypto";
function verify(rawBody, header, secret, toleranceSec = 300) {
const items = header.split(",").map((p) => p.split("="));
const t = items.find(([k]) => k === "t")?.[1];
const sigs = items.filter(([k]) => k === "v1").map(([, v]) => v);
if (!t || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSec) return false;
const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
return sigs.some((s) => s.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected)));
}
With Express, read the raw body for the webhook route only:
import express from "express";
const app = express();
app.post("/pipory-webhook", express.raw({ type: "application/json" }), (req, res) => {
const ok = verify(req.body.toString("utf8"), req.get("Pipory-Signature") || "", process.env.PIPORY_WEBHOOK_SECRET);
if (!ok) return res.status(400).end();
const event = JSON.parse(req.body.toString("utf8"));
// Use event.id to skip events you have already handled.
res.status(200).end();
});
Python
import hashlib
import hmac
import time
def verify(secret: str, header: str, body: bytes, tolerance: int = 300) -> bool:
items = [p.split("=", 1) for p in header.split(",") if "=" in p]
ts = next((v for k, v in items if k == "t"), None)
sigs = [v for k, v in items if k == "v1"]
if ts is None or not sigs or abs(time.time() - int(ts)) > tolerance:
return False
msg = f"{ts}.".encode() + body
expected = hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest()
return any(hmac.compare_digest(expected, s) for s in sigs)
This is the same check Pipory's own test suite uses. In Flask, pass request.get_data() as body; in FastAPI, await request.body().
Duplicates and order
A retry repeats the same event id, and two endpoints subscribed to the same event receive the same id. Store the ids you have handled and skip repeats. Deliveries are not guaranteed to arrive in the order the events happened; use created_at when order matters.