7 Stripe Webhook Mistakes That Quietly Leak Revenue (and How to Fix Each One)
Fake payments, double credits, users who keep premium after cancelling. Most Stripe integrations we audit have at least three of these. Here's how each one happens, how to spot it in your code, and a reference handler that closes all seven.
"We just check for checkout.session.completed in the request body and upgrade the user." We hear some version of this in almost every payment audit. It works perfectly in testing, and it means anyone who finds your webhook URL can give themselves a lifetime subscription.
Integrating Stripe looks easy: create a Checkout Session, redirect the user, wait for a webhook saying they paid. But a webhook is just an HTTP request to a public URL, and Stripe's delivery model has rules that aren't obvious until they cost you money: events can arrive twice, out of order, or days late, and "checkout completed" doesn't always mean "money received".
Below are the seven mistakes we find most often when auditing Stripe integrations, roughly ordered by how much they can cost. Each one comes with how to recognise it in your own code and the fix. At the end there's a complete reference handler that closes all of them.
1.Why the Webhook Is Your Only Source of Truth
Many apps grant access on the success page: Stripe redirects the user to /success?session_id=…, and the page upgrades their account. That page is the least trustworthy place to make a billing decision. Users close the tab before the redirect, bookmark and revisit it, or simply type the URL themselves.
The success page should only say "thanks, we're confirming your payment". The decision to grant access belongs in the webhook handler, server to server, where Stripe tells you what actually happened. Which is exactly why the handler has to be bulletproof.
2.Mistake #1: Trusting an Unsigned Payload
Your webhook endpoint is a public URL, and anyone on the internet can POST to it. If the handler reads the JSON and acts on it, a forged request is indistinguishable from a real one:
Stripe signs every delivery with your endpoint's signing secret (whsec_…) and sends the signature in the Stripe-Signature header. The official SDK's constructEvent recomputes it and throws if anything doesn't match. Only events that pass are real.
The raw-body trap (why people turn verification off)
The signature is computed over the exact bytes Stripe sent. If your framework parses the JSON first and you re-serialise it, whitespace and key order change and verification fails every time. Frustrated developers then "temporarily" skip verification, and it ships that way. Make sure you hand the SDK the untouched body:
- Next.js App Router:
await req.text(), neverreq.json()before verifying. - Next.js Pages Router: disable the built-in parser with
export const config = { api: { bodyParser: false } }and read the raw stream. - Express: mount
express.raw({ type: 'application/json' })on the webhook route, before any globalexpress.json().
Each endpoint has its own signing secret, and test mode and live mode are separate. The Stripe CLI's stripe listen prints yet another one for local forwarding. A classic production outage: the live deploy is still using the test or CLI secret, every webhook fails verification, and nobody gets upgraded.
3.Mistake #2: Replays and Disabled Timestamps
A valid signature proves Stripe sent the payload once. It doesn't stop someone from sending that same signed payload again. Webhook bodies and headers end up in more places than you'd think: request logs, error trackers, debugging dumps in Slack. Anyone with one captured delivery could replay it.
The signature header includes a timestamp, and constructEvent rejects anything older than its tolerance, 5 minutes by default. Teams sometimes raise or disable that tolerance while debugging and forget to restore it. Leave the default alone, and treat the idempotency fix in the next section as your second layer: even a replay inside the window must not run your logic twice.
4.Mistake #3: Running the Same Event Twice
Stripe guarantees at-least-once delivery, not exactly-once. If your endpoint is slow, times out or returns an error, Stripe retries, in live mode for up to three days. Occasionally the same event is delivered twice even when everything went fine. If your handler adds 50 credits on payment_intent.succeeded, three deliveries mean 150 credits for one payment.
The usual fix is to remember processed event IDs. But the most common version of that fix, the one in countless tutorials, still has a hole:
Two deliveries of the same event arriving a few milliseconds apart both find nothing, both grant the credits, and only then try to record the ID. On serverless, where each delivery can land on a different instance, this isn't theoretical.
Make the event ID a unique column and insert it before doing any work. The database lets exactly one insert succeed; every duplicate fails with a unique-constraint error and stops right there. If your own logic then fails, delete the claim and return an error so Stripe's retry gets a clean second chance. The reference handler in section 9 does exactly this.
5.Mistake #4: Treating "Completed" as "Paid"
checkout.session.completed means the customer finished the checkout flow. With cards that usually coincides with payment, but with delayed payment methods (bank debits like ACH or SEPA, some vouchers) the money arrives days later, or never. Grant access on completed and you're giving the product away to every failed bank debit.
- Check
session.payment_status: grant access only when it'spaid, orno_payment_requiredfor free trials and 100% coupons. - If it's
unpaid, wait forcheckout.session.async_payment_succeededbefore granting, and handlecheckout.session.async_payment_failed. - Only offering cards today? Write the check anyway. The day someone enables a new payment method in the Dashboard, your code stays correct.
6.Mistake #5: Letting the Browser Decide the Price
Signature checks prove the event is real. They don't prove the purchase was what your app thinks it was. We often find checkout sessions created straight from request data:
Edit the request in dev tools, send the cheapest priceId with plan: 'enterprise', and a webhook that reads metadata.plan grants Enterprise for the price of Starter. The fix is to never accept a price from the client, only a plan name you map to a price on the server, and in the webhook to decide what to grant from what was actually bought: the line items' price IDs (via stripe.checkout.sessions.listLineItems) or the subscription's items, matched against your own server-side price list.
7.Mistake #6: Only Listening for the Happy Path
The most expensive bug in this list doesn't involve an attacker at all. If your handler only listens for the purchase, every customer who cancels, whose card fails at renewal, or who disputes a charge keeps premium access forever. We regularly find SaaS apps where a meaningful share of "active" users haven't paid in months.
At minimum, a subscription business needs to handle:
| Event | What to do |
|---|---|
| checkout.session.completed | Grant access if payment_status is paid (or no_payment_required) |
| checkout.session.async_payment_succeeded | Grant access for delayed payment methods |
| customer.subscription.updated | Sync plan, status and period end (upgrades, downgrades, past_due) |
| customer.subscription.deleted | Revoke access |
| invoice.payment_failed | Warn the user, start your grace period |
| charge.dispute.created | Flag the account for review |
Stripe doesn't guarantee ordering. An older subscription.updated can land after a newer one and silently undo it. For anything stateful, treat the event as a nudge: fetch the current object from the API (stripe.subscriptions.retrieve(id)) and save that, instead of applying the event's snapshot.
8.Mistake #7: The Operational Traps
None of these are security holes on their own, but each one has quietly broken billing in production apps we've worked on.
Your auth middleware blocks Stripe
A global auth middleware that protects /api/* answers Stripe's requests with a 401 or a redirect to the login page. Stripe sees failures, retries for days, and then disables the endpoint. Explicitly exclude the webhook route, because it's authenticated by its signature, not a session.
Slow handlers cause retry storms
Stripe expects a quick 2xx. If your handler sends emails, generates PDFs and calls three other APIs before answering, it can time out. Stripe then retries an event you already processed (another reason idempotency matters). Verify, claim the event, do the essential database write, return 200, and push slow side-effects to a queue or background job.
Secrets in the wrong place
Anything prefixed NEXT_PUBLIC_ ships to every visitor's browser. We still find NEXT_PUBLIC_STRIPE_SECRET_KEY in audited apps. The secret key and the webhook signing secret are server-only. And don't log full webhook bodies and headers: those logs are what make replays possible.
Nobody watches failed deliveries
The Stripe Dashboard shows every delivery attempt and its response for each endpoint. Look at it after every deploy that touches billing, and alert on failures. It's the fastest way to learn your webhook has been returning 500s since Tuesday.
9.The Reference Handler
Here's what a handler that closes all seven mistakes looks like in a Next.js App Router project with Prisma. Adapt the helpers (grantAccess, syncSubscription) to your own data model.
The stripeEvent table only needs the event id as its primary key (plus the type and a timestamp if you like). P2002 is Prisma's unique-constraint error; with another ORM, catch its equivalent. Test the whole flow locally with stripe listen --forward-to localhost:3000/api/webhooks/stripe and stripe trigger checkout.session.completed.
10.The 2-Minute Audit Checklist
Open your webhook handler and go down this list. Every "no" is money you're either losing or exposed to losing:
- Access is granted in the webhook, not on the success page.
- Every request goes through
constructEventwith the raw body. - Production uses the live endpoint's signing secret; the timestamp tolerance is untouched.
- Event IDs are claimed with a unique insert before any business logic.
payment_statusis checked; delayed payment methods are handled.- The plan granted comes from the purchased price, never from client input or metadata.
- Cancellations, failed renewals and disputes revoke or flag access.
- Subscription changes are synced from the API, not from event snapshots.
- The webhook route is excluded from auth middleware and answers quickly.
- No Stripe secrets in
NEXT_PUBLIC_variables or logs.
Payment code leaves no room for "good enough". A buggy UI annoys users; a buggy billing flow either gives your product away or charges people for things they don't get. If your Stripe integration was built quickly, or by an AI coding tool that stopped at the happy path, it's worth an expert look before your next growth spike finds the holes for you.
Note on Organization Security:We never require full GitHub/GitLab organization admin access. A read-only invite to the specific repository and branch being audited is all that is required, keeping your broader infrastructure completely isolated.
Not sure which methodology fits your application?
We'll analyze your stack, endpoints, and repo requirements in a quick 10-minute triage.