DEV Community

Štefan Bohumel
Štefan Bohumel

Posted on

The 6 Pre-Launch Security Bugs That Keep Breaking AI-Built SaaS Apps (And How to Catch All 30 Patterns Locally in 30ms)

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);
Enter fullscreen mode Exit fullscreen mode

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() inside middleware.ts or API routes instead of supabase.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 calls prisma.workspace.delete(...) without checking the authenticated user and record ownership, anyone can invoke it with curl.

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 });
Enter fullscreen mode Exit fullscreen mode

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:

  1. User authentication (getUser())
  2. Per-user rate limiting (e.g., Upstash Ratelimit)
  3. An explicit max_tokens cap

...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 .zip support (works straight off Lovable / Bolt.new / v0 / Replit / GitHub exports)
  • Auto-Fix Pack (.zip): auto-generates fix_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

ShipGate PRO — Local Pre-Launch Security & Auto-Fix Studio by Štefan Bohumel

Read more about ShipGate PRO — Local Pre-Launch Security & Auto-Fix Studio by Štefan Bohumel on Contra.

favicon contra.com

Top comments (4)

Collapse
 
userxnom profile image
Abdullah Naseer •

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?

Collapse
 
ramirez911 profile image
Štefan Bohumel •

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 Paddle unmarshal).
  • SG-PAY-03 (MEDIUM): Independently checks whether a fulfillment handler that mutates credits/subscriptions/plans actually tracks or deduplicates event.id (e.g., via a unique processed_webhook_events table 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 check or // 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 SECURITY on new tables or drop in USING (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 and max_tokens.

Appreciate you reading closely!

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

getSession in middleware reads a cookie, not the server. it slips past review because it looks like a check.

Collapse
 
ramirez911 profile image
Štefan Bohumel •

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 for middleware.ts.

That's why our rule SG-AUTH-06 specifically skips "use client" files (where getSession() is fine for UI state) and only fires on server contexts (middleware, /api/ routes, Server Actions, Server Components) whenever auth.getSession() is called without auth.getUser().