Skip to main content

Webhook security

How to verify incoming webhook payloads, rotate signing secrets, stay within URL rules, and handle retries safely.

The signature header​

Signatures are off by default (signature_enabled: false). When enabled and a secret exists, DeePsy signs every delivery and sends:

  • Header: X-Webhook-Signature: sha256=<hex>
  • Algorithm: HMAC-SHA256 keyed with your whsec_ secret
  • Signed input: the exact raw UTF-8 JSON request body (unescaped slashes and non-ASCII characters)

Always verify against the raw body bytes before parsing JSON (re-serializing changes escaping and breaks the signature), and use a constant-time comparison:

// Node.js
const expected = 'sha256=' +
crypto.createHmac('sha256', secret).update(rawBody, 'utf8').digest('hex');

const ok = crypto.timingSafeEqual(
Buffer.from(expected),
Buffer.from(req.get('x-webhook-signature') ?? '')
);

Try it locally​

Signature playground

Computes HMAC-SHA256 locally in your browser using Web Crypto. Nothing is sent anywhere.

X-Webhook-Signature (from raw bytes)
Computing...
MismatchThe header does not match the HMAC computed from this secret and raw body.

Enabling & rotating secrets​

  • At creation: pass "signature_enabled": true to POST /webhooks. Copy secret (whsec_...) from the 201 response, because you won't see it again.
  • On an existing webhook: PUT /webhooks/{webhook_id} lets you toggle signature_enabled, but doesn't generate a secret. Call POST /webhooks/{webhook_id}/regenerate-secret to issue a new whsec_ secret and turn signatures on:
curl -X POST "https://deepsy.fr/api/v1/webhooks/{webhook_id}/regenerate-secret" \
-H "Authorization: Bearer deepsy-dev-your-api-key-here"
{ "secret": "whsec_abcd1234..." }

Suspended webhooks can't regenerate secrets (400). Set status back to active first.

No overlap on rotation

Regenerating a secret invalidates the old one immediately. Update your receiver to accept the new secret as soon as you rotate (or swap it during a brief maintenance window).

Keep whsec_ in a secret manager or env var, never commit it, and don't log raw secrets or signature headers.

URL & transport rules​

  • URLs must use https:// (max 500 chars on create) and resolve to a public IP address.
  • At delivery time, DeePsy resolves your hostname and blocks private, loopback, and reserved IP ranges (this is what triggers 403 URL blocked on POST /webhooks/{webhook_id}/test).
  • Connect timeout is 10s, overall timeout is 30s, and redirects are not followed (3xx counts as failed).

Permissions & ownership​

OperationsWho can call it
POST /webhooksAPI key with ADMINISTRATOR on every company in company_ids
/companies/{company_id}/webhooks*API key with ADMINISTRATOR on {company_id}
/webhooks/list, /webhooks/events, /webhooks/{webhook_id}*, /webhooks/logs*Owning API key

Remember the difference between revoke and deny: revoke pauses a company (authorized: false) so it can be re-authorized later; deny removes the company and deletes the webhook if no authorized company is left. All actions are attributed to the API key's creator (Authentication).

Retries & idempotency​

Because automatic retries and manual replays can send the same event more than once, make your receiver idempotent using X-Webhook-Delivery (or delivery_id in the JSON body) as your deduplication key. Retries and manual replays reuse it.

  • Automatic retries: run up to max_retries (0–5, default 0) only on transient errors: network failures, 408, 425, 429, or 5xx. Other 4xx responses fail immediately. Backoff is 2, 4, 8, 16, then 32 minutes.
  • Manual replay (POST /webhooks/logs/{log_id}/retry): replays any non-success log synchronously without checking max_retries, resets retry_count to 0, and clears next_retry_at.
  • Your endpoint's response body is stored in the log (up to 8,000 chars) to make debugging easier.