Skip to content
ScanAnt

What is Supabase Row Level Security (RLS)?

Row Level Security (RLS) is a Postgres feature that Supabase uses to decide, row by row, who may read or write a table. Because the anon key in your app is public, RLS policies are the only thing stopping anyone from reading or changing your data directly through the API.

How it works

Supabase exposes your database through an automatic REST API. Your front-end calls it with the public anon key, which anyone can copy from the page. If RLS is off on a table, that key can read and often write every row. When RLS is on and a policy exists, Postgres applies the policy to each request, using the signed-in user's identity. With RLS on and no policy, access is denied. The service_role key bypasses RLS entirely, so it must never reach the browser.

alter table public.notes enable row level security;

create policy "Users read own notes" on public.notes
  for select using (auth.uid() = user_id);

create policy "Users write own notes" on public.notes
  for insert with check (auth.uid() = user_id);

How to tell if your site is affected

  • The Supabase dashboard shows a table with RLS disabled, or a warning that it is publicly readable.
  • A policy is written as using (true) or with check (true) for anon or authenticated users, which allows everyone.
  • Users can update fields such as role, plan or user_id on their own row.
  • Storage buckets are public or policies do not check the owner of the file.
  • The service_role key appears in your front-end code or an environment variable with a public prefix.

How to fix it

  1. Enable RLS on every table in the public schema: alter table ... enable row level security.

  2. Write explicit policies for select, insert, update and delete, scoped by auth.uid() = user_id, and use with check on inserts and updates.

  3. Avoid using (true) except for data that is truly public, and use separate policies for the anon and authenticated roles.

  4. Protect sensitive columns (role, plan, balance) with a trigger or by moving them to a table users cannot update.

  5. Keep the service_role key in server-only code and rotate it if it ever reached the browser. Test as an anonymous client and as two different users.

How ScanAnt checks for it

Quick scanVerified scanDeep scanCode scan

The free quick scan finds your Supabase project in the page and flags a leaked service_role key; the anon key itself is reported as normal. For verified owners, the verified scan reads at most one or two rows per table with the anon key to see which tables are readable, keeping only table and column names and counts, never values. The deep scan adds an anonymous insert that the database should refuse. The code scan flags tables without RLS and always-true policies in uploaded SQL.

Questions

Is the Supabase anon key a secret?

No. It is designed to be public. That is exactly why RLS must be correct: the key gives access to whatever your policies allow.

Is RLS enabled by default?

Tables created in the dashboard editor have RLS on by default today, but tables created with SQL, migrations or older projects may not. Check every table.

What happens with RLS on but no policies?

Access through the API is denied for anon and authenticated users. Your server using the service_role key can still read everything.

Why do apps from Lovable and Bolt often have RLS problems?

Generated apps work in the demo without policies, and an assistant may add permissive policies to make an error disappear. Review them before launch.

See if your site is affected

Free for any public site, no signup. Need the verified or deep scan? Choose the level on the scan page.

Choose a scan level →