Stripe in an AI-built app: 7 checks before real money
Stripe security checklist for Lovable, Bolt, Cursor and v0 apps: server-side prices, webhook signatures, duplicate events and plan columns users can edit.
Adding payments is the moment an AI-built app stops being a side project. Lovable, Bolt, Cursor and v0 can wire up Stripe Checkout in a few prompts, and the happy path usually works on the first try: you click "Upgrade", pay with the test card, land on a success page, and your account says "Pro".
The trouble is that the happy path is the only path most generated code is tested on. The bugs that cost money show up when someone does something slightly unexpected: changes a number in a request, opens the success page without paying, sends a fake event, or cancels and keeps access.
This guide covers the seven checks we would run on any vibe-coded app before switching Stripe to live mode. Most take a few minutes, and each comes with a fix you can paste back into your AI tool. The same ideas apply if you use PayPal, Lemon Squeezy or Paddle: the names change, the mistakes don't.
1. The price comes from the server, not the browser
The most direct way to lose money is letting the browser decide what to charge. AI tools sometimes generate a checkout call like this:
// browser
await fetch("/api/checkout", {
method: "POST",
body: JSON.stringify({ plan: "pro", amount: 1900 }),
});
and a server route that passes amount straight into price_data.unit_amount. Anyone can open the network tab, copy the request, change 1900 to 50 and pay 50 cents for your Pro plan.
How to check it: find the route or edge function that creates the Checkout Session (search for checkout.sessions.create). Look at where line_items comes from. If any amount, currency, quantity or discount is read from the request body, that is the bug.
The fix: create your products and prices in the Stripe dashboard and keep their price IDs on the server. The browser sends only a plan name such as "pro", and the server maps it to a price ID from a fixed list. Anything not on the list gets rejected.
Paste into your AI tool: "In the code that creates the Stripe Checkout Session, never read amounts, currency, quantity or coupons from the request. Map an allowed plan name to a Stripe price ID stored on the server and reject anything else."
2. The user comes from the session, not the request body
The second half of the checkout request is "who is paying". A common pattern is the browser sending userId along with the plan, and the server putting it in client_reference_id or metadata. When the webhook arrives later, the code upgrades whichever user ID is in the metadata.
That means a user can pay once and upgrade a different account. It is the same "trusting an ID from the request" mistake we describe in what a URL scan can't see, just with money attached.
How to check it: in the checkout route, find where client_reference_id, customer or metadata.user_id is set. It should come from the verified session or token on the server (for Supabase, the user from auth.getUser() with the caller's token), never from req.body.
The fix: get the user on the server, create or look up their Stripe customer ID from your own table, and pass that. Store the mapping between your user ID and the Stripe customer ID in a table only your server can write to.
3. The success page doesn't grant access on its own
After payment, Stripe redirects the customer to your success_url. AI-generated apps often treat reaching that page as proof of payment. The success page calls something like /api/mark-paid, or worse, it updates the user's plan directly from the browser.
Anyone can type your success URL into the address bar. If it upgrades the account, your paywall is a URL away.
Stripe's own docs on fulfilling Checkout orders say you can run fulfillment from the landing page as well as from the webhook, but only in a specific way: the server takes the session_id from the URL (you add ?session_id={CHECKOUT_SESSION_ID} to your success URL), retrieves the Checkout Session from Stripe's API with your secret key, and checks its payment_status before doing anything. The browser's word is never enough.
How to check it: sign in with a free test account and open your success URL directly, without paying. Then try it with a made-up session_id. If your account changes in either case, fix it before launch.
The fix: the webhook should be the main way access is granted. If you also want the success page to show "You're Pro" instantly, it should call a server route that retrieves the session from Stripe and runs the same fulfillment function the webhook uses.
4. The webhook verifies Stripe's signature on the raw body
Your webhook endpoint is a public URL. Anyone can send it a JSON body that looks like checkout.session.completed. The only thing that separates a real Stripe event from a fake one is the Stripe-Signature header, and the code has to check it.
In Node, that check is stripe.webhooks.constructEvent(rawBody, signature, endpointSecret). Stripe's webhook docs stress two details that AI code gets wrong:
- Use the raw body. If your framework parses the JSON first and you pass the parsed object (or a re-stringified version), verification fails. A common "fix" an AI tool suggests at that point is removing the check. Don't accept that fix.
- Keep the timestamp tolerance. Stripe's libraries reject events older than 5 minutes by default, which blocks replays of old captured events. The docs warn not to set the tolerance to
0, because that disables the recency check.
On Supabase Edge Functions, the webhook function usually runs with JWT verification off, since Stripe doesn't send a Supabase token. That's fine only if the signature check is in the code. Our guide on Supabase Edge Functions open to anyone shows how to tell which of your functions accept calls from strangers.
How to check it: open your webhook handler and search for constructEvent (or constructEventAsync on Deno and edge runtimes). Confirm it runs before any database write, on the raw text of the request. Then use the Stripe CLI (stripe listen --forward-to your local URL, then stripe trigger checkout.session.completed) to confirm real test events still work.
5. Duplicate and out-of-order events are handled
Stripe's docs are explicit: webhook endpoints can receive the same event more than once, and Stripe doesn't guarantee events arrive in the order they were created. In live mode, Stripe retries failed deliveries for up to three days.
Generated webhook code often assumes exactly one event, in order. That leads to quieter bugs:
- Credits or tokens added twice when the same event is delivered twice.
- A welcome email or invoice sent twice.
- A subscription marked active after it was cancelled, because the older "updated" event arrived last.
How to check it: look at what the handler does for each event type. If it adds something (credits = credits + 100) rather than setting a state, duplicates will double it.
The fix: store each processed event ID in a table with a unique constraint, and skip events you've already seen. For subscriptions, don't trust the order of events: when an event arrives, retrieve the current subscription from Stripe and save its actual status. That way the last write is always the truth, whichever event triggered it.
create table public.stripe_events (
id text primary key, -- Stripe event ID
type text not null,
received_at timestamptz not null default now()
);
alter table public.stripe_events enable row level security;
-- no policies: only your server (secret key) can read or write it
6. Users can't edit their own plan column
This is the one we see most often in Supabase-backed apps. The profiles table has a plan, is_pro or credits column, and an RLS policy lets users update their own row so they can change their name or avatar:
create policy "users update own profile"
on public.profiles for update
to authenticated
using (auth.uid() = id)
with check (auth.uid() = id);
That policy is about rows, not columns. Any signed-in user can open the browser console and run supabase.from('profiles').update({ plan: 'pro' }).eq('id', theirId). No payment, no webhook, no Stripe. A clean outside scan won't catch it, because the request needs a real account.
How to check it: sign in as a free test user, open the console, and try to update your own plan or credits with the Supabase client. If it works, so will everyone else's attempt. You can also list update policies with:
select tablename, policyname, roles, qual, with_check
from pg_policies
where schemaname = 'public' and cmd in ('UPDATE', 'ALL');
The fix: the cleanest option is moving billing state into its own table (for example subscriptions) with RLS on and only a select policy for the owner. Your webhook writes to it with the server key. If you'd rather keep the column, restrict which columns signed-in users can update. Note that a column-level revoke does nothing while a table-wide grant exists, so replace the table grant:
revoke update on public.profiles from authenticated;
grant update (display_name, avatar_url) on public.profiles to authenticated;
For more on how policies and grants fit together, see Supabase RLS in plain English.
7. Cancellations, refunds and failed payments remove access
Granting access is half the job. Most generated integrations only listen for checkout.session.completed, so nothing ever happens when a subscription ends. Users cancel, get a refund or let their card fail, and keep Pro forever.
How to check it: list the event types your webhook handles. For subscriptions you want at least customer.subscription.updated and customer.subscription.deleted, and usually invoice.payment_failed. For one-off payments with delayed methods (bank debits, some local payment methods), Checkout sends checkout.session.async_payment_succeeded and checkout.session.async_payment_failed, and the session can complete while still unpaid. Check payment_status before granting anything.
The fix: have one function that reads the current subscription from Stripe and sets your subscriptions row to match. Call it from every subscription event. Test it with the Stripe CLI or by cancelling a test subscription in the dashboard.
Before you flip to live mode
A few housekeeping checks that are easy to miss:
- Live keys only in production. Your local
.envand preview deployments should use test keys. The live webhook endpoint has its own signing secret, different from the test one, so set it separately. - The secret key never reaches the browser. The publishable key is meant to be public. The secret key is not. If it's in a
VITE_orNEXT_PUBLIC_variable, it's in every visitor's JavaScript. Our post on API keys in your JavaScript shows how to check. - Consider a restricted key. Stripe lets you create restricted keys that can only do what your server needs (for example, create Checkout Sessions and read subscriptions). If one leaks, the damage is smaller.
The 10-minute version
- Checkout route maps a plan name to a server-side price ID. No amounts from the browser.
- The paying user comes from the server session, not
req.body. - Opening the success URL without paying changes nothing.
- Webhook calls
constructEventon the raw body, before any write. - Event IDs are stored, so duplicates are skipped.
- A free user can't update their own plan or credits from the browser console.
- Cancellations, refunds and failed payments remove access.
For everything that isn't payments, our pre-launch security checklist covers keys, databases, files and headers.
Check your app before you take real money
Start with the outside view. Run the free Greenlight Scan on your live URL and get a traffic-light result in about a minute: it looks for secret keys in your JavaScript, weak headers and cookies, and known-vulnerable libraries. The $19 Full Scan adds deeper checks once you verify you own the site, like exposed files, open Supabase or Firebase data (counted, never downloaded) and API routes that answer without a login, with a fix prompt for your AI tool for every finding.
Most of the payment bugs above live in your code, where no outside scan can see them. If your app takes payments, the $79 Launch Audit connects read-only to your GitHub repo, scans it for committed secrets, and runs a deep AI review of your auth, database policies and payment logic, including client-set prices, unverified webhooks and plan columns users can edit. A second AI double-checks every finding before you see it, and you get a prioritized fix plan and a launch verdict. It's automated, not a pentest, so it won't replace a human review for a high-stakes app, but it catches the mistakes AI tools make most often before your customers do.
The Friday leak report
One short email a week: the newest ways AI-built apps leak data, and the one-line fix for each. No spam, unsubscribe any time.