Skip to content

Verify webhook signatures

Short answer

Every webhook is signed with HMAC-SHA256 using the Standard Webhooks scheme. Check the signature and timestamp before trusting a delivery.

Updated · 1 min read

On this page

Each delivery carries three headers: webhook-id, webhook-timestamp and webhook-signature. Checking the signature proves the request came from TheBusinessApp and wasn't changed on the way. Code samples for Node, Python and PHP are on the webhooks developer page.

How the signature works

  1. Take your signing secret, remove the whsec_ prefix and base64-decode the rest. That is the key.
  2. Build the string {webhook-id}.{webhook-timestamp}.{raw body} using the exact bytes of the request body.
  3. Work out HMAC-SHA256 of that string with the key, and base64 the result.
  4. Compare it, in constant time, with each space-separated v1,... value in webhook-signature. One must match.
  5. Reject the request if webhook-timestamp is more than five minutes from now, to stop replays.
const key = Buffer.from(SECRET.replace(/^whsec_/, ''), 'base64')
const expected = crypto.createHmac('sha256', key)
  .update(`${id}.${ts}.${rawBody}`)
  .digest('base64')

Important

Verify against the raw body, before any JSON parsing. Re-serialised JSON won't match.

Reveal or rotate the secret

  • Open the endpoint and click Reveal secret to see it again.
  • Click Rotate secret to make a new one. For 24 hours the old secret keeps signing alongside the new one, so webhook-signature carries two values while you update your receiver.

Deliveries also include TBA-Event-Type, TBA-Delivery-Id and TBA-Delivery-Attempt headers for logging. The webhook-id stays the same across retries and resends.

Was this article helpful?

Still stuck?

Tell us what you were trying to do and which screen you were on, and we’ll walk you through it. Email hello@thebusinessapp.co.uk or contact support.

    Type to search every help article. Use the arrow keys and Enter to open one.