AI builders often generate a webhook handler that reads the event body and trusts it. Here's how to check yours in 2 minutes and fix it.
Your webhook URL is public: Stripe has to reach it. If the handler parses req.body and acts on checkout.session.completed without checking Stripe's signature, anyone who finds the URL can POST a made-up event and unlock a plan, credits or an order for free.
grep -rnE "checkout.session.completed|payment_intent.succeeded|invoice.paid" \
app/ src/ pages/ supabase/functions/ 2>/dev/null
grep -rnE "constructEvent|constructEventAsync" app/ src/ pages/ supabase/functions/ 2>/dev/null
If the first search finds a handler and the second finds nothing in that same file, the handler is almost certainly not verifying. Also check for STRIPE_WEBHOOK_SECRET (a whsec_... value) in your server env: no secret means no verification.
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(req: Request) {
const body = await req.text(); // raw body, not req.json()
const sig = req.headers.get("stripe-signature")!;
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(body, sig, process.env.STRIPE_WEBHOOK_SECRET!);
} catch {
return new Response("bad signature", { status: 400 });
}
if (event.type === "checkout.session.completed") { /* fulfil */ }
return new Response("ok");
}
const body = await req.text();
const sig = req.headers.get("stripe-signature")!;
const event = await stripe.webhooks.constructEventAsync(
body, sig, Deno.env.get("STRIPE_WEBHOOK_SECRET")!,
undefined, Stripe.createSubtleCryptoProvider()
);
Deno needs the async variant with the SubtleCrypto provider. Stripe documents both in its webhooks guide.
Parsing JSON before verifying ....... use the raw text body
Test-mode secret in production ...... each endpoint has its own whsec_
Secret behind NEXT_PUBLIC_ / VITE_ .. server env only
Also make fulfilment idempotent (store event.id and skip repeats): Stripe retries deliveries.
stripe listen --forward-to localhost:3000/api/webhooks/stripe
stripe trigger checkout.session.completed
curl -X POST localhost:3000/api/webhooks/stripe -d '{"type":"checkout.session.completed"}'
The CLI-triggered event should succeed; the bare curl should get 400. If the curl succeeds, the handler still trusts unsigned events.
Related: the 10-minute Supabase self-check · is my anon key a problem?
Ship-Ready Lite's quick scan flags Stripe webhook handlers that don't verify signatures, plus leaked keys and open database rules, offline and read-only. The Crew ($39) runs the full 59-check scan.