> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.latitude.xyz/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.latitude.xyz/_mcp/server.

# Webhook verification

> Verify that webhooks come from Latitude, and rotate your webhook signing secrets without missing an event

This guide walks through verifying the webhooks Latitude sends to your endpoint. Latitude signs every webhook with the [Standard Webhooks](https://www.standardwebhooks.com) scheme, so you can confirm that it came from Latitude. You'll learn how to get a signing secret, verify each webhook, handle retries, and rotate your secret without failing any deliveries.

## Summary

The high-level steps are as follows:

1. Get a signing secret for your webhook subscription and store it securely
2. Verify the signature of every webhook
3. Respond with a `2xx` status, and use `webhook-id` to ignore duplicate deliveries
4. Rotate the signing secret when needed, without failing any deliveries

## Detailed Steps

### Step 1: Get a signing secret

Each webhook subscription has its own signing secret: `whsec_` followed by a Base64 string. It is returned only once, so store it securely. If you lose it, add a new one as described in [Step 4](#step-4-rotate-your-signing-secret).

#### a) New subscriptions

[Creating a subscription](/api-reference/webhooks/post-v-1-webhook-subscriptions) also creates one secret and returns it as `signing_secret` in the response.

Request:

```http
POST /v1/webhook_subscriptions HTTP/1.1
Content-Type: application/json

{
  "url": "https://your-domain.com/webhooks/latitude",
  "event_types": ["transfer.completed", "transfer.failed"]
}
```

Response:

```http
HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": "whsub_k3Xp9TqL2mVa7RzE",
  "url": "https://your-domain.com/webhooks/latitude",
  "event_types": ["transfer.completed", "transfer.failed"],
  "is_active": true,
  "created_at": "2026-11-17T09:00:00Z",
  "updated_at": "2026-11-17T09:00:00Z",
  "signing_secret": "whsec_ncx2GN9zWyTegOzulZlDnXZir4SwAXf4vodVhxISanE="
}
```

#### b) Existing subscriptions

Subscriptions created before webhook signing was available (11/18/2026) will send unsigned webhooks until you add a secret. To add one, call `POST /v1/webhook_subscriptions/{id}/signing_secrets`. Immediately after secret creation, the next webhook delivered will be signed.

### Step 2: Verify every webhook

Each signed webhook includes these headers:

| Header              | Description                                                                           |
| ------------------- | ------------------------------------------------------------------------------------- |
| `webhook-id`        | Unique event ID. The same on every retry of the event                                 |
| `webhook-timestamp` | Unix time, in seconds, when this delivery attempt was sent                            |
| `webhook-signature` | One or more signatures, separated by spaces, each in the form `v1,<Base64 signature>` |

#### Using a Standard Webhooks library (recommended)

The [Standard Webhooks libraries](https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries) will verify the signature for you, and are available for most languages. Pass the secret exactly as Latitude returned it, including the `whsec_` prefix.

#### JavaScript

```javascript
import { Webhook } from "standardwebhooks"

const wh = new Webhook(base64_secret);
wh.verify(webhook_payload, webhook_headers);
```

#### Python

```python
from standardwebhooks.webhooks import Webhook

wh = Webhook(base64_secret)
wh.verify(webhook_payload, webhook_headers)
```

#### Ruby

```ruby
require 'standardwebhooks'

webhook = StandardWebhooks::Webhook.new(ENV.fetch('WEBHOOK_SECRET'))

payload = webhook.verify(raw_body, {
  'webhook-id' => request_headers.fetch('webhook-id'),
  'webhook-timestamp' => request_headers.fetch('webhook-timestamp'),
  'webhook-signature' => request_headers.fetch('webhook-signature'),
})
```

Libraries are also available for C#, Elixir, Go, Java, PHP and Rust.

#### Verifying without a library

If you can't use a library, compute the signature yourself using the [Standard Webhooks signature scheme](https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md#symmetric-signatures):

```
signature = base64(HMAC-SHA256(key=base64_decode(signing_secret without "whsec_"), msg="{webhook-id}.{webhook-timestamp}.{raw body}"))
```

Compare your signature with each `v1,` entry in the `webhook-signature` header using a constant-time comparison, and check that the timestamp is recent. See [verifying signatures](https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md#verifying-signatures) for the full list of checks.

### Step 3: Respond and handle retries

Respond with any `2xx` status within 10 seconds to acknowledge a webhook. If your endpoint returns another status, times out or can't be reached, Latitude retries the delivery up to 5 times. A retried delivery for the same event will have the same `webhook-id` header.

### Step 4: Rotate your signing secret

In order to support secret rotation, a subscription can have at most 2 active secrets at once. Having 2 lets you switch to a new secret, while still supporting the orginial secret for a period of up to 24 hours. While both are active, Latitude signs every webhook with each secret and sends both signatures in the `webhook-signature` header, newest first:

```http
webhook-signature: v1,8ir4ie+7qJ4WXwWxiuXaGTGix1XK0wVKY55FLUkOymA= v1,hOqmb10nHr+qOY0xH6gQwPqFchQAnakMWUP5Xjxn6sQ=
```

A webhook is valid if any one of its signatures matches, so it verifies with either secret.

To rotate, add a new secret with `POST /v1/webhook_subscriptions/{id}/signing_secrets`. The new secret becomes the current secret and never expires. The previous secret keeps signing for `expire_previous_in` seconds, which is an optional field in the request for a new secret. It must be between `0` (expire now) and `86400` (24 hours), and defaults to `86400`.

For example, this request adds a new secret at 09:00 UTC, and the old secret expires 12 hours later, at 21:00 UTC.

Request:

```http
POST /v1/webhook_subscriptions/whsub_k3Xp9TqL2mVa7RzE/signing_secrets HTTP/1.1
Content-Type: application/json

{
  "expire_previous_in": 43200
}
```

Response:

```http
HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": "whsk_Bn4tYc8WqJ2hLs6D",
  "signing_secret": "whsec_rwsu+IdiKNcbMOHQVv74e9joMZsr5QNxRQCfzaXc9dI=",
  "expires_at": null,
  "created_at": "2026-11-17T09:00:00Z"
}
```

#### Example rotation

Here is the `webhook-signature` header during that rotation:

| Time           | What happens                                                                            | `webhook-signature`               |
| -------------- | --------------------------------------------------------------------------------------- | --------------------------------- |
| Before 09:00   | Only the old secret is active                                                           | `v1,hOqm…` (old)                  |
| 09:00          | You add the new secret                                                                  | `v1,8ir4…` (new) `v1,hOqm…` (old) |
| 09:00 to 21:00 | You deploy the new secret to your endpoint. Webhooks verify before and after the deploy | `v1,8ir4…` (new) `v1,hOqm…` (old) |
| From 21:00     | The old secret expires, 43200 seconds after you added the new one                       | `v1,8ir4…` (new)                  |

#### Replacing a leaked secret

Add a new secret with `expire_previous_in` set to `0`. Your previous secret stops signing immediately, so deploy the new secret as soon as possible. Otherwise, webhooks will fail verification with the old secret until the new secret is implemented into your verification.

#### Number of secrets

A subscription can't have more than 2 active secrets. To create a new secret when you have 2 active secrets for a subscription, you need to call `POST /v1/webhook_subscriptions/{id}/signing_secrets`, with `expire_previous_in` set to 0. This will immediately expire the 2 old secrets, and all new webhooks will be signed with the secret returned from the request. If `expire_previous_in` is not set to 0, a `422` error code will be returned, and no new secret will be created.