🔧 Unbreak My AppAll fixesError codesFix KitsSponsor

Fixes › Payments

Users can change the price at checkout: stop trusting amounts sent from the browser to Stripe

LovableBoltCursorReplitv0

Published

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

The error

A customer paid $1 (or $0.50) for a $79 plan, the Stripe Checkout Session or PaymentIntent shows an amount you never set, or your create-checkout endpoint accepts a request body like {"amount": 7900} or {"price": 79}

Why it happens

AI builders often generate a checkout flow where the frontend sends the price, amount, currency or quantity to your API route or Supabase edge function, and the server passes it straight into stripe.checkout.sessions.create or stripe.paymentIntents.create using price_data or amount. Anything sent from the browser can be edited in DevTools, replayed with curl, or changed in the request, so a user can pay whatever they like. The same flaw shows up as trusting a client-sent discount, a client-sent plan name mapped to an amount the client also controls, unlimited quantity, or granting access on the success page instead of from a verified webhook. The fix is that the server alone decides what is being sold and for how much, using Prices you created in Stripe or a server-side price table.

How to fix it

  1. Test it yourself in Stripe test mode: open DevTools → Network, click your Buy button, find the request to your checkout endpoint and look at its body. If it contains an amount, price, unit_amount, currency or discount value, it can be tampered with.
  2. Create a Product and a Price in the Stripe Dashboard (test mode first) for every plan or item, and copy the Price IDs (they start with price_).
  3. Change the frontend to send only what the customer chose, such as a plan key ('pro_monthly') or a product ID from your own database, never an amount.
  4. On the server, map that key to a Price ID with an allow-list (for example const PRICES = { pro_monthly: process.env.STRIPE_PRICE_PRO_MONTHLY }) and reject anything not in the list with a 400 error.
  5. Create the Checkout Session with line_items: [{ price: PRICES[plan], quantity: 1 }] instead of price_data or amount. If customers can choose a quantity, clamp it on the server to a sensible range, or use Stripe's adjustable_quantity with a maximum.
  6. Handle discounts with Stripe Coupons and Promotion Codes (allow_promotion_codes: true or a server-chosen coupon), never with a percentage or amount sent from the browser.
  7. Grant access or fulfil orders only from the checkout.session.completed webhook after verifying the Stripe signature, and check the amount_total and the line items' price IDs match what you expect before unlocking anything.
  8. Look back through Payments in the Stripe Dashboard for charges below your real prices, and revoke or follow up on any access that was bought at a tampered price.

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

Audit my Stripe checkout for price tampering. My checkout is created in <FILE / API ROUTE / SUPABASE EDGE FUNCTION> and the frontend calls it from <FILE>. Right now the request body sent from the browser is: <PASTE>. Change it so the browser only sends a plan key or product ID, and the server maps that to a Stripe Price ID from an allow-list read from environment variables (reject unknown keys with a 400). Create the Checkout Session with line_items using price IDs only, never price_data, amount or unit_amount from the request. Clamp any quantity on the server, move discounts to Stripe promotion codes, and make sure access is granted only in the checkout.session.completed webhook after verifying the signature with the webhook secret and checking amount_total and the price IDs. Use test mode keys, don't put the secret key in frontend code, and don't print any keys.

FAQ

Isn't Stripe Checkout secure already?

Stripe's payment page is secure, but it charges whatever your server tells it to. If your server copies the amount from the browser, the customer is choosing the price.

Can I just validate the amount on the server?

You can, but it's easier and safer to use Price IDs from Stripe and never accept an amount at all. Then there's nothing to validate.

What about pay-what-you-want or donations?

Use Stripe's customer-chosen price option on a Price, or enforce a server-side minimum and maximum, and still never trust other fields from the browser.

How do I know if someone already did this?

Filter Payments in the Stripe Dashboard by amount and compare against your real prices, and check your webhook logs for sessions whose amount_total doesn't match a known plan.

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.