Supabase RLS disabled: how to tell if your tables are open and fix it in 15 minutes
If your Supabase tables return data to anyone holding your anon key, Row Level Security is off or too loose. Here is how to find out and fix it in about fifteen minutes. How to tell if a table is open Your anon key is i
If your Supabase tables return data to anyone holding your anon key, Row Level Security is off or too loose. Here is how to find out and fix it in about fifteen minutes.
How to tell if a table is open
Your anon key is in your frontend. Anyone can copy it. Ask the REST endpoint for a table with only that key and no user session. If it returns rows, the table is readable by the public. A count-only request tells you how many rows without reading any of them.
The usual causes
- RLS never turned on for that table.
- RLS on, but a policy of
using (true)that allows everyone. - A policy that checks the wrong column, or only covers
selectand forgetsinsert,updateanddelete. - A storage bucket set to public that holds private files.
The fix
Enable RLS, then write policies tied to the signed-in user:
alter table profiles enable row level security;
create policy "read own profile"
on profiles for select
using (auth.uid() = user_id);
create policy "update own profile"
on profiles for update
using (auth.uid() = user_id)
with check (auth.uid() = user_id);
Repeat for insert and delete if the app needs them. Do not leave using (true) on a table that holds user data.
Test it with two users
Create user A and user B. Sign in as B and try to read A's rows. Then try signed out. Both must fail. A screenshot of the policy editor is not a test.
Do not forget
- The
service_rolekey bypasses RLS. It must never be in browser code. - Public storage buckets are not covered by table policies.
ProofForge's free scan checks your public bundle and counts rows an anonymous visitor can read, without reading row contents or using any key it finds. Free first look: https://proofforge.live/fix/supabase-rls-disabled
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.