# Row level security for AI coding agents, required by default

> A table an AI agent creates with plain SQL ships with row level security off, readable by the public key — the exact gap behind the Lovable RLS CVE and 16,000+ exposed Supabase databases. Scribase blocks it at migration time, every time.

Source: https://scribase.com/rls-for-ai-coding-agents

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.

## 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](https://byteiota.com/supabase-security-flaw-170-apps-exposed-by-missing-rls/)
- [16,000+ Supabase databases exposed by missing row level security](https://daily.dev/posts/over-16-000-misconfigured-supabase-databases-are-exposing-personal-data-publicly-l5fvs1miv)
- [HN: "Supabase MCP can leak your entire SQL database"](https://news.ycombinator.com/item?id=44502318)

## 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 migration_

```sql
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
CREATE POLICY "owner only" ON orders
  USING (auth.uid() = user_id);
```

## Sources

- [Scribase docs: Tokens and safety](https://docs.scribase.com/docs/agents/safety)

[Try the free RLS checker](https://scribase.com/tools/rls-checker)

## FAQ

**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.

## Related

- [Check a connection string for RLS gaps](https://scribase.com/tools/rls-checker)
- [Free migration lint](https://scribase.com/tools/migration-lint)
- [Supabase RLS policy examples](https://scribase.com/supabase-rls-policy-examples)
- [Stop an AI agent dropping a production database](https://scribase.com/stop-ai-agent-dropping-production-database)
- [AI agent database permissions](https://scribase.com/ai-agent-database-permissions)