5 Supabase RLS & API Key Leaks I Keep Finding in Cursor & Lovable Apps
Shipping a full-stack app in a weekend with Cursor, Lovable, or Bolt is genuinely amazing—until your first real user opens DevTools and dumps your entire users table with one curl call. After auditing dozens of AI-gener
Shipping a full-stack app in a weekend with Cursor, Lovable, or Bolt is genuinely amazing—until your first real user opens DevTools and dumps your entire users table with one curl call.
After auditing dozens of AI-generated Next.js + Supabase MVPs, the same 5 production leaks show up over and over again. Here is the exact 5-minute pre-launch checklist (and SQL/code fixes) to catch them before you post on Product Hunt or X.
1. Tables Created Without Row Level Security (RLS) Enabled
By default, a new table in Postgres has RLS disabled. Because Supabase exposes your anon key in the browser bundle, anyone can query /rest/v1/<table_name> directly if RLS is off.
Fix: Run this audit query in the Supabase SQL Editor before every launch:
select schemaname, tablename, rowsecurity
from pg_tables
where schemaname = 'public' and rowsecurity = false;
For every user-owned table, enforce both RLS and explicit policies:
alter table public.projects enable row level security;
create policy "Users can only access their own rows"
on public.projects
for all
using (auth.uid() = user_id)
with check (auth.uid() = user_id);
2. Using getSession() Instead of getUser() on the Server
AI coding assistants still frequently generate supabase.auth.getSession() inside Next.js Server Components, Route Handlers, or Middleware. getSession() reads directly from cookies without revalidating the JWT against Supabase Auth—making it spoofable.
Fix: Always use @supabase/ssr and call await supabase.auth.getUser() on the server before returning protected data or mutating records.
3. Leaking SUPABASE_SERVICE_ROLE_KEY via NEXT_PUBLIC_
Prefixing a secret with NEXT_PUBLIC_ (or VITE_) bundles it straight into client-side JavaScript. If service_role ever touches the browser, it bypasses all RLS policies globally.
Fix: Search your repo for NEXT_PUBLIC_ / VITE_ and verify ONLY the URL and anon key are exposed. Keep SUPABASE_SERVICE_ROLE_KEY, Stripe secrets, and OpenAI/Anthropic keys strictly in server-side env vars.
4. Permissive INSERT / UPDATE Policies Allowing Privilege Escalation
Even when RLS is enabled, a common AI-generated policy lets authenticated users update any column on their own profiles row—including is_pro = true, role = 'admin', or credits = 99999.
Fix: Split billing/role fields into a separate table that only service_role webhooks can write to, or enforce column-level restrictions via triggers / Postgres views.
5. Public Storage Buckets With Predictable Paths
Putting user uploads (invoices, resumes, private PDFs) into a public Supabase Storage bucket means anyone who guesses or scrapes the URL can download them without auth.
Fix: Set sensitive buckets to Private, add Storage RLS policies on storage.objects, and serve files exclusively via short-lived signed URLs (createSignedUrl(path, 60)).
Want to Run This Check Automatically Before Launch?
I built a free, 100% browser-side pre-launch security risk checker (zero signup, no code leaves your browser) to score your AI-built app's exposure across RLS, env leaks, and auth flows:
👉 Free Checker: vibeaudit-calc.netlify.app
If you want the complete offline VibeAudit Pro Launch Kit (copy-paste Supabase RLS SQL templates, Next.js middleware hardening snippets, and a 42-point production launch audit pack), it's currently on a $9 launch special (normally $29) for the first 10 builders:
👉 VibeAudit Pro Launch Kit ($9 Launch Special)
What's the nastiest AI-generated security bug you've caught before shipping? Drop it in the comments.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.