Supabase Row Level Security Explained for People Who Ship Fast

Row level security is the lock on your Supabase tables. Here is what it does, how to turn it on, three policies you can copy, and the mistakes that leave data open.

Dr. Security3 MIN READ

💡 The short version: row level security (RLS) is a Postgres feature that decides, row by row, who may read or change your data. In Supabase it's the main thing standing between the internet and your tables. Turn it on for every table, then add a policy for each thing a user is allowed to do.

Supabase gives every project an API that talks straight to your database, and the key your frontend uses is public by design. So the question was never "can a stranger reach my database?" They can. The real question is what does the database let them do? RLS is the answer. 🔐

⏱️ How it works in 60 seconds

  • RLS off: anyone with your public key can use the table through the API, within whatever access the role has been granted.
  • RLS on, no policies: nothing comes back. Supabase's docs say that once RLS is enabled, no data is accessible through the API with a publishable key until you create policies. That's a safe default to build from.
  • RLS on, with policies: a row is visible or changeable only if a policy says yes.

1️⃣ Turn it on for every table

alter table public.todos enable row level security;

Do this for every table in a schema the API exposes, including the ones you made "just for testing". Supabase recommends enabling RLS on every table in an exposed schema, and mentions you can use an event trigger to do it automatically for new tables.

2️⃣ Add the policies you need

Three patterns cover most apps. They use auth.uid(), the id of whoever is signed in.

Users see only their own rows

create policy "read own todos"
on public.todos for select
to authenticated
using ( (select auth.uid()) = user_id );

Users can add rows, but only as themselves

create policy "insert own todos"
on public.todos for insert
to authenticated
with check ( (select auth.uid()) = user_id );

Anyone can read, only the owner can change

create policy "public read"
on public.posts for select
to anon, authenticated
using ( true );

create policy "owner update"
on public.posts for update
to authenticated
using ( (select auth.uid()) = author_id )
with check ( (select auth.uid()) = author_id );

Notice that "anyone can read" is written down on purpose. That's the difference between a public blog table and an accident.

⚠️ Mistakes that still leave data open

  • A table without RLS. The API can read and write it. Fix: enable RLS and add policies.
  • using ( true ) on a private table. Every row is public. Fix: tie the policy to auth.uid().
  • A view over a protected table. Views bypass RLS by default, because they're usually created by the postgres user. Fix: on Postgres 15+, set security_invoker = true. On older versions, keep the view in an unexposed schema or revoke access from anon and authenticated.
  • The secret (service_role) key in the frontend. It bypasses RLS entirely. Fix: use it only on a server, and rotate it if it ever shipped.
  • A public storage bucket you forgot. Files, and sometimes the file list, are open. Fix: make it private and add storage policies.

🕵️ See what a stranger can see

Don't test while you're signed in as yourself. Open a private window, or call your project's API with only the publishable key, and try to read each table. If rows come back that shouldn't, a policy is missing or too wide.

On a paid plan, once you've verified you own the site, Dr. Security can do a first pass for you: it checks whether the Supabase backend your public code points at answers to anyone, read-only, and reports exposed table names, never their contents.

Using Lovable? Pair this with the 12-point Lovable checklist.

🚀 Not sure what your site gives away? Run a free scan and see what comes back.

  • supabase row level security
  • supabase rls
  • supabase security
  • rls policies
  • postgres rls

FIND OUT WHAT YOU'RE EXPOSING.