Anything the browser sends can be changed by the person using it, so your server has to decide the price, the quantity and when an order counts as paid. That means looking up prices on the server, verifying the signature on every Stripe webhook before acting on it, making payment and fulfillment code safe to run twice, and letting only server code mark an order paid. Test all of it in Stripe's sandbox with test cards, never with real ones.
Why do AI-built checkouts trust the browser?
Usually because nobody stated the rule. In a test run by Tenzai, a security startup, five AI coding agents (Claude Code, Codex, Cursor, Replit and Devin) each built the same three apps from identical prompts. None of the 15 apps had an exploitable SQL injection or cross-site scripting flaw. Yet four of the five agents allowed negative order quantities when the prompt did not say orders must be positive, and three of the five allowed products with a negative price (SecurityWeek, January 2026). It is a vendor's test, and the pattern is easy to check in your own code.
An academic audit of 200 deployed apps written mostly by AI points the same way. Its authors traced 55.5% of the vulnerabilities they confirmed to hidden security rules, meaning requirements the builder never stated (arXiv preprint, not peer reviewed). A price must be positive is a hidden rule. So is only the server can mark an order paid.
The database can be just as trusting. In 2025, researcher Matt Palmer analyzed 1,645 projects showcased by Lovable and found 170 with inadequate row-level security. In a follow-up test he sent a crafted request that inserted a record with its payment status set to paid, bypassing the Stripe integration (Palmer's statement). If the browser can write to your orders table, the browser can decide who has paid.
Look up the price on the server
The browser should send only what the customer chose. Your server works out everything else.
- Accept a product or plan ID and a quantity from the client, and nothing that sets an amount.
- Look up the price in your own database, or use a Stripe Price ID that your server selects. Stripe's own Checkout examples pass a Price ID in the line items.
- Reject quantities that are zero, negative, fractional or above a sensible maximum.
- Validate discount codes on the server, including whether they have expired or already been used.
- Set the currency on the server.
- After payment, compare what was paid with what you expected before you fulfill. Stripe's fulfillment guide has you retrieve the Checkout Session with its line items before fulfilling, which gives you the data to compare.
How does Stripe webhook signature verification work?
A webhook is a message Stripe sends to your server when something happens, such as a completed checkout or a successful payment. Your webhook endpoint is a public URL, so anyone can send it a request that looks like a Stripe event. Stripe's webhook docs warn that without verification, an attacker could send fake events to trigger actions like fulfilling orders, granting account access or modifying records. Its integration security guide says you must verify webhook signatures.
Stripe signs each event it sends. The Stripe-Signature header carries a timestamp and an HMAC signature made with SHA-256 over the timestamp and the exact request body, using a signing secret unique to your endpoint. That secret starts with whsec_, and it differs between test and live mode. Verify every event with these steps.
- Read the raw request body. Stripe needs the raw body, and any change to it, including a framework parsing the JSON first, makes verification fail.
- Pass the raw body, the Stripe-Signature header and your endpoint secret to Stripe's official library, which Stripe recommends over writing your own check.
- If verification fails, reject the request with an error status and do nothing else with it.
- Keep the library's default five-minute tolerance on the timestamp to block replayed events. Stripe warns that a tolerance of zero disables the recency check entirely. Keep your server clock synced with NTP.
- Fail closed. If the signing secret is missing from your environment, refuse every event instead of skipping the check.
- Return a 2xx response quickly and do heavy work in a queue, because Stripe counts timeouts and redirects as failed deliveries.
Stripe also recommends allowlisting its published webhook IP addresses and rolling your signing secrets periodically. When you roll a secret, you can keep the old one active for up to seven days while you update your code. If you write verification by hand, use a constant-time comparison and accept the event if any v1 signature in the header matches, since more than one can appear during a rollover.
Make every payment step safe to repeat
Networks fail and messages repeat. Stripe says webhook endpoints might occasionally receive the same event more than once, that it does not guarantee events arrive in the order they were created, and that it retries failed deliveries for up to three days in live mode. Your code has to give the same result whether it runs once or five times.
- Webhooks. Log every event ID you process and skip any you have already handled. A unique constraint on the event ID in your database makes this hard to get wrong.
- Fulfillment. Stripe's fulfillment guide says your fulfillment function might be called multiple times, possibly at the same moment, for the same Checkout Session. It must handle that, check the session's payment status before doing anything, and record that fulfillment happened.
- API calls. An idempotency key is a unique value you send with a request so that a retry is recognized as the same request. Stripe's idempotency docs say every POST request accepts one, and that with a key you can safely repeat a request without creating a second object or performing an update twice. Stripe suggests V4 UUIDs, allows keys up to 255 characters, warns against using email addresses or other personal data as keys, and returns an error if a retry's parameters differ from the original.
- Ordering. Do not assume a payment event arrives after the event that created the order. When something is missing, fetch the current object from Stripe's API.
Let only the server mark an order paid
An order state machine is a short list of the statuses an order can be in, plus rules for which moves are allowed and who can make them. Writing it down turns a hidden rule into a stated one.
| Status | Who can set it | What triggers it |
|---|---|---|
| Draft | The customer, through your server | Items added to a cart |
| Awaiting payment | Your server | A Checkout Session or PaymentIntent created at a server-set price |
| Paid | Only your webhook handler or server-side fulfillment code | A verified Stripe event, with the session's payment status checked |
| Fulfilled | Only server-side fulfillment code | Fulfillment runs once and is recorded |
| Refunded or canceled | Your server, from an admin action or a verified Stripe event | A refund, a dispute or a cancellation |
Three rules make this hold. First, the client never writes the status field. If you use Supabase, your row-level security policies must block inserts and updates to payment fields from the browser, and our Supabase row-level security guide shows how. Second, the success page is only a receipt. Stripe says webhooks are required for fulfillment, because a customer can pay and lose their connection before your landing page loads, and a query string such as ?paid=true proves nothing. If your landing page also triggers fulfillment, it should fetch the Checkout Session from Stripe on the server and check its payment status. Third, check ownership on every order request, so one customer can never view or change another customer's order. The two-account access test is the quickest way to prove it.
How do you test this without real cards?
Use a Stripe sandbox and your test API keys for everything. Stripe's testing docs say its Services Agreement prohibits testing in live mode with real payment method details. Test cards such as 4242 4242 4242 4242, with any future expiry date and any three-digit code, simulate payments without moving money, and decline cards such as 4000 0000 0000 0002 let you test failures. In test code, Stripe recommends test payment methods like pm_card_visa over raw card numbers. The Stripe CLI can forward events to your machine with stripe listen and send test events with stripe trigger.
Run these tests before launch, with fake records only.
- Change the price or quantity in the request from the browser. The server should ignore the price and reject a bad quantity.
- Send a negative or zero quantity, and a discount code that has expired.
- Post a fake event to your webhook endpoint with no signature, and another with a wrong signature. Both should get an error and change nothing.
- Capture a real test event and send it again after the tolerance window. It should be rejected.
- Deliver the same event twice. The order should be fulfilled once.
- Try to set an order's status to paid from the browser or straight through your database API. It should fail.
- Log in as a second test customer and try to read or change the first customer's order.
Getting help with your checkout
Start with the free two-minute self-check. It runs in your browser, asks for no email, and lists where to look first.
If you want these checks built and tested for you, our Payment Page Protection package verifies prices and payment events on the server, along with the payment page work covered in our guide to the SAQ A script rule. The Compliance Readiness Review looks at payments alongside access rules, secrets and AI features, and ties every finding to the PCI DSS, SOC 2 or HIPAA requirement it affects. For what Stripe handles and what stays with you, read our pillar guide to PCI compliance with Stripe.