Webhooks

Signatures, retries, and security

Verify HMAC signatures, prevent replay, and understand the delivery schedule.

Verified against the implementation ·

Delivery headers

HeaderMeaning
content-typeapplication/json
user-agentPrompTessor-Webhooks/1.0
x-promptessor-eventEvent type
x-promptessor-deliveryStable delivery identifier for deduplication
x-promptessor-timestampUnix timestamp in seconds used by the signature
x-promptessor-signaturev1=<lowercase hex HMAC-SHA256>

Verify the signature

Compute HMAC-SHA256 over timestamp + "." + rawBody using the endpoint secret. Compare the lowercase hexadecimal digest to the value after v1= with a constant-time comparison.

import crypto from 'node:crypto';

export function verifyPromptessorWebhook(rawBody, headers, secret) {
  const timestamp = headers['x-promptessor-timestamp'];
  const supplied = headers['x-promptessor-signature']?.replace(/^v1=/, '');
  if (!timestamp || !supplied) return false;

  // Reject stale timestamps in your application before processing the event.
  const expected = crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`)
    .digest('hex');

  const a = Buffer.from(expected, 'hex');
  const b = Buffer.from(supplied, 'hex');
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

Use the raw body

Parsing and re-serializing JSON changes bytes and can invalidate the signature. Capture the raw request body first, verify it, then parse the JSON.

Delivery policy

  • A delivery succeeds on any HTTP 2xx response.
  • Each eligible delivery is claimed with a short lease so overlapping workers do not send it concurrently.
  • Each attempt times out after 10 seconds.
  • Redirects are rejected.
  • Failed deliveries retry with exponential delays: approximately 60, 120, 240, 480, 960, 1,920, then up to 3,600 seconds.
  • A delivery is abandoned after 8 total attempts.
  • Webhook delivery records are retained for 30 days.

Production receiver checklist

  • Store the webhook secret in a secret manager.
  • Allow only HTTPS and keep TLS certificates valid.
  • Enforce a timestamp tolerance appropriate to your environment.
  • Verify HMAC before trusting event type or payload data.
  • Deduplicate deliveries in durable storage.
  • Return 2xx only after durable acceptance.
  • Process business logic from a queue.
  • Alert on repeated verification failures and abandoned deliveries.
  • Rotate the secret after suspected exposure and update the receiver atomically.