TL;DR
AI builders ship Supabase backends in minutes — often with row-level security off or wide open. Six pitfalls that leaked real data, and the checks that close them.
An AI app builder can hand you a working full-stack app in an afternoon: React frontend, Supabase backend, auth, database, deployed. What it does not hand you is a guarantee that the database is closed. The frontend talks to the database directly, with a public key that ships in the JavaScript bundle, and the only thing standing between any visitor and every row is row-level security (RLS) — a switch, plus policies, on each table. When the builder skips that step, the app works perfectly and leaks perfectly at the same time.
The short version: tables created through SQL, migrations, or an API — the route every AI builder takes — start with RLS off, while tables created in the Supabase dashboard get it on automatically. Six recurring pitfalls turn that default into an exposure: RLS never enabled, a policy of using (true), grants left wide open, a missing with check, a secret key in the browser bundle, and views or helper functions that quietly bypass the policies. Every one of them has a check that takes minutes, and every one of them has already leaked real data in public.
Why the backend arrives open
Three things changed at once. First, the builders got fast. Supabase reported in June 2026 that more than 60% of new databases on its platform were being launched by some form of AI tool. A human writing a migration might remember the RLS line; an agent writing ten migrations in a row remembers it only if the prompt says so.
Second, the default is split in a way that hides the problem. Tables created in Supabase's Table Editor get RLS switched on automatically. Tables created through the API — which is how coding agents work with Supabase — do not. The app works either way, because the agent usually tests with a key that bypasses RLS, so nothing in the happy path complains. The failure is silent: no error, no warning in the app, just a public endpoint that answers anyone who asks.
Third, the evidence is now measured in the open, four scans in a row. In May 2025, researcher Matt Palmer disclosed CVE-2025-48757: scanning 1,645 Lovable apps from the platform's own showcase, he found 170 with missing or insufficient RLS policies across 303 endpoints, exposing names, phone numbers, payment details, and API keys. The CVE carries a CVSS score of 8.26. In September 2025, Wiz Research found one in five organizations building on vibe-coding platforms exposed to systemic risk, through four recurring flaws — client-side auth, secrets in client code, open tables, and internal apps with no login. In September 2026, UpGuard probed roughly 300,000 domains showing Supabase use and found 16,326 databases with readable tables, more than half showing signs of personal data; UpGuard confirmed no malicious third-party access to the exposed databases. And in January 2026, Wiz found Moltbook's database open to anyone who read the key from its frontend JavaScript: about 4.75 million records, including 1.5 million agent API tokens, about 35,000 email addresses, and 4,060 private direct-message conversations, some holding plaintext API keys for other services. The founder's own summary of the build: he did not write a single line of its code.
The pitfalls
Pitfall 1: RLS never switched on
This is the one behind most of the numbers above. Postgres tables start with RLS off, and Postgres's own documentation states the consequence plainly: if a user has access privileges to a table, all rows within it are equally available. Supabase's Data API generates a REST endpoint for every table, and on projects created before the grants change, a new table in the public schema starts with every privilege already granted to the anon and authenticated roles. RLS off plus those grants means the publishable key — the key every visitor's browser already holds — reads and writes the whole table.
The fix is one line in the same migration that creates the table, not a later ticket:
alter table public.invoices enable row level security;
Enable it in the same migration, or the table ships unprotected. Supabase's own RLS guide says to enable RLS on every table in an exposed schema, and offers an event trigger that switches RLS on automatically for every new table — worth installing, with the caveat that it only covers tables created after it is installed, and it writes no policies.
Pitfall 2: The using (true) policy
When RLS is on but the app returns no rows, the fastest unblock is a policy that allows everything — and agents reach for it constantly. Supabase's RLS guide is blunt about what it means: a policy that reads to anon using ( true ) grants every unauthenticated visitor read access to every row the role can already reach. It passes a glance at the policies list and protects nothing. It is also what several scanners check for: presence of a policy, not whether the policy says the right thing.
The fix is a policy per operation that names the owner, using Supabase Auth's helper:
create policy "users read their own invoices" on public.invoices for select to authenticated using ( (select auth.uid()) = user_id );
Wrapping auth.uid() in a select lets Postgres evaluate it once per statement instead of once per row, which is the performance pattern Supabase documents. Note the to authenticated: without it, the policy also runs for anonymous visitors.
Pitfall 3: Grants left wide open
Policies and grants are two different locks, and this is the pitfall that survives a correct-looking policy list. Supabase's guide states it directly: adding policies doesn't take grants back. On existing projects, a new table in public starts with select, insert, update, delete, and more granted to anon and authenticated. A table protected only by policies still hands anon an insert path if the grant was never revoked — a policy can only filter rows for operations the role is allowed to attempt.
The fix, per the same guide: revoke the client roles' grants, then grant back only what each role needs — select only for data clients read but never write. Supabase has been changing the default so new tables no longer get automatic grants — new projects since 30 May 2026, all projects from 30 October 2026 — but that only affects tables created after the change. Tables that already exist keep the grants they have, so an existing app needs the revoke done by hand.
Pitfall 4: A missing with check lets users reassign ownership
A policy with only a using clause controls which existing rows a user can see and touch. It does not, on its own, control what the resulting row looks like after an update or insert. Supabase's guide calls this out: the with check expression on an update policy is what stops a user from reassigning user_id to someone else. Without it, a signed-in user can update their own row and set its user_id to another user's id — and then, under the using clause, that row is no longer theirs, but the damage is done: the other user's data now sits under a different owner, or the row becomes visible to the wrong account.
The fix is to pair the two clauses on every update policy:
create policy "users update their own invoices" on public.invoices for update to authenticated using ( (select auth.uid()) = user_id ) with check ( (select auth.uid()) = user_id );
For inserts, with check is the whole policy: it ensures a user cannot create a row that belongs to someone else. Write one policy per operation — Postgres does not accept multiple operations in one for clause, and a for all policy hides which operation each rule was meant to cover.
Pitfall 5: The secret key in the browser bundle
The publishable key is safe to ship in the browser — Supabase designed it that way, and Wiz put it the same way in the Moltbook write-up: the key is safe to expose when row-level security is configured. The secret key is the opposite. It maps to the service_role Postgres role, which has the BYPASSRLS attribute, so no policy you write ever applies to it. An agent that copies the secret key into frontend code, an env file the build inlines, or a seed script committed to the repo has handed every visitor a key that ignores every policy in this article. Supabase now rejects secret keys sent from a browser, and is deprecating the legacy anon and service_role keys by the end of 2026 — but a leaked secret key in an old bundle is still a live credential until it is rotated.
The fix is placement, not policy: the secret key belongs on the server only, in an Edge Function or backend that the browser calls, never in code the browser downloads. If a key has ever appeared in client code, rotate it; RLS cannot retroactively un-expose it. The companion piece on secrets hygiene for AI coding tools covers the exclusion rules and rotation discipline that keep keys out of prompts and bundles in the first place.
Pitfall 6: Views and helper functions that bypass RLS
The last pitfall is the one that passes a table-by-table audit. Views bypass RLS by default, because Postgres creates them with security definer — a view over a protected table hands out every row its policies were meant to withhold. On Postgres 15 and above, the fix is security_invoker = true on the view, so it obeys the underlying tables' policies for anon and authenticated. On older versions, revoke access from the client roles or move the view out of the exposed schema.
The same bypass applies to security definer functions: they run as the role that created them, and a function owned by postgres has bypassrls. That is a legitimate tool — it is how you break a recursive policy cycle, where two tables' policies read each other and Postgres raises 42P17, infinite recursion — but every such function is a hole you drilled on purpose. Supabase's guide requires pinning search_path = '' on each one and schema-qualifying every name inside it, because without a pinned search path a caller can point an unqualified name at their own object and run it with the function owner's privileges.
The options
Option 1: Fix it at generation time
Put the rule where the agent can see it: an AGENTS.md line and a path-scoped rule on supabase/ that refuses to commit a create table without enable row level security and per-operation policies in the same migration. This is the cheapest option — it costs a few lines of repo config — and it is the only one that stops the next table from shipping open. Its limit is that it depends on the agent reading and obeying the rule, and on a human reviewing the migration. It does nothing for the tables already in production.
Pick this first, always. It is the only option that compounds: every future migration inherits it.
Option 2: Fix the platform defaults
Install the ensure_rls event trigger so every new table gets RLS on automatically, revoke the default privileges so new tables are not exposed to the Data API until a grant allows it, and let Supabase's Security Advisor flag the tables that are still open. This is the guardrail layer: it catches the migration the prompt rule missed. Its limit is scope — the trigger only covers tables created after it is installed, in the public schema, and it writes no policies, so a new table returns nothing until policies exist, which is exactly when someone is tempted to add using (true).
Pick this alongside option 1. Defaults are the only defence that works when nobody is watching.
Option 3: Prove it after the fact
Audit what is already live, two ways. First, in the database: list every table with RLS off, and every policy whose condition is literally true.
select tablename from pg_tables where schemaname = 'public' and rowsecurity = false;
Second, as an attacker would: take only the publishable key, sign out, and query each table. If rows come back, the table is open — no tooling required, and this is exactly how Palmer, Wiz, and UpGuard found their numbers. For proof that survives the next deploy, Supabase documents a test pattern: one pgTAP file per table under supabase/tests/, asserting allow and deny for select, insert, update, and delete, for both anon and authenticated, run with supabase test db. A denied using filter returns zero rows silently rather than raising an error, so assert on the returned rows, not on the absence of an error.
Pick this for every app already in production, and keep the tests running in CI. An audit done once rots; a test suite fails loudly when a migration regresses a policy.
The comparison
| Approach | What it catches | When it helps | Cost | What it misses |
|---|---|---|---|---|
| Fix at generation time | Tables born without RLS | Every future migration | A few lines of repo config | Tables already live; agents that ignore the rule |
| Fix the platform defaults | New tables, missed migrations | Whenever nobody is watching | One trigger + grant revoke | Existing tables; policies (still unwritten) |
| Prove it after the fact | Open tables, using (true), leaked keys | Apps already in production | A pgTAP suite + a 2-minute probe | Nothing — if the probe runs on every deploy |
Trade-offs
The trade-off nobody puts in the demo is the empty-result trap. RLS on with no policy is default-deny: the app returns nothing, silently. That is the safe failure, and it is also the moment a tired developer or an agent reaches for using (true) or disables RLS to "make it work". Budget for the moment: when a query returns zero rows after RLS goes on, the fix is a policy, never a wider policy or a disabled switch.
The second trade-off is policy complexity against correctness. Shared rows — an order both buyer and seller can see — need both columns checked in the same policy, and policies that read other tables can recurse into each other until Postgres refuses the query. The escape hatch is a security definer function, which is also a bypass. Every such function is a deliberate hole; keep the list short, pin its search_path, and test it as a non-member, not just as the owner.
The third trade-off is performance. A policy expression runs against every candidate row, so an unindexed user_id filter turns reads into sequential scans — index every column your policies filter on. Wrapping auth.uid() in a select avoids a per-row function call. RLS is not free, but its cost is measurable and small next to the cost of the exposure it prevents.
And the trade-off teams forget: RLS is not a substitute for authentication. A policy that checks auth.uid() assumes the caller is who the token says they are. If login is checked only in the browser — one of Wiz's four recurring flaws — there is no trustworthy identity for the policy to check. The database can only enforce what the auth layer proves. The companion piece on securing AI agents covers the sandboxing side of the same principle: never trust the client, verify at the boundary that matters.
Recommendation
For any app an AI builder produced, run this sequence before the next deploy:
pg_tables query above. Every table with RLS off is open if the project still uses automatic grants.using and with check paired on updates, and the role named with to.anon and authenticated, then grant back only the operations each role needs.security_invoker = true on views over protected tables, pin search_path on every security definer function.If you run an app that already has users, do the inventory today: the Moltbook fix took several rounds over three hours because each round uncovered another exposed table. A list of tables with RLS off, run once, shows all of them at the same time.
When not to rely on RLS
Do not treat RLS as the access control for data that is genuinely public — a marketing page's content table, a public leaderboard. For that data, write the deliberate policy (to anon using (true) on a table that holds only public rows) and say so in a comment; a wide-open policy on a public table is a decision, the same policy on a users table is a bug. The difference is the data, not the SQL.
Do not put RLS between a backend job and its own database. Server-side jobs should use the secret key from the server, where it belongs, not fight policies written for browser clients. And do not expect RLS to save a schema where authorization data itself is user-editable — if a user can update their own role column, they can promote themselves. Keep authorization data in app_metadata, which users cannot update, not in user_metadata.
And do not audit your way out of a generation problem. If the builder keeps shipping open tables, the fix is the prompt rule and the platform default, not a monthly scan. The scan finds the holes; the defaults stop them being dug.
What to do next
This week, run the two-minute check on every Supabase project you own: the pg_tables query, then a signed-out probe of each table with the publishable key. If anything comes back, enable RLS and write the policies before the next feature ships — the zero-trust framing applies here literally: the database should trust no caller, only the policy. Then add the generation-time rule so the next table is born closed, and the pgTAP test so a future migration cannot quietly reopen it.
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.