How to check if RLS is enabled on every Supabase table
How to check whether the Supabase anon key can read every row of a public table the Data API exposes when row level security is off.
By ShipSecurely Editorial · Updated · How we make these guides
Shows up in: Supabase, Postgres, Next.js
What it is
Yes. For a table in the public schema that the Data API exposes, with row level security off, the anon key can read every row. Securing your API says tables and views exposed through the Data API without row level security can be accessed by any role with a matching grant. The API keys guide says the legacy anon key is the older publishable key, and a publishable key with nobody signed in uses the anon role. The database linter says that if row level security is not enabled on a public table, anyone with the project's URL can read, edit, and delete all data in that table. That check is rls_disabled_in_public.
The publishable key, and the older anon key, are meant to ship in the browser. The key is not a password. Postgres row level security is what decides which rows that key can touch.
Turning RLS on with no policies blocks the anon and authenticated roles. That is safer than leaving RLS off, and it will make the app look empty until you add the policy you actually want. A policy of using (true) puts you back where you started.
The secret key (sb_secret_..., and the legacy service_role key) bypasses RLS. A tight policy does not protect queries made with that key. See secret keys in the frontend.
To see whether the anon key can already read a row, use the free Supabase RLS checker. It runs in your browser. A missing grant on a new table is a different failure, covered in Supabase's Oct 30 change: new tables aren't exposed automatically.
How do I check if RLS is enabled on every Supabase table?
pg_tables.rowsecurity is true when row security is enabled on the table. Run this in the SQL editor on a project you own. A rowsecurity value of false means row security is not enabled.
select tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;
PostgreSQL's pg_tables page does not print this statement. schemaname is the schema, tablename is the table, and rowsecurity references pg_class.relrowsecurity. The result is tables in public. A false value on a table the Data API exposes is the case Securing your API describes.
Row security can be on and still allow every row. Row Level Security says a policy of to anon using ( true ) grants every unauthenticated visitor read access to every row the role can already reach through grants. The database linter's permissive_rls_policy check says a permissive USING (true) policy lets the specified role read all rows on SELECT. pg_policies.qual is the expression added to queries the policy applies to, which is the USING expression in CREATE POLICY. That command says policies are permissive by default. pg_policies.permissive is text for whether the policy is permissive or restrictive. This statement keeps public policies where that column is PERMISSIVE and qual is true, the text a using (true) policy stores:
select tablename, policyname, roles, cmd, qual
from pg_policies
where schemaname = 'public'
and permissive = 'PERMISSIVE'
and qual = 'true'
order by tablename, policyname;
pg_policies does not print this statement. A returned row is a permissive using (true) policy. roles lists the roles it applies to. CREATE POLICY says the default is PUBLIC, which applies the policy to all roles. cmd is the command, such as SELECT.
The linter also flags WITH CHECK (true) and USING (1 = 1). This statement matches qual = 'true' only. An insert policy cannot have a USING expression, so a with check (true) policy leaves qual null and stores the check in with_check. A restrictive policy with using (true) has permissive RESTRICTIVE, and CREATE POLICY says restrictive policies are combined with AND. If only restrictive policies exist, no records are accessible, so this filter leaves that row out.
How to check in 5 minutes
In the Supabase dashboard, open the Security Advisor, or run
supabase db advisorsfrom the CLI. Look for RLS disabled on tables inpublic.In the SQL editor, run the
pg_tablesquery above and readrowsecurity. False means row security is not enabled. A table the Data API exposes with that flag false is the bug.In a private browser window, call the Data API with only the publishable key and no user session. If you can
selectanother person's rows, RLS is not doing the job. Do this on your own project, not someone else's.Run the
pg_policiesquery above, then read every other policy.qualoftrueisusing (true). A policy that never comparesauth.uid()to an owner column means any signed-in user, and sometimes anyone, can read the table.
How to fix
Supabase
Enable RLS, then add a policy that matches the real rule, usually "a signed-in user may access their own rows."
alter table public.notes enable row level security;
create policy "notes_select_own"
on public.notes
for select
to authenticated
using (auth.uid() = user_id);
create policy "notes_insert_own"
on public.notes
for insert
to authenticated
with check (auth.uid() = user_id);
create policy "notes_update_own"
on public.notes
for update
to authenticated
using (auth.uid() = user_id)
with check (auth.uid() = user_id);
create policy "notes_delete_own"
on public.notes
for delete
to authenticated
using (auth.uid() = user_id);
Write separate policies for select, insert, update, and delete. An insert policy needs with check, not only using. Afterward, repeat the anonymous API call and confirm it returns nothing it should not.
Do not store a role or plan on auth.users raw user metadata and trust it inside a policy. Supabase documents that end users can change user_metadata through the client libraries. Put privileged flags in a table the user cannot update.
Views and materialized views need extra care. A view can bypass the underlying table's RLS unless it is created with security_invoker = on. Materialized views cannot use RLS. Do not expose those to the anon or authenticated roles if they contain private rows. To check your views, see Do Supabase views bypass RLS?.
Next.js
If a Server Component or Route Handler uses the secret key, RLS does not run. Filter by the signed-in user's id in that query, or stop using the secret key for ordinary user requests and use the publishable key plus the user's session so RLS applies.
Firebase
Firestore does not have Postgres RLS. The same class of bug is an open rules file. Use Firebase rules left open.
Vercel
Vercel hosts the app. It does not enable RLS on your Supabase project. The fix is in Supabase, then a redeploy only if the app was depending on the open table.
Copy the fix prompt
Paste this into Cursor, Lovable, Bolt, or Claude Code. Read the diff before you merge it.
You are fixing database access in this repository. Do not add features. The Supabase Data API exposes tables in the public schema. Row level security must be enabled on every table that should not be world-readable, and policies must match the real rule (usually auth.uid() = user_id). A policy of using (true) is not a fix. Do this: 1. Find every table the app reads or writes, including ones created in supabase/migrations or SQL strings. 2. Enable RLS on each private table. 3. Add separate select, insert, update, and delete policies. Insert and update need with check. 4. Do not use user_metadata for authorization. Users can edit it. 5. If any server code uses the secret key or service_role, list those call sites. Do not leave a user-facing request on that key unless the code checks the session and filters by that user. 6. Do not weaken a policy to make a failing query pass. If you cannot tell who should see a row, stop and ask. Show the SQL and the files you changed. Then tell me how to confirm an anonymous request cannot read another user's row.
Questions
Can the Supabase anon key read every row?
Yes. For a table in the public schema that the Data API exposes, with row level security off, the anon key can read every row. Securing your API says a table or view exposed through the Data API without row level security can be accessed by any role with a matching grant. The API keys guide says the legacy anon key is the older publishable key, and a publishable key with nobody signed in uses the anon role. The database linter says that if row level security is not enabled on a public table, anyone with the project's URL can read, edit, and delete all data in that table.
How do I check if RLS is enabled on every Supabase table?
pg_tables.rowsecurity is true when row security is enabled. In the SQL editor on a project you own, run:
select tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;
A rowsecurity value of false is a public table with row level security off. Then run:
select tablename, policyname, roles, cmd, qual
from pg_policies
where schemaname = 'public'
and permissive = 'PERMISSIVE'
and qual = 'true'
order by tablename, policyname;
A row is a permissive policy whose USING expression is true. pg_policies.qual is that expression. Row Level Security says to anon using ( true ) grants every unauthenticated visitor read access to every row the role can already reach through grants.
Is the publishable key supposed to be in the browser?
Yes. Supabase's API key docs say the publishable key is safe to ship because anyone can read it, and it only reaches what row level security allows. The secret key is the one that must stay on the server. A publishable key in the client with RLS off is the bug. A publishable key in the client with RLS on is normal.
What if enabling RLS breaks the app?
That usually means the app was reading rows the policies will now hide. Add the narrow policy the screen needs, or move that one query to a server path that checks the session. Do not disable RLS to get the data back.
Does RLS on its own stop a secret key?
No. Supabase documents that secret keys use the service_role Postgres role, which has BYPASSRLS. Policies never apply to that key.
Sources
Related
Guides
Need someone to fix it for you? See /help.
The weekly fix
The weekly fix: 3 real security mistakes in vibe-coded apps and how to fix them, every Tuesday.