Supabase Row Level Security is off, and it is leaking your data
Supabase gives every project a public "anon" key that ships inside your frontend, and it exposes your Postgres tables over an auto-generated REST API. On its own that is fine. The problem is what protects the rows: Row Level Security (RLS). If RLS is off, or on but with no policy, that public key can read and write every row in the table.
This is the single most common critical bug in apps built with Cursor, Lovable and Bolt, because the AI writes working queries but rarely turns RLS on for you.
Why it matters
The anon key is not a secret. It is meant to be public, so anyone can open your app, read it out of the network tab, and talk to your database directly. With RLS off, a request like GET /rest/v1/profiles?select=* returns every user’s row: emails, names, whatever the table holds. If write access is open too, an attacker can edit or delete other people’s data.
How do I check if RLS is enabled?
There are two quick ways:
- In the Supabase dashboard, open Table Editor and look for the "RLS enabled" state on each table that holds user data.
- Or, using only your public anon key, call the table’s REST endpoint as an anonymous user. If you get back rows that should be private, RLS is not protecting them.
- Scanwright runs this check for you and shows exactly which tables are exposed.
Enable RLS on every table that holds user data, then add policies that tie each row to its owner. The anon key stays public; the policies are what keep one user out of another user’s rows.
- Open Supabase and go to the SQL Editor.
- Enable RLS on the affected table and add a policy for each operation (select, insert, update).
- Replace the table and owner column with your own, then run it.
- Re-test with the anon key to confirm you can no longer read other users’ rows.
alter table public.profiles enable row level security;
create policy "read own rows" on public.profiles
for select using ( auth.uid() = user_id );
create policy "insert own rows" on public.profiles
for insert with check ( auth.uid() = user_id );
create policy "update own rows" on public.profiles
for update using ( auth.uid() = user_id );
FAQ
Does enabling RLS break my app?
It can, if your app relied on the table being open. After enabling RLS, requests that are not covered by a policy return no rows. Add a policy for every access pattern your app needs (usually "the signed-in user can see their own rows"), and use the service_role key only on the server for admin work.
Is the Supabase anon key a secret I should hide?
No. The anon key is designed to be public and shipped in the browser. Hiding it is not a security control. RLS policies are what actually protect your data.
What is the service_role key then?
The service_role key bypasses RLS entirely and must live only on your server, never in the browser or a committed file. If it ever leaks, rotate it immediately.