Supabase RLS Mistakes AI Tools Make (and How to Test for Them)
Supabase is a common backend for apps built with Lovable, Bolt, v0 and Cursor. It is a good choice. Its security model also assumes you understand one rule: the browser talks to your database directly, and RLS policies decide what each request may see.
Mistake 1: RLS disabled on a table
New tables created with SQL have RLS off. The Supabase dashboard warns about it; code generators don't always notice.
sql select schemaname, tablename from pg_tables where schemaname = 'public' and rowsecurity = false;
Every table in that list is readable and writable by anyone with your anon key, unless you revoked access another way.
Mistake 2: a policy that allows everything
sql create policy "Enable read access for all users" on public.orders for select using (true);
This is the default template name in the dashboard, and AI tools copy it. RLS is "enabled", the warning disappears, and every row is public. Find them:
sql select tablename, policyname, cmd, qual, with_check from pg_policies where schemaname = 'public' and (qual = 'true' or with_check = 'true');
The fix compares the row owner to the caller:
sql create policy "Users read own orders" on public.orders for select using (user_id = (select auth.uid()));
Mistake 3: select is protected, update is not
Policies are per operation. A table with a correct policy and a lax policy lets a user modify rows they can't see, for example changing on another user's record. Check every table has policies for , , and that match what the app needs, and nothing more.
Mistake 4: insert without
controls which existing rows a user can touch. controls what the new row may contain. Without on insert or update, a user can create rows owned by someone else:
sql create policy "Users insert own orders" on public.orders for insert with check (user_id = (select auth.uid()));
Mistake 5: trusting a role stored where the user can edit it
A common generated pattern stores in a table and checks it in policies. If the same table lets users update their own profile row, any user can make themselves an admin. Keep roles in a table users can't write to, or in the JWT , which only the server can set.
Mistake 6: the service role key in the browser
The service role key bypasses RLS completely. It belongs only in server code. Search the built JavaScript, not only the source:
bash grep -r "service_role" .next/static/ dist/ build/ 2>/dev/null
In Next.js, any variable prefixed is shipped to the client. is a leaked key. Rotate it in the Supabase dashboard, then move the code that needed it into a server route.
Mistake 7: storage buckets set to public
Supabase Storage has its own policies. A bucket marked public serves every file to anyone with the URL, and file names are often guessable (, ). Private documents belong in private buckets with policies tied to , served through signed URLs.
The two-account test
SQL queries show you the policies. Only a test shows they work.
- Create user A and user B in your app.
- As B, create some data: an order, a document, a message.
- Log in as A. In the browser console, use the Supabase client the app already loaded:
js
const { data, error } = await supabase.from('orders').select('*');
console.log(data); // should contain only A's rows
await supabase.from('orders').update({ total: 0 }).eq('id', '
- Repeat for every table with user data and every storage bucket.
If any query returns or changes B's data, you have a leak. Add the test to your CI with two seeded test users, so a future AI-generated migration can't quietly reopen it.
How long does this take?
For a typical app with 10-20 tables, finding the problems takes an hour or two with the queries above. Fixing them takes longer when the data model has no clear owner column, because the fix then needs a migration.
RLS is check number 2 in our . If you would rather have someone run the full list and fix what it finds, see our
.
Preguntas frecuentes
¿Qué servicios ofrecemos?
Nos especializamos en crear soluciones digitales innovadoras, incluyendo desarrollo web, aplicaciones móviles, sistemas CRM y software empresarial. Nuestros servicios se adaptan a las necesidades específicas de tu negocio para impulsar el crecimiento.

Oleksii Stupak
CEO en AleannLab
"¿Quieres explorar cómo podemos ayudar a que tu negocio crezca? Conectemos y conversemos sobre tu proyecto en LinkedIn."
¿Listo para hablar de tu proyecto con nosotros?




