Supabase Row Level Security: the mistakes AI-built apps make
Why RLS is the most common critical issue in Supabase apps built with AI tools, the six mistakes behind it, and how to test your policies.
Samed Škulj
· 3 min read
Supabase lets the browser talk to your database directly, using a public "anon" key. That is safe only if Row Level Security (RLS) decides, for every row, who may read or change it. When RLS is missing or wrong, anyone who opens the browser's dev tools can query your tables with the same key your app uses.
This is the most common critical issue I find in apps built with Lovable, Bolt, v0 and similar tools. Here are the mistakes behind it and how to check your own app.
Mistake 1: RLS is turned off
A table without RLS enabled is readable and writable by anyone with the anon key. Check every table in the public schema:
select tablename, rowsecurity
from pg_tables
where schemaname = 'public';
Any row with rowsecurity = false needs fixing, unless the table is meant to be fully public.
Mistake 2: RLS is on, but the policy allows everything
A policy like this is the same as no policy:
create policy "Allow all" on bookings
for all using (true);
AI tools sometimes generate it to make an error go away. The app works, and so does the data leak.
Mistake 3: checking login, not ownership
create policy "Logged in users can read" on bookings
for select using (auth.role() = 'authenticated');
This lets every signed-up user read every booking. The policy must tie the row to the user or their organization:
create policy "Members read their organization's bookings" on bookings
for select using (
organization_id in (
select organization_id from memberships
where user_id = auth.uid()
)
);
Mistake 4: forgetting insert and update checks
A correct select policy doesn't stop a user from inserting a row into another organization, or updating a row to move it there. Use with check on insert and update policies so the new values are validated too:
create policy "Members update their organization's bookings" on bookings
for update
using (organization_id in (select organization_id from memberships where user_id = auth.uid()))
with check (organization_id in (select organization_id from memberships where user_id = auth.uid()));
Mistake 5: users can edit their own role
If a profiles table has a role or plan column and users may update their own profile, they can make themselves admins or upgrade themselves for free. Keep privileged fields in a separate table that users can't write to, or restrict updates to specific columns.
Mistake 6: the service role key in the frontend
The service role key bypasses RLS completely. It must only exist on the server. If your build includes something like VITE_SUPABASE_SERVICE_KEY or NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY, assume it's compromised: rotate it and move the code that needs it into a server function.
Also check: views, functions and storage
- Views can bypass RLS depending on how they're defined. Use security invoker views where your Postgres version supports them, or restrict access.
- Functions marked
security definerrun with their owner's rights. Make sure they check the caller themselves. - Storage buckets have their own policies. A public bucket full of invoices is a data leak too.
How to test your policies
Don't trust policies you haven't tried to break. For each table:
- Sign in as user A in organization 1.
- Try to read, insert, update and delete a row belonging to organization 2, using the Supabase client directly from the browser console.
- Every attempt should fail or return nothing.
Turn this into an automated test that runs in CI, and add a check that fails if a new table is created without RLS. That stops the problem from coming back with the next AI-generated migration.
RLS review is the first step of every AI-built app rescue, and it's finding #1 in the sample audit report. For the other common issues, see the security holes I see most in AI-built apps.

Written by Samed Škulj
Senior Full-Stack Engineer since 2021. I have shipped with teams at Deel, HTEC Group (for Zoox), Ministry of Programming, and now help SaaS teams add AI features and get AI-built apps ready for production. LinkedIn