scribase
Agent governance

RLS for AI coding agents: required, not optional

An AI agent writing SQL creates a table the fast way: CREATE TABLE, no ENABLE ROW LEVEL SECURITY, no policy. Through a dashboard's table editor that gets switched on for you; through the SQL an agent actually runs, it does not. That single gap — not an attack, a default — is the root cause behind a public CVE and tens of thousands of exposed databases this year.

Last checked November 30, 2026.

This is not theoretical

Lovable-generated projects shipped with RLS disabled by default (CVE-2025-48757), exposing data behind the public anon key in 170+ applications, one leak reaching 13,000 users. Separately, a scan across roughly 300,000 domains running Supabase found 16,000+ databases with publicly readable tables from missing or ineffective row-level security — names, addresses, phone numbers, plaintext passwords, some payment data. Security researcher Simon Willison has also documented the service_role bypass: an MCP server or agent given the service_role key skips RLS entirely, so a prompt-injection payload hidden in a support ticket can make the agent leak data a correctly-written policy would have blocked.

Sources: Lovable CVE-2025-48757: RLS disabled by default, 170+ apps exposed, 16,000+ Supabase databases exposed by missing row level security, HN: "Supabase MCP can leak your entire SQL database"

Why an agent skips RLS without meaning to

A dashboard's table editor turns RLS on automatically. An agent writing a CREATE TABLE statement, in a migration file or a direct SQL call, gets exactly what it asked for: a public table, no RLS, no policy, readable and writable by anyone holding the public key the client ships with. Nothing in Postgres or in a plain SQL connection stops that. Reminding an agent to "remember RLS" in a prompt is the same shape of fix as reminding it to "be careful with production" — it works until it does not.

The actual block: RLS proven, not reminded

On Scribase this is a compiled lint rule, not a style guideline: a public-schema table shipped in a migration without RLS enabled and at least one attached policy is refused — blocked before it ever reaches a database. Every MCP schema_apply call is built the same way: it only accepts a schema that policy_test has already proved on a scratch branch, including deliberately broken policy variants the tests must catch, so a policy that looks right but denies or permits the wrong rows is caught before it ships, not after a leak.

What the migration needs to pass; missing either half blocks the migrationsql
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
CREATE POLICY "owner only" ON orders
  USING (auth.uid() = user_id);

Sources: Scribase docs: Tokens and safety

FAQ

Questions people ask

Why does an AI-generated Supabase project end up with RLS disabled?

A dashboard table editor enables row level security automatically when you create a table through it; a CREATE TABLE statement run directly by an agent or a migration does not get that default. The table ships public, readable and writable by anyone holding the publishable key, until a human or a tool notices and adds a policy.

Is this a real, documented security problem, not a hypothetical?

Yes. Lovable shipped CVE-2025-48757 from exactly this default, affecting 170+ applications with one leak reaching 13,000 users, and an independent scan found 16,000+ Supabase databases publicly exposing data for the same reason. Separately, giving an agent the service_role key (which bypasses RLS entirely) has been shown to make agents leak data through prompt injection even when a policy exists.

Does adding a policy later fix an already-exposed table?

It stops new exposure going forward, but does not undo rows already read by whoever found the table while it was open — treat any period with RLS off and a public key in the wild as a real exposure window, not just a config bug to quietly fix.

How does Scribase prevent this specifically?

A migration that creates a public table without both RLS enabled and at least one policy is blocked before it applies — a compiled rule, not a reminder in a prompt. Scribase also proves each policy against deliberately broken variants (policy_test) before schema_apply accepts it, and keeps the service_role-equivalent secret key out of client code and out of the agent's default token.