AI coding tools scaffold Supabase fast — and ship tables with no RLS, using (true) policies, or the service_role key in the frontend. Drop these rules into your agent and it defaults to the secure pattern — rules are advisory, so still verify (below). Especially now: on Oct 30, 2026 new Supabase tables stop being exposed to the Data API without an explicit grant.
When the agent creates or changes a table in a Supabase public schema, it must do all of this in the same migration:
alter table public.<table> enable row level security;SELECT/DELETE use using (user_id = (select auth.uid())); INSERT uses with check (...); UPDATE needs both. For team data, scope by membership.grant select, insert, update, delete on public.<table> to authenticated; — grant anon only for genuinely public data. For a serial id the API inserts into, also grant the sequence.Never:
service_role key (or sb_secret_…) to the browser or a NEXT_PUBLIC_ variable — it bypasses RLS. Server-side only.using (true) / with check (true) on private data a client role can reach. (A read-only using (true) is fine for a table that is public on purpose, like a catalog. Say so in a comment.)42501 permission denied with grant … on all tables in schema public — it re-exposes every RLS-off table. Grant the one table.The anon key is safe in the browser only because RLS limits it — it's not a secret. Full text and every format: the repo.
Pick the file your tool reads — or just drop AGENTS.md, which Cursor, Windsurf and Claude Code all read. Commit it so your whole team's agents share the rules.
| Any (recommended) | AGENTS.md at the repo root |
| Cursor | .cursor/rules/supabase-security.mdc |
| Claude Code | CLAUDE.md (or append to yours) |
| Windsurf | .windsurf/rules/supabase-security.md |
| Older Cursor / Windsurf | .cursorrules / .windsurfrules |
An agent can ignore a rule — they're advisory. Prove your schema is actually safe:
npx airlock-migrate fails the build when a migration creates a table without RLS.SUPABASE_DB_URL=… npx airlock-rls reads your tables with the anon key and proves what's exposed.More: the Supabase RLS guides, the policy generator, and the policy explainer.