PatchPaste · Guides

Last updated 31 October 2026

Stripe webhook in a Supabase Edge Function: verify the signature

Your AI builder added Stripe, a test payment went through, and the paid feature unlocked. But does your webhook check that the request really came from Stripe? If it doesn't, anyone who finds the URL can send a fake “payment succeeded” event and get your product for free.

Short answer: read the body with await req.text(), pass it with the Stripe-Signature header and your whsec_ signing secret to stripe.webhooks.constructEventAsync(...), and return a 400 if it throws. Deploy that one function with verify_jwt = false, because the signature is its lock. Unlock paid features only there, never from the success page (Supabase's Stripe webhook example, Stripe docs).

Why an unchecked webhook is dangerous

Stripe's docs put it plainly: “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). A webhook function with verify_jwt off and no signature check is an open door: it does whatever the JSON says.

AI tools get this wrong in two common ways. They parse the body with req.json() and skip the check because it “failed”, or they unlock the feature on the /success page, which anyone can open without paying.

Step 1: keep the secrets out of the browser

ValueWhere it belongs
Stripe secret key (sk_live_, sk_test_)Edge Function secret, for example STRIPE_API_KEY
Webhook signing secret (whsec_)Edge Function secret, for example STRIPE_WEBHOOK_SIGNING_SECRET
Publishable key (pk_)Fine in the frontend
supabase secrets set STRIPE_API_KEY=sk_live_... STRIPE_WEBHOOK_SIGNING_SECRET=whsec_...

Each endpoint has its own signing secret. Stripe's docs say the secret the Stripe CLI prints for stripe listen is different from a Dashboard endpoint's secret, and mixing them up is the most common cause of failed checks. More on where keys go: Supabase Edge Function secrets.

Step 2: check the signature in the function

This follows Supabase's official Stripe webhook example (also listed in Supabase's docs), with the payment handling added:

// supabase/functions/stripe-webhooks/index.ts
import Stripe from 'npm:stripe@^22'
import { withSupabase } from 'npm:@supabase/server@^1'

const stripe = new Stripe(Deno.env.get('STRIPE_API_KEY') as string)
// Deno uses the Web Crypto API, so Stripe needs this provider.
const cryptoProvider = Stripe.createSubtleCryptoProvider()

export default {
  fetch: withSupabase({ auth: 'none' }, async (req) => {
    const signature = req.headers.get('Stripe-Signature')
    // Must be the raw text. req.json() would break the signature.
    const body = await req.text()
    let event
    try {
      event = await stripe.webhooks.constructEventAsync(
        body,
        signature!,
        Deno.env.get('STRIPE_WEBHOOK_SIGNING_SECRET')!,
        undefined,
        cryptoProvider
      )
    } catch (err) {
      return new Response('Bad signature', { status: 400 })
    }

    if (event.type === 'checkout.session.completed' ||
        event.type === 'checkout.session.async_payment_succeeded') {
      const session = event.data.object
      if (session.payment_status === 'paid') {
        // Unlock here, using IDs from the session (for example
        // session.client_reference_id), never from the browser.
        // Skip it if you've already handled event.id.
      }
    }
    return Response.json({ ok: true })
  }),
}

Why constructEventAsync: Edge Functions run on Deno, so the check uses the Web Crypto provider and the async version of the function.

Step 3: turn verify_jwt off for this function only

Stripe can't send a Supabase login token, so the platform's JWT check would reject every event. Supabase's example says to deploy the webhook with verify_jwt = false:

# supabase/config.toml
[functions.stripe-webhooks]
verify_jwt = false

# or when deploying
supabase functions deploy stripe-webhooks --no-verify-jwt

This is only safe because the signature check in Step 2 replaces it. Keep verify_jwt on for every function your users call (Supabase docs: Securing Edge Functions).

Step 4: unlock from the webhook, not the success page

Step 5: test it

stripe listen --forward-to https://<project-ref>.supabase.co/functions/v1/stripe-webhooks
stripe trigger checkout.session.completed

Then try the fake: send a POST with made-up JSON and no valid signature. You should get a 400 and nothing should unlock. If something unlocks, your function isn't checking the signature.

A prompt you can paste into Lovable, Bolt or Cursor

Make my Stripe webhook Edge Function verify every request. Read the raw body with await req.text(), get the Stripe-Signature header, and call stripe.webhooks.constructEventAsync(body, signature, Deno.env.get('STRIPE_WEBHOOK_SIGNING_SECRET'), undefined, Stripe.createSubtleCryptoProvider()). Return 400 and do nothing if it throws. Keep the Stripe secret key and signing secret in Edge Function secrets only, never in frontend code or any VITE_ variable. Set verify_jwt = false for this function only. Only unlock paid features inside the webhook when payment_status is 'paid' (also handle checkout.session.async_payment_succeeded), skip event IDs already handled, and remove any unlocking from the success page.

Quick checklist

Before launch, run the full Lovable/Bolt pre-launch checklist. Also see is my Lovable app secure?

Stripe webhook FAQ

How do I verify a Stripe webhook in a Supabase Edge Function?

Read the raw body with await req.text(), take the Stripe-Signature header, and call await stripe.webhooks.constructEventAsync(body, signature, Deno.env.get('STRIPE_WEBHOOK_SIGNING_SECRET'), undefined, Stripe.createSubtleCryptoProvider()). If it throws, return a 400 and do nothing. This is the pattern in Supabase's own Stripe webhook example.

Why does my Stripe webhook say 'No signatures found matching the expected signature for payload'?

Stripe's docs say at least one of the three inputs is wrong: the body, the signature header or the endpoint secret. The usual causes are using the wrong whsec_ secret (the Stripe CLI and each Dashboard endpoint have different ones) or parsing the body with req.json() before checking it. The body must be the exact text Stripe sent.

Why use constructEventAsync instead of constructEvent in Deno?

Edge Functions run on Deno, which uses the Web Crypto API. Supabase's example creates Stripe.createSubtleCryptoProvider() and passes it to the async version, constructEventAsync.

Should verify_jwt be off for a Stripe webhook function?

Yes, for that one function only. Stripe doesn't send a Supabase login token, so Supabase's example says to deploy it with verify_jwt = false. That's only safe because the function checks Stripe's signature itself. Keep verify_jwt on for every function your users call.

Can I unlock a paid feature from my Stripe success page?

No. Anyone can open the success URL without paying, and anything decided in the browser can be faked. Unlock the feature only in the webhook after the signature checks out, and only when the Checkout Session's payment_status is paid.

Is it safe to put the Stripe webhook secret in my frontend?

No. The whsec_ signing secret and your sk_live_ key belong in Edge Function secrets, read with Deno.env.get. Only the publishable pk_ key belongs in the browser.

Does PatchPaste test my Stripe webhook?

No. PatchPaste scans your live site from the outside, so it can't see your Edge Functions. It does search the JavaScript your site ships for Stripe secret keys (sk_live_) and other admin keys, which is how a leaked Stripe key is usually found.

Is your Stripe secret key in your live app?

PatchPaste can't see your webhook, but it does search the JavaScript your site sends to every visitor for Stripe secret keys and other admin keys (shown masked), and checks common Supabase tables, exposed files and headers. The report is free.

Free. No login. No code access.

Want to see one first? View a sample report.