Skip to content

Verify webhook signatures

Every delivery is signed. Check the signature before you trust the body, and turn away anything older than five minutes.

Admin APIApps4 min read

How the signature is built

Each request carries the topic, the API version its body is shaped for, the event's ID and a shop-signature header with a timestamp and one or more signatures:

Request headers
POST /hooks HTTP/1.1
Content-Type: application/json
shop-topic: order.created
shop-api-version: 2026-10
shop-event-id: evt_01k9w3m2c8f4z7d0q5n1t6v8bx
shop-delivery-id: whdel_01k9w3m2d1h5a8e2r6p0s4y7cz
shop-store-id: store_01k9w2t7q3x8c5n0b4m6v1k9hd
shop-attempt: 1
shop-signature: t=1762588920,v1=5f0c3e9d…a91b

v1 is the hex HMAC-SHA256 of the timestamp, a dot and the raw body, keyed with the secret:

1762588920t, in seconds
{ raw body }the body, unparsed
HMAC-SHA256keyed with the secret
v1=5f0c3e…a91bhex, compare in constant time

Webhooks your app declares in its manifest are signed with the app's client secret. A webhook created through the Admin API has its own signing secret, returned once when you create it.

Verify it in your server

Read the body as bytes, check the timestamp, compute the HMAC, then compare it in constant time.

import { createHmac, timingSafeEqual } from "node:crypto";

const FIVE_MINUTES = 5 * 60;

/** rawBody: the request body exactly as it arrived, as a Buffer. */
export function verify(rawBody, header, secret) {
  const pairs = (header ?? "").split(",").map((kv) => kv.split("="));
  const t = Number(pairs.find(([key]) => key === "t")?.[1]);
  const age = Math.abs(Date.now() / 1000 - t);
  if (!Number.isInteger(t) || age > FIVE_MINUTES) return false;

  const expected = createHmac("sha256", secret)
    .update(`${t}.`)
    .update(rawBody)
    .digest();

  // After a rotation, two v1 values arrive: accept either.
  return pairs
    .filter(([key]) => key === "v1")
    .map(([, value]) => Buffer.from(value, "hex"))
    .some((given) => given.length === expected.length
      && timingSafeEqual(given, expected));
}

Reject old deliveries

  • Accept a timestamp up to five minutes from your clock, in either direction.
  • Keep each event ID for a day and ignore repeats: a retry or a redelivery carries the same ID, in shop-event-id and in the body's id.
  • Answer with a 2xx within ten seconds, then do the slow work in the background. A slower answer counts as a failure and is tried again.

When you rotate the secret

For 24 hours after a rotation, every delivery carries two v1 signatures, one from the new secret and one from the old, so you can deploy the new secret without dropping events.

Rotate an app's client secret in the developer console, in the app's settings. Rotate a webhook's own secret with POST /admin/v1/stores/{store_id}/webhooks/{webhook_id}/rotate-secret.

Test it

For a webhook created through the Admin API, queue a signed webhook.test delivery with POST /admin/v1/stores/{store_id}/webhooks/{webhook_id}/test, then read its result in the webhook's delivery log.

For your app's webhooks, follow the failed deliveries from the app's folder:

Terminal
$ snizu app logs --follow --state failed
2026-11-24T12:04:51Z failed 401 order.created · Siwa Grove
Following. Ctrl+C to stop.

Was this page helpful?

Updated 24 Nov 2026