Short answer
Your Stripe webhook URL is public and has to run with verify_jwt off, so the only proof that an event really comes from Stripe is the Stripe-Signature header. A handler that parses req.json() and upgrades a plan without verifying that signature can be fed fake ‘payment succeeded’ events. Read the raw body, verify it with stripe.webhooks.constructEventAsync and your endpoint secret, reject everything that fails, and only then act on the event.
Ask an AI about this page:ChatGPTClaude
On this page
A Stripe webhook without a signature check believes any request that looks like a Stripe event. The endpoint is public, so whoever finds its URL can post a made-up “checkout completed” event and your app will mark them as paid, add credits or unlock a plan. It is rated high because it turns a simple HTTP request into free access to what you sell, and because the endpoint must stay public by design: the signature is the only thing that proves the sender.
Why it matters
Stripe states the risk plainly in its webhook docs: without verification, an attacker could send fake events “to trigger actions like fulfilling orders, granting account access, or modifying records.” Stripe signs every event it sends with a secret that only Stripe and you know, and puts the signature into the Stripe-Signature header. Checking it is the whole defense.
In Supabase apps the risk has an extra twist. A webhook function must run with verify_jwt = false, because Stripe has no Supabase token; Supabase’s function configuration docs use the Stripe webhook as the main example for that setting and warn that it lets anyone invoke the function. Once that platform check is off, your code is the only gate.
AI tools often generate a handler that works in testing and skips verification entirely:
import { createClient } from "npm:@supabase/supabase-js@2";
const admin = createClient(Deno.env.get("SUPABASE_URL")!, Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!);
Deno.serve(async (req) => {
const event = await req.json(); // anyone can send this
if (event.type === "checkout.session.completed") {
await admin.from("profiles").update({ plan: "pro" }).eq("id", event.data.object.client_reference_id);
}
return Response.json({ received: true });
});Nothing in this code asks where the request came from, and it upgrades whatever user ID the body names.
How to find it in your app
Find your webhook handlers and check for a signature verification before the first action:
grep -rln "checkout.session.completed\|invoice.paid\|customer.subscription" supabase/functions src/app/api 2>/dev/null
grep -rn "constructEvent\|stripe-signature\|STRIPE_WEBHOOK_SECRET" supabase/functions src/app/api 2>/dev/nullA file in the first list that is missing from the second list is unverified. Also watch for three half-fixes:
- The signature is read but the result is ignored, or an error only logs and the code continues.
- The body is parsed with
req.json()first and re-stringified for verification. That changes the bytes and makes verification fail, which tempts people to remove it. - Verification uses the synchronous
constructEvent. On Deno it throws, as Supabase’s docs note, which again tempts people to remove it.
How to fix it
Read the raw body as text, verify it with the async API, and act only on the verified event. This follows the Stripe example in Supabase’s edge function docs:
import { createClient } from "npm:@supabase/supabase-js@2";
import Stripe from "npm:stripe";
const stripe = new Stripe(Deno.env.get("STRIPE_SECRET_KEY")!);
// Deno has no synchronous Node crypto: verify with the async API and Web Crypto.
const cryptoProvider = Stripe.createSubtleCryptoProvider();
const admin = createClient(Deno.env.get("SUPABASE_URL")!, Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!);
Deno.serve(async (req) => {
const signature = req.headers.get("stripe-signature") ?? "";
const body = await req.text(); // the raw body, exactly as Stripe sent it
let event: Stripe.Event;
try {
event = await stripe.webhooks.constructEventAsync(
body,
signature,
Deno.env.get("STRIPE_WEBHOOK_SECRET")!,
undefined,
cryptoProvider,
);
} catch {
return new Response("Invalid signature", { status: 400 });
}
if (event.type === "checkout.session.completed") {
const session = event.data.object;
if (session.payment_status === "paid" && session.client_reference_id) {
await admin.from("profiles").update({ plan: "pro" }).eq("id", session.client_reference_id);
}
}
return Response.json({ received: true });
});And keep the platform check off for this one function only:
[functions.stripe-webhook]
verify_jwt = falseA few details matter:
- The secret is the endpoint’s
whsec_…signing secret, stored as an Edge Function secret. Test and live mode have different secrets. - Leave the tolerance alone. Stripe’s libraries reject events whose timestamp is more than 5 minutes old by default; Stripe warns that a tolerance of
0disables the recency check. - Trust only what you set yourself.
client_reference_idshould be the user ID your server put on the Checkout Session when it created it, not something the browser chose. - Return 400 on failure so the request is refused. Legitimate events that fail because of a configuration mistake show up as failed deliveries in Stripe’s dashboard, and Stripe retries them.
Verified events can still arrive twice. Pair this fix with idempotent event handling so a retried delivery doesn’t grant access or credits again. The Stripe security guide covers checkout, subscriptions and paywalls around it.
In the Stripe webhook edge function (supabase/functions/stripe-webhook/index.ts, or wherever Stripe events are handled), verify every request before acting on it: read the raw body with await req.text(), read the stripe-signature header, and call stripe.webhooks.constructEventAsync with the body, the signature, the STRIPE_WEBHOOK_SECRET secret and Stripe.createSubtleCryptoProvider(). Return 400 and do nothing else when verification throws. Use only the verified event object afterwards; never parse req.json() for this endpoint.
Keep verify_jwt = false for this function only. Do not log the webhook secret. Only act on checkout sessions whose payment_status is paid, and take the user id from client_reference_id that our server set when creating the session.
Check that the fix works
- Send an unsigned request to your own endpoint:
curl -X POST https://your-project.supabase.co/functions/v1/stripe-webhook -d '{"type":"checkout.session.completed"}'. It must answer 400, and no row may change. - Run
stripe listen --forward-to <your function URL>andstripe trigger checkout.session.completedwith the Stripe CLI, using the secretstripe listenprints. The event must be accepted with 200. - In the Stripe dashboard, open the endpoint’s event deliveries. After deploying, real events must show as delivered, not failed.
- Search the function once more: no
req.json()may remain before the verification.
Frequently asked questions
Why does verification fail even though my secret is right?
Usually because the body was changed before verification. Stripe’s docs say verification needs the raw request body, and any manipulation makes it fail. In an edge function, read it with await req.text() and pass that string, not a re-serialized JSON object.
Which secret do I use: the API key or the webhook secret?
The endpoint’s signing secret, which starts with whsec_. Stripe generates one per endpoint, and test and live mode have different ones. The Stripe CLI’s stripe listen prints its own secret for local testing.
Can I turn verify_jwt off for the webhook function?
Yes, you have to: Stripe doesn’t send a Supabase token. Supabase’s docs show exactly this setup for Stripe. The signature check in your code then replaces the platform check, so it must never be skipped.
Is checking the Stripe IP addresses enough?
Stripe recommends IP allowlisting in addition to signature verification, not instead of it. The signature also proves that the payload wasn’t changed.
Sources
- 1.Receive Stripe events in your webhook endpoint — Stripe Docs
- 2.Manage webhook endpoints — Stripe Docs
- 3.Securing Edge Functions — Supabase Docs
- 4.Function Configuration — Supabase Docs
- 5.CWE-345: Insufficient Verification of Data Authenticity — MITRE