If you built your SaaS MVP in Lovable, Bolt, or Cursor over a weekend, you probably checked the Supabase dashboard, saw the green RLS Enabled badge on your tables, and assumed multi-tenant isolation was done.
It usually is not.
Over the past month, I audited AI-generated Supabase repositories and migrations and kept running into the exact same five failure modes. None of them trip the basic "is RLS enabled?" warning in the dashboard. All five let an authenticated (or anonymous) user read another customer's rows, escalate to an admin plan, or forge Stripe webhooks.
To stop checking these by hand, I wrote a zero-dependency Node.js 18+ static and passive audit script (supabase-rls-audit.mjs) that scans SQL migrations, Edge Functions, and frontend bundles against 15 rules (VCR-01 through VCR-15).
Here are the 5 silent leaks that slip past the green RLS toggle most often, along with the exact SQL and TypeScript patches to close them.
VCR-04)
When an AI coding assistant hits a 403 error during prototyping, its favorite shortcut is to turn RLS on and immediately create a policy with USING (true) or WITH CHECK (true) for public, anon, or authenticated.
The dashboard shows RLS as enabled. In practice, every row in the table is readable or writable across tenants via the public PostgREST endpoint.
What our CLI flags:
-- Vulnerable: passes "RLS Enabled" checks, leaks every tenant row
CREATE POLICY "allow_authenticated_all"
ON public.projects
FOR SELECT
TO authenticated
USING (true);
The fix:
DROP POLICY "allow_authenticated_all" ON public.projects;
CREATE POLICY "tenant_isolated_select"
ON public.projects
FOR SELECT
TO authenticated
USING ((SELECT auth.uid()) = user_id);
Wrapping auth.uid() in (SELECT auth.uid()) also lets Postgres cache the initPlan per statement instead of re-evaluating per row.
INSERT / UPDATE Policies Missing an Explicit WITH CHECK (VCR-05)
An UPDATE policy with only a USING clause checks whether you own the row before the update, not after. An INSERT policy without WITH CHECK lets any signed-in user submit another tenant's user_id or org_id in the payload and inject records directly into someone else's workspace.
DROP POLICY "owner_update" ON public.projects;
CREATE POLICY "owner_update"
ON public.projects
FOR UPDATE
TO authenticated
USING ((SELECT auth.uid()) = user_id)
WITH CHECK ((SELECT auth.uid()) = user_id);
VCR-08)
In PostgreSQL, views run with the permissions of the view creator (postgres) by default. If your AI assistant generated a reporting view (public.dashboard_metrics or public.active_subscriptions) to simplify a frontend query, PostgREST exposes that view to the client and silently bypasses every RLS policy on the underlying tables.
The fix (PostgreSQL 15+ / Supabase):
ALTER VIEW public.dashboard_metrics SET (security_invoker = true);
-- Or set it on creation:
CREATE OR REPLACE VIEW public.dashboard_metrics
WITH (security_invoker = true) AS
SELECT id, user_id, total_cents
FROM public.invoices;
raw_user_meta_data (VCR-07)
This is the most common billing bypass in Lovable and Cursor templates. A signup trigger or RLS policy reads NEW.raw_user_meta_data ->> 'role' or raw_user_meta_data ->> 'plan'.
The catch: raw_user_meta_data is user-controlled. Anyone can pass { data: { role: 'admin', plan: 'pro' } } during supabase.auth.signUp() or modify it later with supabase.auth.updateUser().
The fix:
Never read roles, plans, or org IDs from raw_user_meta_data. Hardcode least-privilege defaults on insert, or read server-managed raw_app_meta_data only:
INSERT INTO public.profiles (id, email, full_name, role, plan)
VALUES (
NEW.id,
NEW.email,
NEW.raw_user_meta_data ->> 'full_name',
COALESCE(NEW.raw_app_meta_data ->> 'role', 'member'),
'free'
);
Pair this with column-level revocation (REVOKE UPDATE (plan, role, is_admin, credits) ON public.profiles FROM authenticated;, checked by VCR-11) so users cannot patch their own billing columns from browser DevTools.
constructEventAsync (VCR-09 & VCR-10)
Two bugs show up constantly in AI-generated Supabase Edge Functions handling Stripe:
await req.json() directly and trusting body.type === 'checkout.session.completed' with zero HMAC signature verification. Anyone can curl your endpoint and grant themselves a paid plan.stripe.webhooks.constructEvent() inside Deno, which throws a crypto runtime error in Supabase Edge Functions, prompting the developer to comment out signature verification "temporarily" to get checkout working.
The fix for Supabase Edge Functions (Deno):
const rawBody = await req.text();
const sig = req.headers.get('stripe-signature');
if (!sig) return new Response('Missing signature', { status: 400 });
const event = await stripe.webhooks.constructEventAsync(
rawBody,
sig,
Deno.env.get('STRIPE_WEBHOOK_SECRET')!,
undefined,
Stripe.createSubtleCryptoProvider()
);
Then deduplicate event.id in a public.stripe_webhook_events table with stripe_event_id text PRIMARY KEY before granting credits (VCR-10) so Stripe retries never double-credit an account.
Beyond those five checks, supabase-rls-audit.mjs checks for:
service_role JWTs leaked in client bundles (VCR-01) and hardcoded API tokens ( VCR-02) ENABLE ROW LEVEL SECURITY (VCR-03) SECURITY DEFINER functions missing SET search_path = '' (VCR-06) storage.objects policies (VCR-12).env files or NEXT_PUBLIC_/ VITE_ prefixed secret keys (VCR-13) dangerouslySetInnerHTML and interpolated SQL (VCR-14) Access-Control-Allow-Origin: * on authenticated routes (VCR-15)
If you are about to launch a Lovable, Bolt, Cursor, or Next.js + Supabase app and want a clean 24-hour pre-launch security review (full 15-point scan, redacted report, ready-to-apply SQL migrations, and Stripe webhook patch PR), email me at support@localledgerstudio.xyz with your repo stack. Fixed-price audits run $149 to $399 depending on table count and Edge Function complexity, with zero retainer lock-in.
More 60-second dev fixes and free browser-local tools from LocalLedger Studio:
DESIGN.md spec generator: