Skip to navigation

Webhook verification

This guide walks through verifying the webhooks Latitude sends to your endpoint. Latitude signs every webhook with the Standard Webhooks 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.

a) New subscriptions

Creating a subscription also creates one secret and returns it as signing_secret in the response.

Request:

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/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:

HeaderDescription
webhook-idUnique event ID. The same on every retry of the event
webhook-timestampUnix time, in seconds, when this delivery attempt was sent
webhook-signatureOne or more signatures, separated by spaces, each in the form v1,<Base64 signature>

The Standard Webhooks 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.

import { Webhook } from "standardwebhooks"
const wh = new Webhook(base64_secret);
wh.verify(webhook_payload, webhook_headers);

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:

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 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:

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:

POST /v1/webhook_subscriptions/whsub_k3Xp9TqL2mVa7RzE/signing_secrets HTTP/1.1
Content-Type: application/json
{
"expire_previous_in": 43200
}

Response:

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:

TimeWhat happenswebhook-signature
Before 09:00Only the old secret is activev1,hOqm… (old)
09:00You add the new secretv1,8ir4… (new) v1,hOqm… (old)
09:00 to 21:00You deploy the new secret to your endpoint. Webhooks verify before and after the deployv1,8ir4… (new) v1,hOqm… (old)
From 21:00The old secret expires, 43200 seconds after you added the new onev1,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.