Short answer
A table in the public schema without row level security (RLS) answers every request that its grants allow, and with Supabase’s default grants that includes visitors who are not signed in. Anyone who copies the public key from your site can read, change and delete every row. Enable RLS, add owner policies, revoke what signed-out visitors don’t need, and test as a second user.
Ask an AI about this page:ChatGPTClaude
On this page
A table without row level security (RLS) has no rule about who may see which row. In a Supabase app the browser talks to the database directly with a public key, so such a table hands every row to whoever asks: other users, and with Supabase’s default grants also visitors who never signed in. It is rated critical because it needs no account, no skill and no guessing: one request with the key from your site’s JavaScript is enough.
Why it matters
Supabase serves tables in the public schema through its Data API. Supabase’s own docs say that tables exposed this way without RLS “can be accessed by any role with matching grants”, and depending on when your project was created, new tables in public get those grants automatically. Postgres starts every new table with RLS off, and AI builders create tables with SQL migrations. Unless the migration contains the line that switches RLS on, the table is open.
This is the migration from one of our own test apps, a small document manager we deliberately built with this mistake:
create table public.documents (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references auth.users (id) on delete cascade,
title text not null,
content text not null default '',
created_at timestamptz not null default now()
);
grant select, insert, update, delete on table public.documents to anon, authenticated;In the app everything looks right, because the React hook asks for .eq("user_id", userId) and each user only sees their own documents. But that filter is a convenience, not protection. A visitor who leaves it out reads every user’s documents, and can edit or delete them too. Our audit engine found exactly this in our test apps: it reported the migration and the client-only filter in src/hooks/useDocuments.ts as one critical finding.
How to find it in your app
First open Advisors → Security Advisor in the Supabase dashboard. Lint 0013 (rls_disabled_in_public) lists tables in public without RLS. Then run this query in the SQL Editor. It lists every such table and shows whether signed-out visitors (anon) and signed-in users can read it:
select c.relname as table_name,
has_table_privilege('anon', c.oid, 'select') as visitors_can_read,
has_table_privilege('authenticated', c.oid, 'select') as users_can_read
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
and c.relkind in ('r', 'p')
and not c.relrowsecurity
order by 1;Every row is a problem. A true in either column means the Data API will answer for that role without any row check. Tables that only your server uses still need RLS: switch it on and add no client policies.
How to fix it
Add a new migration; don’t edit the one that already ran. For a table where each row belongs to one user, this is the complete fix:
alter table public.documents enable row level security;
revoke all on table public.documents from anon;
create policy "Owners can read their documents"
on public.documents for select
to authenticated
using ((select auth.uid()) = user_id);
create policy "Owners can add documents"
on public.documents for insert
to authenticated
with check ((select auth.uid()) = user_id);
create policy "Owners can edit their documents"
on public.documents for update
to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy "Owners can delete their documents"
on public.documents for delete
to authenticated
using ((select auth.uid()) = user_id);
create index if not exists documents_user_id_idx on public.documents (user_id);enable row level security switches on the default deny: from now on no row gets through unless a policy allows it. revoke all … from anon removes access for signed-out visitors as a second lock. Wrapping auth.uid() in select lets Postgres compute it once per query, and the index keeps the policy fast. The Supabase RLS guide explains each part and covers shared team data, which needs a membership check instead of an owner check.
If you build with an AI tool, paste this prompt and read the migration it writes before you apply it:
Add a new Supabase migration for the table public.documents (replace with your table name and owner column). Enable row level security on it. Revoke all privileges on it from the anon role. Create four policies for the authenticated role only: select, insert, update and delete, each allowing access only when (select auth.uid()) = user_id. The update policy needs both USING and WITH CHECK. Add an index on user_id if none exists.
Do not edit existing migrations, do not disable RLS on any table and do not use the service role key in browser code. Afterwards, list every other table in the public schema that still has RLS disabled.
Check that the fix works
The SQL Editor and the secret key skip RLS, so they prove nothing. Pretend to be a visitor and a user inside a transaction that you roll back:
begin;
set local role anon;
select count(*) from public.documents;
rollback;
begin;
set local role authenticated;
set local request.jwt.claims = '{"sub": "11111111-1111-1111-1111-111111111111", "role": "authenticated"}';
select count(*) from public.documents;
rollback;The visitor block should now fail with permission denied for table documents. For the user block, put in a real user ID from Authentication → Users: the count must match that user’s documents only. Repeat with a second user ID, then run the check query again: documents must no longer appear. For more patterns, see how to test your RLS policies. If the table needs to be shared rather than private, the policies change, but never back to using (true) for everyone.
Frequently asked questions
Does Supabase turn on RLS automatically for new tables?
Not for tables created with SQL. In Postgres a new table starts with row level security off, and AI builders create tables through SQL migrations. Run the check query on this page instead of assuming.
Is it enough to filter by user_id in my frontend code?
No. The filter only runs because your own code asks for it. Anyone calling the Data API with your public key can leave it out and get every row. The rule has to live in the database.
My table only holds public data. Do I still need RLS?
Yes, but the policy can be simple. Enable RLS, allow select for everyone, and give no write policy to anon or signed-in users. Without RLS, visitors could also change or delete that public data.
Will enabling RLS break my app?
It will block every query until you add policies, so add them in the same migration. If lists suddenly show up empty after the change, a select policy is missing.
Sources
- 1.Row Level Security — Supabase Docs
- 2.Securing your API — Supabase Docs
- 3.Performance and Security Advisors — Supabase Docs
- 4.Row Security Policies — PostgreSQL Documentation
- 5.CWE-862: Missing Authorization — MITRE
- 6.A01 Broken Access Control — OWASP Top 10