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.
verifyWebhook in the SDK
The TypeScript SDK checks it for you:
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
verifyWebhookrejects a timestamp more than 300 seconds from now, either way. A captured delivery sent again later fails. Change the window withtoleranceSecondsonly 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-idheader. - Events can arrive out of order. Use
created_at, and formessage.status,previous_status, rather than arrival order. - Answer
410 Goneto 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.