{"slug": "the-supabase-security-checklist-i-run-on-every-ai-built-app-lovable-bolt-v0", "title": "The Supabase security checklist I run on every AI-built app (Lovable, Bolt, v0, Cursor)", "summary": "A developer published a read-only SQL checklist for auditing Supabase security in AI-generated apps from builders such as Lovable, Bolt, v0 and Cursor, arguing that these tools ship working logins and policies without deciding who can read which row. The checklist uses catalog queries and greps, never writes or requires service_role, to surface tables with RLS disabled, policies using USING (true), FOR ALL policies missing WITH CHECK, anon write grants, dangerous default privileges, SECURITY DEFINER functions without a pinned search_path, and views lacking security_invoker.", "body_md": "An AI app builder will connect Supabase, create tables, generate policies and ship a working login in one session. What it will not do is sit down with your access model and decide who is allowed to read which row. That part is still yours — and the gap between \"it works\" and \"it is closed\" is measurable with read-only SQL.\n\nThis is the order I run. Every step is a catalog read or a grep. None of them writes, deletes or needs `service_role`, and all of them are safe to run on a production project.\n\nThe key in your `NEXT_PUBLIC_` / `VITE_` env is supposed to ship to the browser. The security boundary is not the key; it is what the key can touch. Fetch a table you believe is private with only the anon key and see whether rows come back. A populated response is the finding.\n\n`public`\n\n```\nselect n.nspname as schema, c.relname as table\nfrom pg_class c\njoin pg_namespace n on n.oid = c.relnamespace\nwhere n.nspname = 'public'\n  and c.relkind = 'r'\n  and not c.relrowsecurity\norder by 1, 2;\n```\n\nEvery row is a table with RLS off. With the anon key and default grants, an RLS-off table in `public` is readable by anyone who has your project URL.\n\n`true`\n\n```\nselect schemaname, tablename, policyname, cmd, roles, qual, with_check\nfrom pg_policies\nwhere schemaname = 'public'\n  and (qual = 'true' or with_check = 'true');\n```\n\n`USING (true)` on a `SELECT` policy means every row is visible to every role the policy names — usually `authenticated`, which means every logged-in user. AI-generated schemas contain one of these surprisingly often so the demo works before anyone decides the access model.\n\n`FOR ALL` without `WITH CHECK`\n\n```\nselect tablename, policyname, cmd\nfrom pg_policies\nwhere schemaname = 'public'\n  and cmd = 'ALL'\n  and with_check is null;\n```\n\n`USING` decides which existing rows a statement may touch. `WITH CHECK` decides which new row it may produce. Without it, a user can update a row they own into a state they should not reach — a different tenant, a different owner, an escalated status.\n\n`anon` hold write grants?\n\n```\nselect table_name, privilege_type, grantee\nfrom information_schema.role_table_grants\nwhere table_schema = 'public'\n  and grantee in ('anon', 'authenticated')\n  and privilege_type in ('INSERT', 'UPDATE', 'DELETE')\norder by 1, 3;\n```\n\nRLS still stops the write, but a grant is a second lock that should not be open by accident — and it is exactly the failure mode behind the Supabase October 30 grant change, where tables that relied on old default grants started returning 42501.\n\n```\nselect pg_get_userbyid(defaclrole) as creator,\n       defaclobjtype as object_type,\n       defaclacl as acl\nfrom pg_default_acl;\n```\n\n`ALTER DEFAULT PRIVILEGES ... GRANT SELECT ON TABLES TO anon` creates no row in `role_table_grants` and no policy. It waits here and attaches silently when the next migration creates a table. If your builder's migrations run as one role and your app queries as another, this is where tomorrow's leak is configured today.\n\n`SECURITY DEFINER`: pin `search_path`\n\n```\nselect p.proname,\n       p.prosecdef as security_definer,\n       p.proconfig as settings,\n       has_function_privilege('anon', p.oid, 'EXECUTE') as anon_can_execute\nfrom pg_proc p\njoin pg_namespace n on n.oid = p.pronamespace\nwhere n.nspname = 'public'\n  and p.prosecdef\norder by p.proname;\n```\n\nA definer function runs with its owner's rights. If `proconfig` is null, `search_path` is not pinned and the function can be redirected to another schema. If `anon_can_execute` is true and the function touches privileged data, that is a leak path no policy review will show you.\n\n```\nselect c.relname as view_name, c.reloptions\nfrom pg_class c\njoin pg_namespace n on n.oid = c.relnamespace\nwhere n.nspname = 'public'\n  and c.relkind = 'v'\n  and not (coalesce(c.reloptions, '{}') @> array['security_invoker=true']);\n```\n\nA normal view evaluates with the view owner's rights. If the owner also owns the base table and the table has no `FORCE ROW LEVEL SECURITY`, the view can return rows your caller's policies would hide. `security_invoker = true` makes the view run as the caller.\n\n```\nselect id, name, public from storage.buckets order by name;\n```\n\nA public bucket serves every object to anyone with the URL. For private data: private bucket, signed URLs, and `storage.objects` policies reviewed the same way as table policies — one per operation, scoped by owner.\n\n```\ngrep -rn \"service_role\\|sb_secret_\\|SUPABASE_SERVICE\" \\\n  --include=\"*.ts\" --include=\"*.tsx\" --include=\"*.js\" \\\n  --include=\"*.env*\" . | grep -v node_modules\n```\n\n`service_role` and `sb_secret_` bypass RLS by design. They belong in server-only code. Any hit imported by a client component, or prefixed `NEXT_PUBLIC_` / `VITE_`, is a full-database key sitting in the browser.\n\n`auth.uid()` is null unless you pass the token\nA route that queries Supabase with the anon key and no user JWT runs as `anon`. `auth.uid()` is null, your policy filters everything, and the route returns empty or 42501. Worse: a route that trusts a `user_id` from the request body instead of the verified JWT is an IDOR no matter how good the policies are.\n\nPostgres Changes is filtered by table RLS. Broadcast and Presence are authorized by policies on `realtime.messages`, and only for channels joined with `private: true` while \"Allow public access\" is off in Realtime settings. A public channel can be joined by anyone holding the anon key. Two policies are needed per topic — `select` to receive, `insert` to send — and a join-time policy cache means revoking a membership row does not disconnect anyone until their JWT refreshes.\n\nEverything above is a snapshot. The failure mode is not \"I never checked\"; it is \"I checked in March and the schema changed in July\". A nightly read-only diff over the same catalog queries reports only new fingerprints, and fails closed when the credential breaks instead of writing an empty baseline.\n\nThese are catalog checks, not proof of a leak. They do not read application rows, do not run as `service_role` and do not modify anything. I verified the queries against a local PostgreSQL 17 fixture — not against hosted Supabase projects, whose defaults and exact revision are outside what a public catalog query can tell you. Zero findings does not mean safe; the catalog cannot tell you what your access model should have been.\n\nIf you want the executable version, the write-up with the full check set and a free nightly n8n workflow is on my site: [https://cenkkurtoglu.com/blog/supabase-security-checklist-lovable-bolt-v0-cursor](https://cenkkurtoglu.com/blog/supabase-security-checklist-lovable-bolt-v0-cursor)\n\nIf you'd rather have a person read the output and separate real exposure from noise, that is a fixed-scope review — and it starts only after payment is secured.", "url": "https://wpnews.pro/news/the-supabase-security-checklist-i-run-on-every-ai-built-app-lovable-bolt-v0", "canonical_source": "https://dev.to/cekuu35/the-supabase-security-checklist-i-run-on-every-ai-built-app-lovable-bolt-v0-cursor-4pa4", "published_at": "2026-12-05 11:40:52+00:00", "updated_at": "2026-12-05 11:43:22.557250+00:00", "lang": "en", "topics": ["ai-tools", "ai-agents", "developer-tools", "ai-safety"], "entities": ["Supabase", "Lovable", "Bolt", "v0", "Cursor"], "also_reported_by": [], "takeaway": "Run read-only catalog queries against pg_class, pg_policies, role_table_grants, pg_default_acl, pg_proc and pg_class reloptions to catch RLS-off tables, USING (true) policies, FOR ALL policies without WITH CHECK, anon write grants, unpinned SECURITY DEFINER search_paths and non-security_invoker view", "recommendation": {"advice": "Audit AI-generated Supabase schemas with these read-only catalog queries before shipping, and treat any RLS-off table, USING (true) policy or unpinned SECURITY DEFINER function as a leak to fix.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/the-supabase-security-checklist-i-run-on-every-ai-built-app-lovable-bolt-v0", "markdown": "https://wpnews.pro/news/the-supabase-security-checklist-i-run-on-every-ai-built-app-lovable-bolt-v0.md", "text": "https://wpnews.pro/news/the-supabase-security-checklist-i-run-on-every-ai-built-app-lovable-bolt-v0.txt", "jsonld": "https://wpnews.pro/news/the-supabase-security-checklist-i-run-on-every-ai-built-app-lovable-bolt-v0.jsonld"}}