Your first check is free. No card needed.Run a free security check

Can users unlock paid features without paying? Stripe in an AI-built app

They can if your app decides who has paid from anything the browser controls: a price sent from the page, a visit to the success URL, a plan column the user can update, or a webhook endpoint that does not verify Stripe's signature. Look prices up on the server, grant access only from a verified, idempotent webhook or a server-side check of the Checkout Session, and keep the plan field out of the user's reach.

Imagine your pricing page sends people to Stripe Checkout with success_url set to /success?plan=pro. The success page runs supabase.from('profiles').update({ plan: 'pro' }) and shows a thank-you message. It works in every test you run.

Now imagine someone on a free account types /success?plan=pro into the address bar. They get Pro. Stripe never charged them, nothing logged an error, and the only sign is a gap between your Pro users and your Stripe payments.

Where does the price come from?

The first mistake is letting the browser say what to charge. AI tools often write a checkout function like this:

// Don't: the browser chooses the amount
const { amount, name } = await req.json()
const session = await stripe.checkout.sessions.create({
  mode: "payment",
  line_items: [{
    price_data: { currency: "usd", unit_amount: amount, product_data: { name } },
    quantity: 1,
  }],
  success_url: "https://example.com/success",
})

Anyone can call that function with amount: 100 and pay one dollar for your annual plan. Stripe accepts it, because price_data exists for "dynamic pricing when the amount isn't known ahead of time" (Stripe API). Stripe's own guidance for the session endpoint is blunt: "Don't forward arbitrary client-supplied Session parameters", and protect it with access controls and limits on repeated creation (accept a payment).

Let the browser send a plan name only, and look up the Price ID on the server:

// Do: the server maps a plan name to a Price ID it trusts
const PRICES: Record<string, string> = {
  pro_monthly: Deno.env.get("STRIPE_PRICE_PRO_MONTHLY")!,
}

const { data: { user } } = await supabase.auth.getUser() // caller's token
if (!user) return new Response("Sign in first", { status: 401 })

const { plan } = await req.json()
const price = PRICES[plan]
if (!price) return new Response("Unknown plan", { status: 400 })

const session = await stripe.checkout.sessions.create({
  mode: "subscription",
  line_items: [{ price, quantity: 1 }],
  client_reference_id: user.id,
  success_url: `${SITE_URL}/billing/done?session_id={CHECKOUT_SESSION_ID}`,
  cancel_url: `${SITE_URL}/pricing`,
})

client_reference_id ties the session to the signed-in user, taken from the verified token rather than the request body.

Is the success page proof that someone paid?

No, in both directions. Stripe says you "can't rely on triggering fulfillment only from your checkout landing page, because it's not guaranteed customers visit that page" (fulfill orders). A customer can pay and lose their connection before it loads. And anyone can open the address without paying, as in the story above.

Stripe's recommended pattern is a single server-side fulfillment function, called from the webhook and, optionally, from the landing page with the session ID. It retrieves the Checkout Session from Stripe, checks payment_status, and records that the session was fulfilled. Our rule of thumb is to also confirm that client_reference_id matches the signed-in user before granting anything on the landing page. The browser never writes the plan itself.

Does your webhook check Stripe's signature?

The webhook is where access should be granted, which makes it the endpoint to lock. This is the version to look for and remove:

// Don't: anyone who finds the URL can post this
const event = await req.json()
if (event.type === "checkout.session.completed") {
  await grantPro(event.data.object.client_reference_id)
}

Stripe signs every event in the Stripe-Signature header and asks you to verify it with the raw body, warning that "any manipulation to the raw body of the request causes the verification to fail" (webhooks). In a Supabase Edge Function, which runs on Deno, that means req.text() and the async verifier, as in Supabase's own example (Supabase example):

const cryptoProvider = Stripe.createSubtleCryptoProvider()

const signature = req.headers.get("Stripe-Signature")
const body = await req.text() // raw body, before any JSON parsing
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 })
}

That example is deployed with JWT verification turned off, because Stripe cannot send a Supabase sign-in token. The signature check is then the only lock on the function. In a Next.js route handler, Stripe's example passes await req.text() to stripe.webhooks.constructEvent and returns 400 on failure (stripe-node example).

Keep the libraries' default five-minute timestamp tolerance; Stripe says a tolerance of 0 "disables the recency check entirely".

What happens when Stripe sends the same event twice?

It will, sooner or later. Stripe says endpoints "might occasionally receive the same event more than once", retries failed deliveries for up to three days in live mode, and does not guarantee event order (webhooks). Its fulfillment guide adds that your function "might be called multiple times, possibly concurrently, for the same Checkout Session".

If a duplicate adds 100 credits twice, that is a free top-up. Record each event ID with a unique key and skip ones you have seen:

create table public.stripe_events (
  id text primary key,
  type text not null,
  received_at timestamptz not null default now()
);
alter table public.stripe_events enable row level security;
-- no policies: only the webhook, using the secret key, writes here
const { error } = await admin
  .from("stripe_events")
  .insert({ id: event.id, type: event.type })
if (error?.code === "23505") return new Response("Already handled", { status: 200 })

Better still, make the grant itself idempotent: upsert the subscription by its Stripe ID, or store fulfilled session IDs under a unique constraint. Return a 2xx quickly; Stripe counts a timeout as a failed delivery and tries again.

Who can write the plan column?

A perfect webhook does not help if the user can set plan = 'pro' themselves. If entitlements sit in a profiles row with an "update your own row" policy, read can a user make themselves admin? and move them out of the user's reach. Write subscription state only from the webhook, using a secret key that stays on the server.

That key belongs nowhere near the browser. Stripe: "Only publishable keys are safe to expose outside your application's back end" (API keys). Search your live app's scripts for sk_live_, sk_test_ and rk_; if one turns up, follow what to do when a key is exposed. Lovable, for one, stores the key as a backend secret named STRIPE_SECRET_KEY, and its docs say to ask it to set up webhooks if you need them for fulfillment (Lovable docs). For anything that grants access, you do.

The checklist

CheckBad signGood sign
PriceAmount or price_data built from the requestPrice ID looked up on the server
Session endpointWorks signed out, no limitsRequires sign-in, limits repeat calls
Success pageWrites the plan from the browserServer retrieves the session, or only shows status
Webhook signaturereq.json() then actRaw body plus constructEvent or constructEventAsync
DuplicatesCredits added per deliveryEvent or session ID stored under a unique key
Secret keysk_ or rk_ in browser scriptsOnly pk_ in the browser
Plan columnUser can update itOnly the server writes it

Test it on your own app in Stripe test mode

Run these against your own endpoint, in test mode or on staging.

  1. Unsigned request. Send a fake event with no signature:
curl -i -X POST https://YOUR-PROJECT.supabase.co/functions/v1/stripe-webhook \
  -H "Content-Type: application/json" \
  -d '{"id":"evt_fake","type":"checkout.session.completed","data":{"object":{"id":"cs_fake"}}}'

Expect a 400 and no change in your database. A 200 is the thing to fix today.

  1. Signed events. Forward real test events with the Stripe CLI: stripe listen --events checkout.session.completed --forward-to localhost:54321/functions/v1/stripe-webhook, then stripe trigger checkout.session.completed. Expect a 200.
  2. Duplicates. Open a delivered test event in the Dashboard and click Resend (it works for 15 days after the event). Expect one grant, not two.
  3. Success URL. Signed in as a free test account, open your success address directly with a made-up session ID. Expect no upgrade.
  4. Price. In the developer tools, copy your checkout request with Copy as fetch, change the plan or amount, and run it. Expect a 400, or Stripe's page showing your real price.

Where does Saqr fit?

Saqr does not read your code or your Stripe dashboard, and it does not test webhooks. What it can do on a Full task, signed in with a test login you provide, is try fields a user should not control, such as role or price, and admin pages an ordinary account can reach. A Deep task on the Pro plan also follows multi-step flows such as checkout. Every finding shows the request and response behind it, with a fix prompt for your AI coding tool. Your first check is free, no card needed.

Saqr (usesaqr.com) is AI security for web apps. Its AI agents attack your live app from the outside, the way a real attacker would, and show you exactly what to fix. From $19 a month, cancel any time. Tests only apps you have shown are yours.

Questions

Does Stripe Checkout stop someone from changing the price?

Stripe charges whatever your server put in the Checkout Session. If your server built the session from an amount the browser sent, the hosted page will show and charge that amount, so the protection has to be in your session-creation code.

Is my Stripe publishable key in the front end a problem?

No. Stripe marks publishable keys starting with pk_ as safe to expose; they cannot create charges or read account data. Secret and restricted keys are the ones to keep on the server.

Should I also allowlist Stripe's IP addresses?

Stripe recommends both IP allowlisting and signature verification. On hosted functions where you cannot filter by IP, the signature check is the part you cannot skip.

How do I handle cancellations and failed renewals?

Listen for subscription events such as customer.subscription.updated and customer.subscription.deleted and update access from them, using the same signature check and duplicate handling. Do not wait for the user to visit a page.

My AI tool wrote the webhook. How can I tell if it verifies signatures?

Look for constructEvent or constructEventAsync called with the raw body from req.text(). If the handler parses JSON first and acts on it, or wraps verification in a check that skips it when no secret is set, it is not verifying.