Deutsch
Security wikiPayments · Integrations

What is a webhook signature?

Also known as: HMAC signature, Stripe-Signature, signing secret, whsec_, X-Hub-Signature-256

A webhook signature proves that a webhook really comes from the provider and was not changed. How HMAC signatures work, how Stripe signs events and what to check.

By Tim GeithnerPublished 2 min read

Short answer

A webhook signature is a code, usually an HMAC-SHA256, that the provider computes over the request body with a secret only you and it know, and sends in a header. Your handler recomputes it and rejects the request if they differ. Without that check, anyone can send your endpoint a fake ‘payment succeeded’ event. Verify against the raw body, compare in constant time and check the timestamp.

Ask an AI about this page:ChatGPTClaude

On this page

A webhook signature is a short code that the sender computes over the request body using a secret shared only with you, and sends along in a header. Your handler computes the same code with the same secret and accepts the request only if both match. Most providers use HMAC with SHA-256: GitHub sends it in X-Hub-Signature-256, Stripe in Stripe-Signature, with a signing secret that starts with whsec_.

Webhook signatures in an AI-built app

A webhook endpoint is a public URL. In a Lovable or Bolt app it is typically a Supabase edge function with verify_jwt = false, because Stripe does not send a Supabase token. If that function reads event.type === "checkout.session.completed" straight from await req.json(), anyone who finds the URL can send a hand-written event and unlock a paid plan for free. Accepting data without checking where it came from is CWE-345 (opens in a new tab).

Stripe’s scheme has three parts worth knowing:

  • The header carries a timestamp t= and one or more v1= signatures. During a secret rollover there is one v1 per active secret.
  • The signature covers timestamp.body, so the exact raw body matters. A framework that parses JSON first breaks the check.
  • The timestamp lets you reject old, replayed events. Stripe’s libraries use a five-minute tolerance by default.

In a Supabase edge function, the check looks like this with Stripe’s Node library:

supabase/functions/stripe-webhook/index.ts (sketch)
const cryptoProvider = Stripe.createSubtleCryptoProvider(); // Web Crypto in Deno
const signature = req.headers.get("Stripe-Signature") ?? "";
const body = await req.text(); // raw body: read it before any JSON parsing
const event = await stripe.webhooks.constructEventAsync(
  body,
  signature,
  Deno.env.get("STRIPE_WEBHOOK_SECRET")!,
  undefined, // default tolerance (five minutes)
  cryptoProvider,
); // throws if the signature or timestamp is wrong: answer 400

How to check your app

  1. Open every webhook handler and find the first line that reads the body. Before it, there must be a signature check with the provider’s library or an HMAC comparison.
  2. Check that the handler reads the body as text or bytes, not through a JSON parser, before verifying.
  3. If the check is hand-written, check that it compares in constant time. GitHub’s docs say never to use a plain ==.
  4. Check that the signing secret comes from a server-side secret, not from code, and that a failed check returns an error without doing anything else.

How to fix or prevent it

Use the provider’s official library to verify, pass it the raw body and the endpoint’s secret, keep the default timestamp tolerance, and return 400 on failure. Then deduplicate by event ID, as explained under idempotency. The complete fix with a prompt for your AI builder is on Stripe webhook without signature check; the wider payment setup is in Stripe in vibe-coded apps.

Frequently asked questions

Why does my Stripe signature check fail even with the right secret?

Usually the body was changed before the check: parsed as JSON and serialized again, or whitespace removed. Stripe needs the raw request body exactly as sent. Also make sure you use the secret of this endpoint; the CLI and the dashboard endpoint have different secrets.

Is an IP allow list enough instead of a signature?

Stripe recommends both: accept requests only from its published IP addresses and verify the signature. The signature is the part that also proves the payload was not changed.

What is the timestamp in the Stripe-Signature header for?

It is part of what is signed, so it can’t be altered. Rejecting events older than a tolerance stops replay attacks. Stripe’s libraries default to five minutes; Stripe warns that a tolerance of 0 switches the check off.

Sources

  1. 1.Receive Stripe events in your webhook endpoint — Stripe Docs
  2. 2.Validating webhook deliveries — GitHub Docs
  3. 3.CWE-345: Insufficient Verification of Data Authenticity — MITRE
  4. 4.Securing Edge Functions — Supabase Docs
  5. 5.Stripe webhooks example for Edge Functions — Supabase on GitHub

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt