Building a full-stack SaaS with Next.js, Supabase, Stripe, and OpenAI has never been faster. Unfortunately, shipping a critical vulnerability on day one has never been easier either.
While building a deterministic pre-launch scanner (ShipGate PRO), I cataloged the 30 highest-impact security failures across modern indie SaaS and AI-assisted codebases — and grouped them into 6 concrete failure modes every developer should verify before hitting Deploy.
1. Supabase Row Level Security (RLS) Traps
Creating a table in supabase/migrations/001_init.sql without ALTER TABLE ... ENABLE ROW LEVEL SECURITY; leaves that table exposed via PostgREST to anyone holding your public anon key.
Just as common: enabling RLS, then adding an overly broad policy to "make it work":
-- Dangerous: any logged-in user can overwrite or delete other customers' rows
CREATE POLICY "profiles_allow_all" ON public.profiles
FOR ALL USING (true) WITH CHECK (true);
Fix: Always pair ENABLE ROW LEVEL SECURITY with explicit owner predicates (auth.uid() = user_id), and check migrations across all SQL files so multi-file migrations don't create false alarms.
2. Server-Side supabase.auth.getSession() & Unprotected "use server" Actions
Two Next.js footguns that slip past code review constantly:
- Using
supabase.auth.getSession()insidemiddleware.tsor API routes instead ofsupabase.auth.getUser().getSession()trusts unverified cookie payloads on the server;getUser()validates the JWT with Supabase Auth. - Forgetting that
"use server"Server Actions compile into public HTTP POST endpoints. If an action callsprisma.workspace.delete(...)without checking the authenticated user and record ownership, anyone can invoke it withcurl.
3. Mass Assignment & IDOR in "Simple" CRUD Routes
// Vulnerable: attacker sends { "role": "admin", "credits": 99999 }
const body = await req.json();
await prisma.user.update({ where: { id: user.id }, data: body });
Always parse incoming JSON with a strict allowlist schema (Zod / Pydantic) and scope every update/delete query by BOTH id AND userId: user.id.
4. Payment Webhooks Without Signature Verification or Idempotency
If your /api/stripe/webhook handler runs const event = await req.json() without stripe.webhooks.constructEvent(rawBody, sig, secret), any attacker can forge checkout.session.completed and grant themselves Pro access.
And even when signatures are verified, skipping event.id deduplication means Stripe's automatic webhook retries can double-credit accounts.
5. Public AI Endpoints (The Overnight API Wallet-Drain Bug)
An exported POST /api/ai/chat calling openai.chat.completions.create(...) without:
- User authentication (
getUser()) - Per-user rate limiting (e.g., Upstash Ratelimit)
- An explicit
max_tokenscap
...is an open proxy to your credit card.
6. Client-Bundled Secrets (NEXT_PUBLIC_*) & Missing Headers
Prefixing a service key with NEXT_PUBLIC_ or VITE_ bakes it directly into browser JavaScript. Similarly, shipping next.config.mjs with ignoreBuildErrors: true and zero CSP / HSTS / X-Frame-Options headers silently degrades production security.
Automating All 30 Checks Locally (With Auto-Fix Packs)
To avoid manually grepping through every repo before launch — and without uploading private client source code to third-party SaaS scanners — I packaged all 30 checks into ShipGate PRO:
- Zero-cloud local Web Studio + CLI (Python + FastAPI, runs in ~30ms)
-
Drag & Drop
.zipsupport (works straight off Lovable / Bolt.new / v0 / Replit / GitHub exports) -
Auto-Fix Pack (
.zip): auto-generatesfix_supabase_rls.sql,security_headers_patch.js, and targeted 1-click AI fix prompts per finding -
White-Label HTML/PDF Client Report + SARIF 2.1.0 for GitHub Actions (
--fail-on high)
Every rule is tested against both vulnerable fixtures and paired hardened negative controls (30/30 coverage, 0 false positives).
Check it out here: https://czechaieu.gumroad.com/l/shipgate-pro
Top comments (4)
The RLS trap is the one I would put first too — a table created without ENABLE ROW LEVEL SECURITY is exposed through PostgREST to anyone holding the anon key, and it is exactly the kind of thing AI-generated migrations skip. The getSession vs getUser distinction is the other one that bites people: getSession trusts the cookie payload, getUser validates the JWT with Supabase Auth, and that difference stays invisible until someone forges a session.
One question on the scan itself: for the Stripe webhook check, does it flag both halves — the missing constructEvent signature verification and the missing event.id dedup? The signature gap is the loud one, but Stripe's automatic retries double-crediting an account is the quieter failure of the two. And of the 6 modes, which one showed up most often in the codebases you scanned?
Great question — yes, it flags both halves as two independent rules so fixing the signature doesn't hide the retry bug:
SG-PAY-01(CRITICAL): Flags webhook handlers processing billing events (checkout.session.completed,invoice.paid,payment_intent.succeeded,order_created, etc.) without cryptographic signature verification (stripe.webhooks.constructEvent, HMAC +timingSafeEqual/compare_digest, or Paddleunmarshal).SG-PAY-03(MEDIUM): Independently checks whether a fulfillment handler that mutates credits/subscriptions/plans actually tracks or deduplicatesevent.id(e.g., via a uniqueprocessed_webhook_eventstable or conflict-guarded upsert).One subtle detail we had to harden during testing: the scanner strips comments before checking security guards, because AI-generated code loves leaving
// TODO: add idempotency checkor// TODO: verify signature— and naive regex checks get fooled by those comments.As for which of the 6 shows up most often: Database/RLS and Auth/API routes are neck-and-neck at the top. In prototype-speed builds (Cursor / Lovable / Bolt), people either forget
ENABLE ROW LEVEL SECURITYon new tables or drop inUSING (true)to stop 403 errors while testing and never tighten it back. Right behind that are unauthenticated"use server"actions / API routes missing ownership checks (IDOR), and public LLM routes missing rate limits andmax_tokens.Appreciate you reading closely!
getSession in middleware reads a cookie, not the server. it slips past review because it looks like a check.
Exactly — that's what makes it so dangerous in code review. Visually
const { data: { session } } = await supabase.auth.getSession()looks identical to a proper auth guard, and most older tutorials and LLM outputs still generate it formiddleware.ts.That's why our rule
SG-AUTH-06specifically skips"use client"files (wheregetSession()is fine for UI state) and only fires on server contexts (middleware,/api/routes, Server Actions, Server Components) wheneverauth.getSession()is called withoutauth.getUser().