The code calls constructEvent, the tests pass, and the endpoint still accepts a fake checkout.session.completed. The verification runs, but when it fails the handler keeps going. Stripe's warning applies in full: "Without verification, an attacker could send fake webhook events to your endpoint to trigger actions like fulfilling orders, granting account access, or modifying records" (Stripe docs: Verify events).
Stripe's libraries tell you when verification fails: "If verification fails, you get an error" (Stripe docs: Receive events). Fail-open code catches that error and doesn't stop. These are the patterns to search for:
catch (or except) block logs "signature failed" and then falls through to code that parses req.body and fulfills it.event = JSON.parse(body) "so it still works". That line is the forgery path.if (sig) { constructEvent(...) }. A forged request simply leaves out Stripe-Signature.if (!process.env.STRIPE_WEBHOOK_SECRET) { /* dev mode */ }. One missing env var in production and every event is trusted.SKIP_WEBHOOK_VERIFY=true set while debugging and never removed.secret, destination, and payload entries aren't covered by the HMAC. Don't use them to authenticate a request" (source). Only a valid v1 signature counts.AI builders produce these when asked to "fix the signature error". The real fix for that error is the raw body or the right whsec_ secret (signature verification failed), not catching it.
Verify first, and return 400 from the catch block before anything else runs. Stripe's own Express example does exactly this: on error it logs and sends res.status(400), then returns (stripe-node example: Express webhook). The Ruby and Python examples in Stripe's docs return 400 the same way (source).
// Next.js App Router (route.ts). Same shape works in Express or a Supabase Edge Function.
const secret = process.env.STRIPE_WEBHOOK_SECRET;
export async function POST(req: Request) {
if (!secret) return new Response("webhook secret not configured", { status: 500 }); // never skip
const sig = req.headers.get("stripe-signature");
if (!sig) return new Response("missing signature", { status: 400 });
const body = await req.text(); // raw body, byte for byte
let event;
try {
event = stripe.webhooks.constructEvent(body, sig, secret);
} catch (err) {
console.error("stripe signature failed", (err as Error).message);
return new Response("bad signature", { status: 400 }); // stop here
}
// Only verified events reach this line.
await handleEvent(event); // your helper: idempotent on event.id
return new Response("ok", { status: 200 });
}
Helper names are placeholders. In Python, return 400 from the except and never fall through to json.loads.
Two rules make the pattern hard to break later: the only event your handler ever sees comes out of constructEvent, and a missing secret is a server error (500), not a reason to skip.
Green tests that only send good events can't catch a fail-open handler. Add negative tests against your webhook route:
Stripe-Signature header: expect 400 and no database change.stripe listen + stripe trigger, Stripe docs: test webhooks): expect 200 and exactly one fulfillment.Run tests 1 and 2 against production too after each deploy, so a missing env var shows up as a 500 instead of open doors: curl -i -X POST -H 'content-type: application/json' -d '{}' https://yourdomain.com/api/webhooks/stripe should return 400, not 200.
Our Stripe webhook must fail closed. 1) Read the raw request body and the Stripe-Signature header. If STRIPE_WEBHOOK_SECRET is not set, return 500; never skip verification. If the header is missing, return 400. 2) Call stripe.webhooks.constructEvent(rawBody, signature, secret) inside try/catch; in the catch, log the message and return 400 immediately. Do not parse the body any other way and do not continue after a failed check. 3) Remove any SKIP/dev flags that bypass verification. 4) Add tests: no signature returns 400, wrong-secret signature returns 400, a valid signed event returns 200 and fulfills exactly once (dedupe on event.id).
4242 4242 4242 4242 and confirm the delivery returned 2xx and the user was unlocked.Paste your webhook URL. WebhookProof sends 3 harmless test requests and tells you whether Stripe can reach it and whether it rejects unsigned events. If it finds a problem, the $9 fix pack gives you the exact copy-paste fix for your stack (refundable for 14 days).
Run the free checkUsually the error from constructEvent is caught and the handler keeps going, or verification only runs when the Stripe-Signature header or the webhook secret is present. Return 400 from the catch block and never process an event that did not come out of constructEvent.
Stripe's own examples return 400 when signature verification fails. Return it before any fulfillment code runs.
Treat it as a server error and return 500 so the failure is visible and Stripe retries. Never skip verification because the secret is missing.
Send a request with no Stripe-Signature header and one signed with the wrong secret. Both should return 400 with no change in your database. A correctly signed test event should return 200.
Stripe webhook not working? Check these 7 things in order · A customer paid but didn't get access. What went wrong? · No signatures found matching the expected signature for payload · Stripe webhook failing with a 307 or 308 redirect
Last reviewed 2026-11-13. WebhookProof is an independent tool, not affiliated with Stripe, Inc.. Quotes are from the linked documentation.