Case study
Two Stripe bugs I found auditing my own SaaS before it went live
CloakMotion is a multi-tenant SaaS I built that turns a prompt into a short video and posts it to YouTube and TikTok on a schedule. It has three paid plans on Stripe. Before I ever deployed it, I sat down and audited the payment code the way a stranger would. Two of the problems I found were the kind that don't show up in a demo.
Bug 1: the webhook would accept fake events
Stripe tells your app about payments by calling a webhook. Laravel Cashier checks that each call really came from Stripe, but only if STRIPE_WEBHOOK_SECRET is set. If the variable is missing, the check is skipped and the endpoint accepts whatever anyone sends it.
Nothing in my code forced that variable to exist. A deploy with a forgotten environment variable would have run happily, with an open webhook, and no error anywhere.
The fix is to refuse to start without it. This is in AppServiceProvider::boot():
if ($this->app->environment('production') && empty(config('cashier.webhook.secret'))) {
throw new \RuntimeException('STRIPE_WEBHOOK_SECRET must be set in production.');
}
A missing secret now stops the deploy instead of quietly weakening it.
Bug 2: the billing portal could downgrade a paying customer
The Stripe customer portal lets users change plans. My app decides what a user is allowed to do by reading a plan name I store on each subscription when it is created through my own checkout. A plan change made inside the portal creates a subscription without that name. The app stored it as type default, and my access checks treated default as no plan. A customer who had just upgraded would have been treated as a free user.
I didn't patch around it. I removed the way it could happen. The portal is now created with plan changes turned off, and plan changes go through my own /billing/subscribe endpoint, which always sets the plan name:
'subscription_update' => ['enabled' => false],
Cancelling, updating a card and seeing invoices still work in the portal.
What I'd tell a client
- Check what happens when a config value is missing, not only when it is wrong. A missing secret failed silently, which is worse than failing loudly.
- Anything that can create a subscription outside your checkout can bypass your own bookkeeping. Close the door instead of handling every case behind it.
- Both fixes are small. Finding them took a read-through of the payment path with the question "what if this value isn't there, or this event didn't come from where I think?"
A third problem from the same audit was a silent data bug after I moved the database from MariaDB to Postgres. A file-upload endpoint used a MySQL-only call to get the new row id, which does nothing on Postgres, so it didn't error. It just returned nothing useful. That one deserves its own post.
CloakMotion has no automated test suite and isn't deployed publicly. It runs locally in Docker, and there's a recorded walkthrough in my Upwork portfolio. If you want your Stripe setup reviewed the same way, book a call with me on Upwork.
The code from this post is public: https://github.com/hassan91199/cloakmotion-highlights/tree/main/stripe