# Verifying bubbl3 webhook signatures

Every bubbl3 webhook carries a bubbl3-signature header, an HMAC-SHA256 of the timestamp and the raw body keyed with your endpoint's secret. Check it with verifyWebhook from @bubbl3/sdk before you trust a delivery, answer with a 2xx within 10 seconds, and deduplicate on the event id, because deliveries are retried for up to 24 hours.

## The short version

1. **Keep the raw body** Read the request body as raw bytes, before any JSON parsing.
2. **Verify the signature** Call verifyWebhook with the raw body, the bubbl3-signature header and your endpoint's secret, and answer 400 if it returns false.
3. **Deduplicate** Record the event id and skip any event you've already handled.
4. **Answer quickly** Answer with a 2xx within 10 seconds, then do the slow work afterwards.

A webhook endpoint is a public URL. The signature is how you know a request really came from bubbl3 and wasn't changed on the way.

## Signature header

Each delivery is a POST with a JSON body and these headers:

- `bubbl3-signature`: `t=<unix seconds>,v1=<hex HMAC-SHA256>`.
- `bubbl3-event-id`: the event's id, the same on every retry and replay.
- `bubbl3-event-type`: the event's type.
- `bubbl3-delivery-id`: this delivery, for matching with the dashboard's delivery log.

The signature is an HMAC-SHA256, keyed with your endpoint's secret, of the timestamp, a dot and the raw body. The secret (`whsec_...`) is shown once, when you create the endpoint. See [webhooks](/developers/webhooks).

## `verifyWebhook` in the SDK

The [TypeScript SDK](/developers/sdk) checks it for you:

```ts
import express from 'express';
import { verifyWebhook } from '@bubbl3/sdk';

const app = express();

app.post('/bubbl3/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
  if (
    !verifyWebhook(req.body, req.headers['bubbl3-signature'], process.env.BUBBL3_WEBHOOK_SECRET)
  ) {
    return res.status(400).end();
  }
  const event = JSON.parse(req.body.toString('utf8'));
  // Record event.id first, and skip it if you've seen it before.
  res.status(200).end();
  void handle(event);
});
```

`verifyWebhook(rawBody, header, secret)` returns true or false and doesn't throw. Give it the raw body, exactly as received: a parsed object fails. To learn why a check failed, call `checkWebhookSignature` with the same arguments; it returns `missing_header`, `malformed_header`, `invalid_body`, `stale_timestamp` or `signature_mismatch`.

Without the SDK, compute the HMAC-SHA256 of `<t>.<raw body>` as hex, compare it in constant time with each `v1` value, and reject old timestamps.

## Replay

Two kinds of replay matter.

- **Someone else replaying a request.** The timestamp is signed with the body, and `verifyWebhook` rejects a timestamp more than 300 seconds from now, either way. A captured delivery sent again later fails. Change the window with `toleranceSeconds` only if your clocks need it.
- **You replaying a delivery.** Every attempt is kept, and you can replay a finished delivery from the dashboard or the API. It sends the same event id with a fresh signature, so your duplicate check still works.

## Retries

- Answer with any 2xx within 10 seconds, then do slow work afterwards or on a queue.
- Anything else, including a timeout or a refused connection, is retried with exponential backoff and jitter, for up to 24 hours. Then the delivery is marked failed.
- Delivery is at least once. Deduplicate on the event id, or the `bubbl3-event-id` header.
- Events can arrive out of order. Use `created_at`, and for `message.status`, `previous_status`, rather than arrival order.
- Answer `410 Gone` to stop deliveries to an endpoint. If more than half of an endpoint's last 100 deliveries fail, bubbl3 disables it and emails you.

Test your endpoint with a signed test event before you go live, or in the [sandbox](/developers/sandbox).

## Common questions

**What does verifyWebhook do when the secret is missing?**

It returns false. A missing or blank secret always fails, so a missing environment variable can't let deliveries through.

**How do I rotate the secret without dropping events?**

For 24 hours after a rotation, each delivery carries two v1 signatures, one per secret. Pass both secrets to verifyWebhook as a list until you've switched.

## Keep reading

- [Webhooks](https://bubbl3.com/developers/webhooks)
- [TypeScript SDK](https://bubbl3.com/developers/sdk)
- [Webhook](https://bubbl3.com/glossary/webhook)

Updated: 2026-10-17
