Skip to Content

How do I verify a webhook signature?

Compute an HMAC-SHA256 of the raw request body — the exact bytes received, before any JSON parsing — with your signing secret, encode it the way the sender does, and compare it with the signature header in constant time. For Stripe’s official error and the usual causes, see “No signatures found matching the expected signature for payload.”

The check

import { createHmac, timingSafeEqual } from 'node:crypto' // Verify an HMAC-SHA256 webhook signature over the raw body. // rawBody: the body exactly as received (Buffer or string), never JSON.stringify(req.body) // encoding: 'hex' or 'base64' as the sender documents; prefix: for example 'sha256=' for GitHub export function verifySignature ({ rawBody, secret, received, encoding = 'hex', prefix = '' }) { if (typeof received !== 'string' || !received.startsWith(prefix)) return false const expected = Buffer.from(createHmac('sha256', secret).update(rawBody).digest(encoding)) const given = Buffer.from(received.slice(prefix.length)) return given.length === expected.length && timingSafeEqual(given, expected) }

Each sender’s scheme

SenderHeaderEncodingPrefix
GitHubx-hub-signature-256hexsha256=
LinkedInx-li-signaturehexnone
QuickBooksintuit-signaturebase64none
Shopifyx-shopify-hmac-sha256base64none
Typeformtypeform-signaturebase64sha256=

Stripe is not in the table, because it does not fit the Header, Encoding, and Prefix columns. Stripe signs a timestamp joined to the raw body and sends both in the Stripe-Signature header (t= and v1=). Square also signs more than the body: it signs your notification URL joined to the body. For where Square’s key lives, see Where do I find my Square webhook signature key?

Where do I find my Stripe webhook signing secret?

Your Stripe webhook signing secret is on the endpoint in Stripe Workbench. Open Workbench, select Webhooks, open the endpoint, and click Reveal secret. The value starts with whsec_. That is the signing secret — sometimes called a webhook key — not a Stripe API key.

  1. In Stripe, open Workbench, select Webhooks, and open the endpoint that sends the events.
  2. Click Reveal secret. Stripe generates this value when you create the endpoint; you don’t invent it. It starts with whsec_. If you rotate it, use Roll secret in the same place, then update the value stored on the data stream.
  3. Paste that value into the data stream’s inbound secret field, with no extra whitespace. If you used stripe listen, the secret printed in the terminal is a different whsec_ value. It will not verify events sent to a Workbench endpoint, and the Workbench secret will not verify events the CLI forwarded to localhost.

Why does Stripe signature verification fail?

Stripe signature verification fails when the signing secret, the raw request body, or the Stripe-Signature header doesn’t match what Stripe sent. The error often reads: “No signatures found matching the expected signature for payload.” The most common cause is using the wrong endpoint secret. The causes, and that official error, are in “No signatures found matching the expected signature for payload.”

“No signatures found matching the expected signature for payload”

Stripe’s library asks, in the same message, “Are you passing the raw request body you received from Stripe?” The official error is: “No signatures found matching the expected signature for payload.”

The usual causes, from Stripe’s docs:

  • The wrong endpoint secret. The secret for a CLI-forwarded endpoint is different from the secret for a Dashboard or Workbench endpoint — don’t mix them. Both start with whsec_. Extra whitespace on the secret will also fail the check. Using an API key (sk_ or pk_) instead of the signing secret fails the same way. See Where do I find my Stripe webhook signing secret?
  • The body was changed before verification. Stripe signs the exact UTF-8 bytes it sent. If a framework parses the JSON, re-serializes it, strips whitespace, or reorders keys, the signature will not match. Use the raw request body.
  • The Stripe-Signature header wasn’t read correctly. The header looks like t=…,v1=…. Keep the t and v1 values. Stripe can add other entries; don’t depend on a fixed order or count.
  • A different failure: Stripe’s official libraries also reject an event if its timestamp is older than their default five-minute tolerance. That error is not the “No signatures found” message. That five-minute figure is Stripe’s library default, not a Slashbin tolerance.

To receive Stripe through Slashbin and inspect the stored payload and signature result, see Why did my Stripe webhook do nothing? and How do I retry failed Stripe webhooks?.

In Slashbin

Verification runs at the gateway from stored configuration — the header, the encoding and the prefix for each sender — before your Golden Model or any destination sees the event, so there is no verification code of yours to get wrong.

Need somewhere for the next project’s webhooks to land? Slashbin’s Free plan takes an account, not a card.

Start free

(opens in a new tab)