Oktopost

Security

Verify webhook signatures and build a reliable endpoint.

Every webhook request is signed. Verify the signature before you act on a delivery, and design your endpoint to handle retries.

Verify Webhook Signatures

Check X-Oktopost-Secret before you trust a delivery. It proves the request came from Oktopost and that the body was not changed in transit.

Each request includes three headers:

Prop

Type

Calculate the signature from the request body and the Secret returned when the webhook was created:

  1. Read the body as text, exactly as it arrived, before you parse it as JSON.
  2. Compute HMAC-SHA1 of that text, using the webhook Secret as the key.
  3. Encode the result as hexadecimal.
  4. Compare it with the X-Oktopost-Secret header. Accept the request only when they match.

Parse the JSON only after the check succeeds. If you parse the body and turn it back into a string, spacing or key order can change, and the signature will not match.

const crypto = require('crypto');

// rawBody: the POST body as text, before JSON.parse
// signature: the X-Oktopost-Secret header
// secret: the Secret returned when the webhook was created
function verifyWebhook(rawBody, signature, secret) {
  const expectedSignature = crypto
    .createHmac('sha1', secret)
    .update(rawBody)
    .digest('hex');

  return signature === expectedSignature;
}

Endpoint Requirements

Your webhook endpoint should:

  • Respond quickly - Return a 2xx status code within 5 seconds
  • Use HTTPS - All webhook URLs must use HTTPS
  • Handle retries - Oktopost retries failed webhooks up to 3 times
  • Be idempotent - Handle duplicate webhook deliveries gracefully
  • Check the signature - Compare X-Oktopost-Secret with your calculated signature before processing the body

Error Handling

If your endpoint returns a non-2xx status code or times out:

  • Oktopost will retry the webhook up to 3 times
  • Retries use exponential backoff (5s, 25s, 125s)
  • After 3 failed attempts, the webhook delivery is abandoned
  • Check the webhook log to diagnose delivery issues