{"slug": "i-built-a-zero-dependency-15-point-audit-cli-for-vibe-coded-supabase-apps-what-s", "title": "I Built a Zero-Dependency 15-Point Audit CLI for Vibe-Coded Supabase Apps (What Lovable's Green RLS Toggle Misses)", "summary": "A developer built a zero-dependency Node.js 18+ audit script, supabase-rls-audit.mjs, that scans SQL migrations, Edge Functions, and frontend bundles against 15 rules (VCR-01 through VCR-15) to catch Row Level Security gaps in AI-generated Supabase apps. The tool targets five failure modes that pass Supabase's green RLS-enabled badge, including permissive USING (true) policies, UPDATE/INSERT policies missing WITH CHECK, views that bypass RLS without security_invoker, and signup triggers that trust user-controlled raw_user_meta_data for roles and plans. The writeup pairs each finding with SQL patches, such as wrapping auth.uid() in a subselect for per-statement caching and revoking column-level updates on plan and role fields.", "body_md": "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.\n\nIt usually is not.\n\nOver 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.\n\nTo 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`).\n\nHere 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.\n\n`VCR-04`)\nWhen 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`.\n\nThe dashboard shows RLS as enabled. In practice, every row in the table is readable or writable across tenants via the public PostgREST endpoint.\n\n**What our CLI flags:**\n\n```\n-- Vulnerable: passes \"RLS Enabled\" checks, leaks every tenant row\nCREATE POLICY \"allow_authenticated_all\"\n  ON public.projects\n  FOR SELECT\n  TO authenticated\n  USING (true);\n```\n\n**The fix:**\n\n```\nDROP POLICY \"allow_authenticated_all\" ON public.projects;\n\nCREATE POLICY \"tenant_isolated_select\"\n  ON public.projects\n  FOR SELECT\n  TO authenticated\n  USING ((SELECT auth.uid()) = user_id);\n```\n\nWrapping `auth.uid()` in `(SELECT auth.uid())` also lets Postgres cache the initPlan per statement instead of re-evaluating per row.\n\n`INSERT` / `UPDATE` Policies Missing an Explicit `WITH CHECK` (`VCR-05`)\nAn `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.\n\n```\nDROP POLICY \"owner_update\" ON public.projects;\n\nCREATE POLICY \"owner_update\"\n  ON public.projects\n  FOR UPDATE\n  TO authenticated\n  USING ((SELECT auth.uid()) = user_id)\n  WITH CHECK ((SELECT auth.uid()) = user_id);\n```\n\n`VCR-08`)\nIn 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.\n\n**The fix (PostgreSQL 15+ / Supabase):**\n\n```\nALTER VIEW public.dashboard_metrics SET (security_invoker = true);\n\n-- Or set it on creation:\nCREATE OR REPLACE VIEW public.dashboard_metrics\nWITH (security_invoker = true) AS\nSELECT id, user_id, total_cents\nFROM public.invoices;\n```\n\n`raw_user_meta_data` (`VCR-07`)\nThis 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'`.\n\nThe 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()`.\n\n**The fix:**\n\nNever 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:\n\n```\nINSERT INTO public.profiles (id, email, full_name, role, plan)\nVALUES (\n  NEW.id,\n  NEW.email,\n  NEW.raw_user_meta_data ->> 'full_name',\n  COALESCE(NEW.raw_app_meta_data ->> 'role', 'member'),\n  'free'\n);\n```\n\nPair 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.\n\n`constructEventAsync` (`VCR-09` & `VCR-10`)\nTwo bugs show up constantly in AI-generated Supabase Edge Functions handling Stripe:\n\n`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.\n**The fix for Supabase Edge Functions (Deno):**\n\n``` js\nconst rawBody = await req.text();\nconst sig = req.headers.get('stripe-signature');\nif (!sig) return new Response('Missing signature', { status: 400 });\n\nconst event = await stripe.webhooks.constructEventAsync(\n  rawBody,\n  sig,\n  Deno.env.get('STRIPE_WEBHOOK_SECRET')!,\n  undefined,\n  Stripe.createSubtleCryptoProvider()\n);\n```\n\nThen 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.\n\nBeyond those five checks, `supabase-rls-audit.mjs` checks for:\n\n`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`)\nIf 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](mailto: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.\n\n**More 60-second dev fixes and free browser-local tools from LocalLedger Studio:**\n\n`DESIGN.md` spec generator:", "url": "https://wpnews.pro/news/i-built-a-zero-dependency-15-point-audit-cli-for-vibe-coded-supabase-apps-what-s", "canonical_source": "https://dev.to/riskopslab/i-built-a-zero-dependency-15-point-audit-cli-for-vibe-coded-supabase-apps-what-lovables-green-rls-fbk", "published_at": "2026-11-30 06:37:00+00:00", "updated_at": "2026-11-30 06:45:04.036447+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents", "ai-safety"], "entities": ["Supabase", "Lovable", "Bolt", "Cursor", "PostgreSQL", "Stripe"], "also_reported_by": [], "takeaway": "Supabase's RLS-enabled badge does not prove tenant isolation: audit for USING (true) policies, UPDATE/INSERT policies lacking WITH CHECK, views without security_invoker, and roles or plans read from user-controlled raw_user_meta_data.", "recommendation": {"advice": "Audit AI-generated Supabase schemas for permissive RLS policies, missing WITH CHECK clauses, and non-invoker views, and never read roles or plans from user-controlled raw_user_meta_data.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/i-built-a-zero-dependency-15-point-audit-cli-for-vibe-coded-supabase-apps-what-s", "markdown": "https://wpnews.pro/news/i-built-a-zero-dependency-15-point-audit-cli-for-vibe-coded-supabase-apps-what-s.md", "text": "https://wpnews.pro/news/i-built-a-zero-dependency-15-point-audit-cli-for-vibe-coded-supabase-apps-what-s.txt", "jsonld": "https://wpnews.pro/news/i-built-a-zero-dependency-15-point-audit-cli-for-vibe-coded-supabase-apps-what-s.jsonld"}}