Skip to content
ClearReadout

Verify a delivery

Confirm a delivery came from us before you trust it.

On the Agency plan

Your signing secret

Check the signature

Check svix-signature before you trust a delivery. Svix's own library does it in one call (pip install svix).

Python
from svix.webhooks import Webhook, WebhookVerificationError

def is_from_clearreadout(body: bytes, headers: dict, secret: str) -> bool:
    try:
        Webhook(secret).verify(body, headers)
        return True
    except WebhookVerificationError:
        return False

Or check it by hand

  1. Read the headerssvix-id, svix-timestamp, and each v1, value in svix-signature.
  2. Sign it yourselfHMAC-SHA256 of the id, a dot, the timestamp, a dot and the raw body, with your secret after whsec_, base64-decoded.
  3. CompareOne v1 must match your base64 result, and the timestamp must be under five minutes old.
Python
import base64, hashlib, hmac, time

def is_from_clearreadout(body: bytes, headers: dict, secret: str) -> bool:
    headers = {k.lower(): v for k, v in headers.items()}
    try:
        msg_id, stamp = headers["svix-id"], headers["svix-timestamp"]
        key = base64.b64decode(secret.removeprefix("whsec_"))
        signed = f"{msg_id}.{stamp}.".encode() + body
        expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
        sent = [s.split(",", 1)[1] for s in headers["svix-signature"].split() if s.startswith("v1,")]
        return any(hmac.compare_digest(expected, s) for s in sent) and abs(time.time() - int(stamp)) < 300
    except (KeyError, ValueError):
        return False