Receiving webhooks
Verify incoming monitoring event signatures and prevent duplicate processing. Webhook configuration is managed in your Labrika account.
On this page
Webhook notifications are configured in the dashboard. This section explains how to verify and process an incoming change monitoring event.
- The webhook is sent at the same time as the change monitoring alert email.
- Webhook management is not part of the Public API.
- The signature protects the body from tampering.
- A timestamp tolerance of ±5 minutes limits the replay window. Event deduplication is also required: a timestamp alone does not prevent a replay within that window.
HEADERX-Labrika-Webhook-ID
Delivery identifier for diagnostics and correlation. It does not by itself prove that the event is authentic.
HEADERX-Labrika-Webhook-Timestamp
Unix timestamp. Events older than 5 minutes should be rejected.
HEADERX-Labrika-Webhook-Signature
v1= + hex HMAC-SHA256 of {timestamp}.{raw_body}.
Payload
{
"event": "diff.alert.created",
"event_id": "EVENT_ID",
"created_at": "2026-05-31T12:30:00Z",
"diff_project_id": "PROJECT_ID",
"report_id": "REPORT_ID",
"url_md5": "URL_MD5",
"alert": {
"id": "ALERT_ID",
"name": "Price block",
"http_status": 404,
"available": false
}
}
Validating an incoming event
- Read the raw body bytes and the three X-Labrika-Webhook-* headers. Do not parse and serialize the body again before verifying the signature.
- Use the webhook secret to compute HMAC-SHA256 over timestamp.raw_body, and compare v1= plus the hex result with the received signature using a timing-safe comparison. Check the allowed clock difference in both directions.
- Parse JSON only after signature verification. Atomically store event_id from the signed body together with the processing job; a repeated event must not execute the action twice. Keep X-Labrika-Webhook-ID for diagnostics.
- Test the receiver with a valid event, a modified body, an invalid signature, an expired timestamp and a duplicate delivery.
The Labrika signature formula covers the timestamp and body. It does not cover the delivery-ID header, so that header alone cannot prove an event is authentic. Configure the destination and obtain the secret in the dashboard; this documentation does not define a webhook management API.
Python
import hashlib
import hmac
import json
import time
def verify_labrika_webhook(raw_body: bytes, headers, secret: bytes):
timestamp = headers["X-Labrika-Webhook-Timestamp"]
signature = headers["X-Labrika-Webhook-Signature"]
if abs(time.time() - int(timestamp)) > 300:
raise ValueError("Webhook timestamp is outside the allowed window")
signed = timestamp.encode("ascii") + b"." + raw_body
expected = "v1=" + hmac.new(secret, signed, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected, signature):
raise ValueError("Invalid webhook signature")
payload = json.loads(raw_body)
if not isinstance(payload, dict) or not isinstance(payload.get("event_id"), str) or not payload["event_id"]:
raise ValueError("Missing event_id")
return payload
