🔧 Unbreak My AppAll fixesError codesFix KitsSponsor

Fixes › Payments

Visiting the success page unlocks Pro without paying: grant access from the Stripe webhook, not the redirect

LovableBoltCursorReplitv0

Published

Weakness type: CWE-602 (Client-Side Enforcement of Server-Side Security)

The error

Anyone who opens /success or /thank-you?session_id=... gets Pro access, users who close the tab after paying never get upgraded, or your app sets is_pro=true from the browser after Stripe Checkout redirects back

Why it happens

AI builders often generate a checkout flow where Stripe redirects to a success_url and the success page itself (or a fetch it makes) marks the user as paid, for example by calling supabase.from('profiles').update({ is_pro: true }) from the browser or hitting an unauthenticated /api/upgrade route. The redirect is just a URL: it can be opened, bookmarked, shared or replayed without any payment, and the session_id in it is not checked. It also fails the other way: if the customer closes the tab, loses connection or pays with a delayed method like a bank debit, the success page never runs and a paying customer stays on the free plan. Stripe's own guidance is to fulfil orders from the checkout.session.completed webhook (and async_payment_succeeded for delayed methods), verified with your webhook signing secret, and to treat the success page only as a friendly message.

How to fix it

  1. Test it in Stripe test mode: log in as a free user in a private window and open your success URL directly (for example /success or /success?session_id=cs_test_fake). If the account becomes Pro, you have this bug.
  2. Remove every place the browser can set paid status: no client-side update of is_pro, plan or credits, and add a Supabase RLS policy (or server check) so users cannot update those columns on their own row.
  3. Create a webhook endpoint on your server or a Supabase edge function, and in the Stripe Dashboard (test mode first) subscribe it to checkout.session.completed, checkout.session.async_payment_succeeded and, for subscriptions, customer.subscription.updated and customer.subscription.deleted.
  4. In the webhook, read the raw request body and verify it with stripe.webhooks.constructEvent and your STRIPE_WEBHOOK_SECRET. Reject anything that fails verification with a 400.
  5. Identify the user from data you set on the server when creating the Checkout Session, such as client_reference_id or metadata.user_id, never from the success URL.
  6. Only grant access when payment_status is 'paid' (or on async_payment_succeeded), check the price IDs and amount_total match what you sell, then update the user's plan with a service-role key on the server. Record the event ID so retries don't double-grant.
  7. Make the success page read-only: show 'Payment received, unlocking your account…' and poll your own database for the plan to change, instead of changing it.
  8. Check existing Pro users against paid Checkout Sessions or active subscriptions in Stripe, and downgrade any account that was upgraded without a payment.

Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

Fix my Stripe fulfilment so access is only granted from a verified webhook. Checkout is created in <FILE / API ROUTE / EDGE FUNCTION> and my success page is <FILE>, which currently does: <PASTE WHAT IT DOES>. Remove any code that sets is_pro, plan or credits from the browser or from the success page, and add an RLS policy or server check so users can't update those fields themselves. Set client_reference_id (or metadata.user_id) to the logged-in user's ID when creating the Checkout Session. Add a webhook handler that verifies the Stripe signature with STRIPE_WEBHOOK_SECRET using the raw body, handles checkout.session.completed and checkout.session.async_payment_succeeded (plus customer.subscription.updated and customer.subscription.deleted for subscriptions), only grants access when payment_status is paid and the price IDs match, stores processed event IDs to stay idempotent, and updates the user with the service-role key on the server. Make the success page only show a message and poll for the upgrade. Use test mode keys and never print or expose any secret.

FAQ

Can't I just check the session_id on the success page?

You can retrieve the session on the server to show a nicer message, but you still need the webhook, because many customers never reach the success page and delayed payment methods aren't paid yet when they do.

Why does it work in my testing but not for real customers?

In testing you always wait for the redirect. Real customers close tabs, lose signal or use bank payments that settle later, so a success-page-only flow silently misses paid users.

Will the webhook arrive before the success page loads?

Not always. Show a short 'unlocking your account' state and poll your database, or retrieve the session server-side, so the page handles both orders.

Do I need the webhook for one-time payments too?

Yes. The same rule applies to one-off purchases, credits and lifetime deals: fulfil from checkout.session.completed after verifying the signature.

Sources

Based on the official documentation:

Related fixes

Want the full checklist for this area? Get a Fix Kit ($29)

Get one new fix a week

Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.

We only use your email to send the newsletter. Unsubscribe any time. See privacy.