Blog · 8 min read
Supabase RLS mistakes your AI assistant made.
By the Obra Insights team ·
Supabase is the default backend for a huge share of vibe-coded apps. It's a great choice, but it comes with one rule that AI assistants routinely get wrong: your anon key is public, so Row Level Security is the only thing standing between strangers and your data.
Anyone who opens your site can find the project URL and anon key in the JavaScript bundle. That's by design. It's only safe if every table has RLS turned on with the right policies. Here are the mistakes we see most often in AI-built apps, and how to fix them.
1. RLS is turned off on a table
Tables created through the SQL editor or a migration don't get RLS automatically, and assistants often generate create table statements without enabling it. Open the Supabase dashboard, go to Advisors, then Security Advisor, and look for "RLS disabled in public." Fix each table:
alter table public.projects enable row level security;
Enabling RLS with no policies blocks all access through the API, so your app will "break" right away. That's expected. Add the policies below next.
Heads up: new tables need explicit grants from October 30, 2026
Supabase is changing a default. Starting October 30, 2026, new tables you create in the public schema on existing projects are no longer exposed to the Data API (the REST and GraphQL layer supabase-js uses) until you grant access. Projects created since late May 2026 already work this way. Existing tables keep their grants. A new table without a grant returns 42501 permission denied for table ..., even with correct policies. (Supabase changelog)
The danger is the "fix" your assistant reaches for: turning off RLS or granting everything to anon. Instead, have every migration that creates a table do three things together: grant only the roles and operations the app uses, enable RLS, and add owner policies.
grant select, insert, update, delete on public.projects to authenticated;
alter table public.projects enable row level security;
-- then the owner policies below
Only grant to anon if logged-out visitors genuinely need that table.
2. The "fix" was using (true)
When the app breaks after RLS is enabled, the quickest prompt answer is a policy like using (true). That makes the table readable by everyone again. Write policies that tie each row to its owner instead:
create policy "Owners read their projects" on public.projects
for select to authenticated
using ((select auth.uid()) = user_id);
create policy "Owners insert their projects" on public.projects
for insert to authenticated
with check ((select auth.uid()) = user_id);
Add matching update and delete policies. Wrapping auth.uid() in select lets Postgres evaluate it once per query instead of once per row, and an index on user_id keeps these queries fast as the table grows.
3. Update policies without with check
An update policy with only using controls which rows a user can change, but not what they change them to. Without with check, a user can update their own row and set user_id to someone else's ID, or flip a plan column to "pro." Give update policies both clauses, and keep sensitive columns like plan, credits, and role out of tables users can write to.
4. Roles stored where users can edit them
A common AI-generated pattern is checking user.user_metadata.role === "admin". User metadata can be changed by the signed-in user. Store roles in app_metadata (only server code with the service role can set it) or in a separate user_roles table that users can read but not write. Then check the role in your RLS policies or server code, not just by hiding buttons in the UI.
5. The service_role key in the frontend
The service_role key bypasses RLS entirely. If an assistant "fixed" a permissions error by swapping it in, every visitor now has admin access to your database. Search your built files and your repo for it. If you find it in client code, move that operation into a server function or Edge Function, then rotate the key in the dashboard. Deleting it from the code isn't enough; assume it has already been copied. Our guide to leaked API keys in AI-built apps covers how to look.
6. Views and functions that skip RLS
Two quieter holes:
- Views run with the permissions of whoever created them by default, which usually means RLS doesn't apply. On Postgres 15 and later, create views with
with (security_invoker = true)so the caller's policies are enforced. - Functions marked
security definerrun as their owner and can be called through the API withrpc(). Only use them when you have to, checkauth.uid()inside them, and set a fixedsearch_path.
7. Storage buckets left public
Uploaded files live in Supabase Storage, which has its own policies on storage.objects. A public bucket means anyone with the URL can download the file. For invoices, ID photos, or anything private, use a private bucket, store files under a folder named after the user's ID, and add policies that check that folder against auth.uid(). Serve files with signed URLs that expire.
8. Trusting the session on the server
In server code (API routes, server components, middleware), getSession() reads whatever is in the cookie without re-verifying it. To decide whether a request is allowed, verify the user with getUser() (or verified JWT claims) before you trust the user ID. This matters most anywhere you use the service role key, because RLS won't catch the mistake for you.
Two tests that take five minutes
The anon test. Copy your project URL and anon key from the browser, then request a table directly, as a logged-out stranger would:
curl "https://YOUR-PROJECT.supabase.co/rest/v1/projects?select=*" \
-H "apikey: YOUR_ANON_KEY"
You should get an empty list or an error, never real rows.
The two-user test. Sign up as User A and create something. In a private window, sign up as User B and try to read or edit A's item, through the UI or by replaying A's request with B's token. If B can see A's data, fix that before you launch. More on this in how to fix a broken vibe-coded app.
Get a second opinion
RLS problems are invisible until someone goes looking, and the people who go looking aren't always friendly. Our free app scan checks a public URL for exposed keys and obvious misconfigurations. The $99 Health Scan reviews your policies table by table, and a $149 Quick Fix covers a single issue like one leaky table, delivered as a pull request you approve.