Verifying Flowda webhook signatures
The exact HMAC construction for X-Watch-Signature, a fixed test vector, and the retry rules your receiver has to survive.
A watch job with a webhook_url delivers one event when a page changes: watch.change_detected. Every delivery is signed with the webhook_secret returned when the callback URL was registered, and the signature is the only thing that distinguishes a real event from anyone who learned your endpoint.
This post is the short version of Webhooks: how the digest is built, how to verify it with the bytes you actually received, and what the retry policy demands of your handler.
The header
X-Watch-Signature: t=1793234266,v1=06f172a6db59be1f62a69db93093142030d79fec915cb025d7704e98c34b497d
t is the unix timestamp in seconds, v1 the lowercase hex digest. The digest is:
HMAC-SHA256(secret, timestamp + "." + raw_request_body)
The dot is literal. The body is the raw bytes that arrived, not a re-serialized object. Our relay re-serializes each event before sending it, so key order is not what the upstream platform produced — verify first, parse afterwards.
Verify with the bytes you received
Python:
import hashlib
import hmac
def verify(secret: str, header: str, raw_body: bytes) -> bool:
parts = dict(piece.split("=", 1) for piece in header.split(","))
timestamp, digest = parts.get("t"), parts.get("v1")
if not timestamp or not digest:
return False
expected = hmac.new(
secret.encode(), f"{timestamp}.".encode() + raw_body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, digest)
Node.js:
import crypto from 'node:crypto';
export function verifySignature(secret, header, rawBody) {
const parts = Object.fromEntries(
header.split(',').map((piece) => {
const index = piece.indexOf('=');
return [piece.slice(0, index), piece.slice(index + 1)];
}),
);
const timestamp = parts.t;
const digest = parts.v1;
if (!timestamp || !digest) return false;
const expected = crypto
.createHmac('sha256', secret)
.update(Buffer.concat([Buffer.from(`${timestamp}.`), rawBody]))
.digest('hex');
const left = Buffer.from(expected);
const right = Buffer.from(digest);
return left.length === right.length && crypto.timingSafeEqual(left, right);
}
Two details that break naive implementations: read the raw body before any JSON middleware rewrites it, and compare in constant time.
Check your verifier against this tuple
These four values are a known-answer pair. If your function returns true for them, the algorithm and encoding are right:
secret whsec_EXAMPLEsecret
t 1793234266
body {"event":"watch.change_detected","delivered_at":1793234266,"data":{"job":{"job_id":"job_example000000000000","url":"https://www.example.com/pricing","status":"active"},"check":{"check_id":"chk_example000000000000","changed":true}}}
X-Watch-Signature t=1793234266,v1=06f172a6db59be1f62a69db93093142030d79fec915cb025d7704e98c34b497d
Reject a signature whose t is more than five minutes from your clock. That bounds replay of a captured request.
What the retry policy assumes about you
- Answer
2xxas soon as you have accepted the event, then do the slow work asynchronously. - A non-
2xxanswer is retried: 6 attempts in total, waiting 10s, 1m, 5m, 30m, then 2h. 4xxanswers other than408,425, and429stop the retries immediately.Retry-Afteris honoured up to 10 minutes.- A retry can arrive for an event you already handled. Compare
X-Flowda-Event-Idbefore doing the work; it is stable for the same job, check, and event.
The secret is returned once
When you register a new webhook_url, the response carries data.data.webhook_secret. Store it immediately — it is not returned again, GET /v1/watch/jobs/{id} never includes it, and there is no rotation endpoint. To rotate, register a different callback URL (for example a new path) and update the job to point at it. Reusing a URL that was registered before never returns its secret again.
Only changes are delivered
A check that finds no change sends nothing, and a job without webhook_url sends nothing at all. The event body's data.diff.hunks[].path tells you where the change is — a CSS/XPath selector, a JSON pointer, or a line marker such as L683 — while data.diff.unified_diff carries the diff itself, possibly truncated.
data.job and data.check in the event are subsets of what the job endpoints return. For the full check record, call GET /v1/watch/jobs/{id}/checks/{check_id}. The complete schema is WatchEvent in the OpenAPI document.