Most apps that take money through Stripe find out about a payment from a webhook. A Lovable or Bolt app on Supabase usually has an Edge Function at something like /functions/v1/stripe-webhook; a Cursor or v0 app on Next.js has a route handler at app/api/stripe/webhook/route.ts. When checkout.session.completed arrives, the handler marks the order paid, unlocks the plan or sends the download. That makes it one of the few endpoints in your app where a forged request turns directly into money.

There's no news hook today, so here is a check we'd run on any app with Stripe before it takes real payments. It takes about fifteen minutes, and you need your code, your Stripe dashboard and a terminal with curl.

Why AI-built handlers get this wrong

Stripe signs every webhook it sends. The Stripe-Signature header carries a timestamp t and one or more v1 signatures, each an HMAC-SHA256 of the timestamp, a full stop and the raw request body, keyed with the endpoint's whsec_ signing secret. Stripe's docs are blunt about what happens without verification: an attacker "could send fake webhook events to your endpoint to trigger actions like fulfilling orders, granting account access, or modifying records."

The signature is computed over the exact bytes Stripe sent. That's where generated code tends to break. The model writes const event = await req.json(), the handler works in a demo, and nobody notices there is no verification at all. Or it adds verification on top of a parsed body, verification fails with a 400, and the next prompt "fixes" it by commenting the check out. Both versions ship and both look fine until someone posts a fake event.

The check, step by step

  1. Find the handler. Search the codebase for stripe.webhooks, constructEvent, Stripe-Signature and checkout.session.completed. If you find the event type but none of the first three, the handler doesn't verify anything. Stop here and fix that first.

  2. Confirm it verifies the raw body. In a Next.js route handler or a Supabase Edge Function, the body must be read with await req.text() and that string passed straight to the verifier. In Express it's express.raw({type: 'application/json'}) on that route. Stripe's docs: "Any manipulation to the raw body of the request causes the verification to fail." On Supabase (Deno), the official example uses stripe.webhooks.constructEventAsync(body, signature, secret, undefined, cryptoProvider) with Stripe.createSubtleCryptoProvider(), because the synchronous constructEvent needs Node's crypto. A req.json() anywhere before verification is a bug.

  3. Confirm a failed check stops the handler. The verifier throws on a bad signature. The catch must return a 400 and exit. Look for the pattern where the error is logged and execution carries on with JSON.parse(body); that's verification in name only. Also check that no code path reads event.data.object before verification succeeds.

  4. Check the secret. The signing secret must come from an environment variable such as STRIPE_WEBHOOK_SECRET, never a string in the code, and must never have a NEXT_PUBLIC_ or VITE_ prefix that ships it to the browser. Then check it's the right one. Stripe generates a separate secret for each endpoint, a different one for test and live mode on the same URL, and stripe listen prints yet another for local forwarding. Open the endpoint in the Stripe dashboard (Workbench, Webhooks), click to reveal the secret and compare the last four characters with what's set in Vercel, Netlify or your Supabase function secrets. If the live endpoint shows failed deliveries with status 400, a mismatched secret is the first suspect.

  5. Send it a forged event. Post a fake event without a valid signature and see what happens:

curl -i -X POST https://your-app.com/api/stripe/webhook -H "Content-Type: application/json" -H "Stripe-Signature: t=1,v1=bad" -d '{"type":"checkout.session.completed","data":{"object":{"id":"cs_fake"}}}'

You want a 400 and no change in your database. A 200, a new paid order or an unlocked account means anyone can do this. Then do the opposite test with real signatures: stripe trigger checkout.session.completed against a sandbox endpoint, or stripe listen --forward-to with your local server, should succeed.

  1. Make it idempotent. Stripe says endpoints "might occasionally receive the same event more than once" and doesn't guarantee order. In live mode it retries failed deliveries for up to three days. Store the processed event.id in a table with a unique constraint and skip IDs you've seen, so a retry doesn't send a second download or credit an account twice.

A few things that look like bugs but aren't

Don't set the timestamp tolerance to 0 to make an error go away. The libraries default to five minutes, and Stripe's docs warn that 0 "disables the recency check entirely", which reopens the door to replayed requests. If verification fails on timing, your server clock is the problem.

The newer Stripe-Signature header may carry extra secret, destination and payload entries for debugging. They aren't covered by the HMAC, so code must never authenticate with them. Only a valid v1 signature counts, and a manual verifier should ignore every other scheme, including the fake v0 Stripe adds for sandbox events.

On Supabase, the Edge Function has to accept requests without a Supabase JWT, since Stripe doesn't send one. The official example deploys with verify_jwt = false for that reason. That's fine, because the Stripe signature is now the only thing keeping strangers out, which is exactly why steps 2 and 3 matter.

Finally, return the 2xx fast. Stripe treats a slow response as a failure and retries it, so do the heavy work after acknowledging, or in a queue. A redirect counts as a failure too: if Stripe shows 302 deliveries, the endpoint URL points at a route that redirects, often from the bare domain to www, and needs updating to the final URL.

If live payments go through but orders never update, and the code looks right, the problem is often the deploy rather than the handler. Our page on apps that work locally but 500 live covers the missing environment variable and the function that never deployed.

Sources

First published on RescueMySites.