// guide · Stripe webhooks · published Nov 13, 2026
Can anyone fake a Stripe payment in your AI-built app? Test your webhook in 1 minute
Short answer
Your webhook URL is public, so anyone can POST a fake checkout.session.completed to it. If the handler doesn't verify the Stripe-Signature header against the raw request body with your whsec_ secret, that fake event unlocks your paid plan for free. Send your own endpoint an unsigned fake event with curl: it must return 400. If it returns 200, verify with stripe.webhooks.constructEvent on the raw body and fail closed.
Why this keeps happening in vibe-coded apps
Stripe says it plainly: without verification, an attacker can send fake webhook events to trigger actions like fulfilling orders or granting access (Stripe webhooks docs). AI tools get the happy path working first: the payment goes through, the webhook flips the user to Pro, the demo works. The signature check is the part that breaks during development, because the generated route parses the body as JSON before verifying it. The “fix” the AI then offers is often to remove the check, wrap it in a try/catch that logs and carries on, or skip it when the secret isn't set. All three leave the door open, and the app still works perfectly for real customers, so nobody notices.
// What AI tools often write: trusts whatever JSON arrives
export async function POST(req: Request) {
const event = await req.json(); // parsed body, no signature check
if (event.type === "checkout.session.completed") {
await grantPro(event.data.object.metadata.userId); // anyone can call this
}
return Response.json({ received: true });
}Test it in 1 minute
Point this at your own webhook route (never at someone else's app). It sends a fake event with no signature, then one with a made-up signature:
# Run this ONLY against your own app. Replace the URL with your webhook route.
URL=https://your-app.com/api/stripe/webhook
# 1) No signature at all
curl -s -o /dev/null -w "%{http_code}\n" -X POST "$URL" \
-H "content-type: application/json" \
-d '{"id":"evt_fake_test","type":"checkout.session.completed","data":{"object":{"id":"cs_fake_test","object":"checkout.session","payment_status":"paid","customer_email":"you@example.com","metadata":{}}}}'
# 2) A made-up signature
curl -s -o /dev/null -w "%{http_code}\n" -X POST "$URL" \
-H "content-type: application/json" -H "stripe-signature: t=1,v1=00" \
-d '{"id":"evt_fake_test","type":"checkout.session.completed","data":{"object":{"id":"cs_fake_test"}}}'
# Both must print 400 (or another 4xx). A 200 means your handler accepted a forged event.If either request returns 200, check your database for an order, credit or subscription row tied to cs_fake_test and delete it. Then fix the handler. A 404 or 405 means the URL is wrong: copy the exact endpoint URL from the Webhooks tab in the Stripe Dashboard (Workbench).
The 5 mistakes to look for
- No verification at all. The handler reads
req.json()and acts onevent.type. - Verifying a parsed body.
constructEvent(JSON.stringify(await req.json()), ...)or a globalexpress.json()before the webhook route. Stripe requires the raw body, byte for byte, so this fails, which leads to mistake 3. - Failing open.
if (sig) verify(),if (!process.env.STRIPE_WEBHOOK_SECRET) skip, or acatchthat logs the error and processes the event anyway. A missing header or secret must mean 400. - No idempotency. Stripe can deliver the same event more than once and retries failed deliveries for up to three days in live mode. Without storing
event.id, a retry can grant credits twice. - Granting on the wrong signal.
checkout.session.completedcan arrive withpayment_status: "unpaid"for delayed payment methods. Fulfill only when it isn'tunpaid(Stripe's own sample check), and again oncheckout.session.async_payment_succeeded(Stripe fulfillment docs).
The fix
Next.js App Router (Vercel, Lovable exports, Bolt, Cursor projects):
// app/api/stripe/webhook/route.ts (Next.js App Router)
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(req: Request) {
const secret = process.env.STRIPE_WEBHOOK_SECRET;
const sig = req.headers.get("stripe-signature");
if (!secret || !sig) return new Response("Missing signature", { status: 400 }); // fail closed
const body = await req.text(); // RAW body, byte for byte
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(body, sig, secret);
} catch {
return new Response("Bad signature", { status: 400 });
}
// Idempotency: Stripe may deliver the same event more than once.
if (await alreadyProcessed(event.id)) return Response.json({ received: true });
if (event.type === "checkout.session.completed" || event.type === "checkout.session.async_payment_succeeded") {
const session = event.data.object as Stripe.Checkout.Session;
if (session.payment_status !== "unpaid") await grantPro(session); // server-side write (service role)
}
await markProcessed(event.id);
return Response.json({ received: true });
}Supabase Edge Function. Stripe doesn't send a Supabase JWT, so the function is deployed with --no-verify-jwt (Supabase example). That makes it public, so the signature check is the only gate. Deno needs the async version with the SubtleCrypto provider:
// supabase/functions/stripe-webhook/index.ts (Deno)
// Deploy with: supabase functions deploy stripe-webhook --no-verify-jwt
import Stripe from "npm:stripe";
const stripe = new Stripe(Deno.env.get("STRIPE_SECRET_KEY")!);
const cryptoProvider = Stripe.createSubtleCryptoProvider();
Deno.serve(async (req) => {
const sig = req.headers.get("stripe-signature");
const secret = Deno.env.get("STRIPE_WEBHOOK_SECRET");
if (!sig || !secret) return new Response("Missing signature", { status: 400 });
const body = await req.text();
let event: Stripe.Event;
try {
event = await stripe.webhooks.constructEventAsync(body, sig, secret, undefined, cryptoProvider);
} catch {
return new Response("Bad signature", { status: 400 });
}
// ...same idempotency + payment_status checks as above, writes with the service role key
return new Response(JSON.stringify({ received: true }), { status: 200 });
});Express:
// Express: the webhook route needs the raw body, so register it BEFORE app.use(express.json())
app.post("/api/stripe/webhook", express.raw({ type: "application/json" }), (req, res) => {
let event;
try {
event = stripe.webhooks.constructEvent(req.body, req.headers["stripe-signature"], process.env.STRIPE_WEBHOOK_SECRET);
} catch {
return res.status(400).send("Bad signature");
}
// ...handle event, then:
res.json({ received: true });
});
app.use(express.json()); // everything elseKeep the libraries' default 5-minute timestamp tolerance (it blocks replays of old signed requests) and never pass 0, which turns the check off. If you verify by hand, only the t and v1 entries count: ignore v0 and the debug entries (secret, destination, payload), which are not covered by the signature, and compare with a constant-time function (signature docs).
Signature errors after the fix? Check the secret: each endpoint has its own whsec_, test and live mode secrets differ, and the one printed by stripe listen only works for events forwarded by the CLI.
Tell your AI coding tool
Paste this into Lovable, Bolt, Cursor or Claude Code:
Audit and fix the Stripe webhook handler in this project.
1. Find every route or function that handles Stripe events (checkout.session.completed, invoice.paid, customer.subscription.*).
2. Make each one read the RAW request body (req.text() in Next.js/Deno, express.raw() in Express) and verify it with stripe.webhooks.constructEvent(rawBody, stripe-signature header, STRIPE_WEBHOOK_SECRET). On Deno/Supabase Edge Functions use constructEventAsync with Stripe.createSubtleCryptoProvider().
3. Return 400 when the header or secret is missing or verification fails. Do not catch the error and continue. Do not set the tolerance to 0.
4. Store each processed event.id (unique column) and skip duplicates.
5. Only fulfill when the Checkout Session's payment_status is not "unpaid"; also handle checkout.session.async_payment_succeeded.
6. Write plan/credit changes server-side only (service role), never from the browser.
7. Add a test that POSTs a fake checkout.session.completed with no signature and with "t=1,v1=00" and expects 400 and no database change.Check your repo automatically
RescueMyRepo's free scan flags Stripe webhook handlers that never call constructEvent (critical) and handlers that verify a parsed body instead of the raw one, with a fix prompt for each. It also checks Telegram, GitHub, Clerk, Resend, Twilio, Slack, Lemon Squeezy and Paddle webhooks, Stripe secret keys exposed to the browser, Supabase tables without RLS and leaked keys. It reads code, so the curl test above is still the best proof that your deployed endpoint rejects fakes.
FAQ
Is my Stripe webhook URL a secret?
No. It is a normal public HTTPS route, often a predictable one like /api/stripe/webhook or /functions/v1/stripe-webhook. Anyone can POST to it. The only thing that proves a request came from Stripe is the Stripe-Signature header, checked against your endpoint's whsec_ signing secret and the raw request body.
Why does my signature check keep failing?
Almost always one of two things. The body was parsed before verification (req.json(), express.json(), a body-parser middleware), so the bytes no longer match what Stripe signed. Or the secret is wrong: each endpoint has its own whsec_ secret, test and live mode secrets differ, and the secret printed by stripe listen only works for events forwarded by the CLI. Fix the cause. Never remove or bypass the check to make the error go away.
My Supabase Edge Function webhook returns 401. Should I turn off JWT verification?
Yes for this one function, because Stripe doesn't send a Supabase JWT (deploy it with --no-verify-jwt or verify_jwt = false). That makes the function public, so the Stripe signature check becomes the only gate. Use constructEventAsync with Stripe.createSubtleCryptoProvider() in Deno.
Is verifying the signature enough?
It is the must-have. Also make the handler idempotent (Stripe can deliver the same event more than once, so store event.id and skip repeats), only fulfill when the Checkout Session's payment_status is not unpaid, as in Stripe's own sample (delayed payment methods finish later with checkout.session.async_payment_succeeded), and keep the default 5-minute timestamp tolerance. Stripe also publishes the IP addresses it sends webhooks from if you want an allowlist on top.
Does RescueMyRepo check other webhook providers?
Yes. The free scan also flags unverified Telegram, GitHub, Clerk (Svix), Resend, Twilio, Slack, Lemon Squeezy and Paddle webhook handlers.
Related
- Hiding Pro features in the UI isn't a paywall: enforce paid plans in Supabase RLS
- Don't store roles or plans in Supabase user_metadata