# Webhooks

Outbound webhooks deliver event notifications from Risk Register to your endpoint, usually within a minute of the change. Every delivery is signed with HMAC-SHA256 in a Stripe-style format, retried on failure, and protected against replay.

## Plan availability

Webhooks require the Business plan. Risk Register staff can turn webhooks on for a specific organisation without a plan upgrade.

## Quick links

| What you want | Where |
| --- | --- |
| Verify a webhook signature in your code | [Verifying signatures](https://riskregister.com/docs/webhook-signatures.md) |
| The list of event types and their payloads | [Event types](https://riskregister.com/docs/webhook-event-types.md) |
| Configure an endpoint in the app | `/{orgSlug}/settings/webhooks` (an admin, on the Business plan) |
| List or read endpoints via the REST API | `GET /api/v1/webhook-endpoints` and `GET /api/v1/webhook-endpoints/{id}` (admin tokens). Endpoints are created, changed and revoked in the app. |
| Inspect delivery history | `GET /api/v1/webhook-endpoints/{id}/deliveries` |

## Architecture at a glance

```
┌─────────────────┐    inside tx    ┌──────────────────────┐    cron (60s)    ┌──────────────────┐
│  Tenant request │ ─────────────> │ webhook_event_outbox │ ───────────────> │  Inngest worker  │
│  (state change) │  audit + event │  (durable row)       │  drains pending  │  (HMAC sign +    │
└─────────────────┘                └──────────────────────┘                  │   POST + retry)  │
                                                                            └────────┬─────────┘
                                                                                     │
                                                                                     ↓
                                                                          ┌──────────────────┐
                                                                          │ Your endpoint    │
                                                                          │ verifies + 2xx   │
                                                                          └──────────────────┘
```

Every state-mutating call that emits a webhook event writes a durable row to `webhook_event_outbox` **inside the same database transaction** as the audit row. If the transaction rolls back, no event fires. If it commits, the event is guaranteed to be in the outbox.

A separate Inngest cron sweeps the outbox once a minute and hands pending events to the delivery worker. Once the hand-off succeeds, the row is marked `sent`; if it fails, its attempt count increments and a later sweep tries again, up to 20 times. The delivery worker then POSTs the event to each subscribed endpoint (see [Retry policy](#retry-policy)).

This is the canonical "outbox pattern" for at-least-once delivery. It survives process death between the database commit and the network send.
## Headers on every delivery

```
POST /your-endpoint HTTP/1.1
Webhook-Id: 5dba8a3c-9b71-4f9b-9b9a-3b8b2a1c4d2e
Webhook-Timestamp: 1748000000
Webhook-Signature: t=1748000000,v1=<64-char hex hmac>
Content-Type: application/json

{ "id": "5dba8a3c-9b71-4f9b-9b9a-3b8b2a1c4d2e", "createdAt": "2026-05-28T12:00:00.000Z", "event": "risk.created", "data": { "risk": { … } } }
```

The body has four keys: `id`, `createdAt`, `event` (the event type) and `data`. There is no organisation id in it: an endpoint belongs to one organisation. [Event types](https://riskregister.com/docs/webhook-event-types.md#envelope) describes each key.

- `Webhook-Id` - the event's `id`, stable across retries. It isn't signed, so dedupe on the `id` in the verified body, and reject a delivery whose header differs from it ([why](https://riskregister.com/docs/webhook-signatures.md#idempotency)).
- `Webhook-Timestamp` - unix seconds, the moment this delivery attempt was signed (the event's own time is `createdAt` in the body). Reject anything more than 5 minutes old to defeat replay. Each delivery attempt, retries included, is signed again with a fresh timestamp, so a retry sent hours after the event still passes this check.
- `Webhook-Signature` - `t=<ts>,v1=<hmac>`, Stripe-style. Verify before parsing.

The signing scheme is HMAC-SHA256 over the literal string `<Webhook-Timestamp>.<raw_body>`. Use the raw request bytes, not the JSON-parsed payload. Full code samples in [Verifying signatures](https://riskregister.com/docs/webhook-signatures.md).

Despite the header names, this is not the Standard Webhooks scheme (which signs `<id>.<timestamp>.<body>` and encodes the result in base64), so Standard Webhooks libraries will not verify these deliveries. Use the code in [Verifying signatures](https://riskregister.com/docs/webhook-signatures.md).

## Retry policy

| Attempt | Delay before retry |
| --- | --- |
| 1 → 2 | ~5 seconds |
| 2 → 3 | ~5 minutes |
| 3 → 4 | ~30 minutes |
| 4 → 5 | ~2 hours |
| after 5 | the event is abandoned for that endpoint |

An event is tried up to 5 times for each endpoint. Every attempt carries the same body and `Webhook-Id`, and a new `Webhook-Timestamp` and signature made at the moment it is sent.

An endpoint whose last 20 delivery attempts all failed (attempts, not events: four abandoned events are enough) is turned off. It stays in your list with status `auto_disabled`; an admin re-enables it in the app after fixing the receiver, which resets the failure count. An attempt held back by the per-endpoint rate cap (see [Endpoint constraints](#endpoint-constraints)) doesn't count towards the 20.

## What counts as success?

Any 2xx status. Your endpoint should:

1. Verify the signature.
2. Check the timestamp is recent (≤5 minutes).
3. Check the body's `id` equals `Webhook-Id`, then check that `id` against your dedup table (idempotent handling).
4. Store the event and its `id`.
5. Return 2xx, then process the event asynchronously. The response timeout is 10 seconds.

If you return non-2xx, the worker retries. If you can't process the event (corrupted data, unknown event type), return 2xx anyway: a 2xx stops the retries, and the failure is yours to investigate from your own logs. Returning 4xx/5xx for an error that a retry can't fix just wastes retries.

## Endpoint constraints

- HTTPS only. HTTP endpoints are rejected at create-time. The SSRF (server-side request forgery) defence checks the resolved IP address and refuses loopback, link-local, private, and unspecified ranges (including IPv4 addresses written in IPv6 form). DNS resolution is pinned per-delivery to defeat rebinding.
- The `Host` header your endpoint sees is your customer-facing hostname. TLS SNI uses the same. The pinned IP path applies only to the connect step; cert verification is unchanged.
- Response body is read up to 4 KiB and stored with the delivery, where the delivery history shows it. Anything beyond 4 KiB is truncated. UTF-8 byte boundaries are respected.
- Response timeout is 10 seconds. Slower than that and the worker treats it as a failure.
- An organisation can hold at most 10 endpoints. Paused endpoints (an admin can pause and resume one in the app) and auto-disabled endpoints count; revoking one frees its place. Point several systems at one receiver if you need more.
- Events leave the outbox at up to 300 per organisation a minute (see [Rate limits](https://riskregister.com/docs/rate-limits.md#per-org-per-minute-caps)). A bulk operation that creates more than that is delivered over the following minutes.
- An endpoint is sent at most 100 delivery attempts a minute. A delivery over that waits and is sent later, up to about two hours on: it is not recorded as failed and does not use one of the event's 5 attempts, because your endpoint was never called. After a large import, expect its events to arrive spread over that time.
- At most two of an organisation's events are being delivered at once. The rest wait their turn, so slow receivers delay only their own organisation's deliveries, never another's.

## Secret management

Each endpoint has a secret used to compute the HMAC. The secret format is `rrws_<43 base64url chars>`.

**One-shot reveal.** The secret is shown once at endpoint creation. Copy it to your secret store immediately.

**Rotation.** An admin rotates the secret from the endpoint's page in the app. The new secret is shown once. For the next 24 hours every delivery is signed with both the old and the new secret (two `v1=` values in the signature header), so you can move your receiver to the new secret without dropping events; after that, only the new one signs. See [Verifying signatures](https://riskregister.com/docs/webhook-signatures.md).

**At rest.** The server stores secrets encrypted with AES-256-GCM under a per-deployment key. Plaintext is never persisted.

## Event selection

When an admin creates an endpoint in the app, they choose which event types it receives (for example `risk.created`, `risk.escalated` and `review.overdue`), and can change the selection later on the endpoint's page.

Subscribing to a subset reduces noise and limits what an attacker sees if your endpoint is ever compromised. Subscribe to everything during integration testing, then narrow once you know which events you actually consume.

## Testing

Each endpoint has a "Send test event" button in the app that fires a synthetic event bypassing the outbox. The signature, headers, and body shape all match production - useful for verifying your receiver before any live event lands.

For local development, [smee.io](https://smee.io/) or [ngrok](https://ngrok.com/) work fine. Just remember the SSRF defence rejects loopback IPs — you need a public URL.

## See also

- [Verifying signatures](https://riskregister.com/docs/webhook-signatures.md) - code samples for Node.js and Python.
- [Event types](https://riskregister.com/docs/webhook-event-types.md) - the catalogue of every event you can subscribe to.
- [API errors](https://riskregister.com/docs/errors.md) - for the management endpoints.
- [Rate limits](https://riskregister.com/docs/rate-limits.md) - the per-organisation dispatch cap.
