RLS in Supabase, in short
Row-level security (RLS) is a Postgres feature that checks every query against rules you write, called policies, and lets it read or change only the rows those rules allow. In Supabase it’s the part of your app that decides who sees what, because the browser talks to your database directly.
Supabase’s own definition is that RLS “gives you granular authorization rules that run inside the database”. If you’ve built apps with a backend before, think of it as moving the “is this user allowed to see this?” check out of your server code and into the table itself.
This page explains the model: why Supabase needs RLS, what turning it on changes, what automatic RLS is, and the errors you’ll meet. For policy examples and the mistakes that leak data, see the guide on the Supabase RLS Generator page.
Why Supabase depends on it
In a classic web app, only your server talks to the database. It signs in with one database account and checks permissions in code before each query. Supabase removes that middle step for most reads and writes. Its Data API turns requests from the browser into SQL, so a request like “give me the notes table” reaches Postgres with no code of yours in between.
Here’s what happens to each request:
- The browser sends a key and, if someone is signed in, their access token. The publishable key (or the older anon key) is in your page’s code for anyone to copy. That’s by design: Supabase calls it “safe to expose online”.
-
Supabase picks a Postgres role. A request with no signed-in user runs as
anon; one with a valid user token runs asauthenticated, with the token’s claims available to SQL. A request with a secret key (or the older service_role key) runs asservice_role. - Postgres checks grants, then policies. The role needs a grant on the table first. Then RLS adds the conditions from your policies, row by row.
So the public key alone can reach any table the API serves. Without RLS, nothing stops a visitor from opening your browser console and reading every row. With it, the database itself refuses.
What turning RLS on changes
RLS is off on a new Postgres table until you turn it on. Once it’s on, Postgres denies by default: with no policies, no rows are visible and none can be changed. Each policy you add opens one kind of access for one set of roles.
| Table state | Visitors (anon) | Signed-in users | Secret key, SQL Editor |
|---|---|---|---|
| RLS off | Every row, read and write, if the role has grants | Every row, if the role has grants | Everything |
| RLS on, no policies | Nothing | Nothing | Everything |
| RLS on, with policies | Only what a policy for anon allows |
Only what a policy for authenticated allows |
Everything |
The last column never changes, and that surprises people. Supabase’s docs say a secret key
works through the
service_role role, which has the bypassrls attribute. In Postgres, superusers, roles with
that attribute and, normally, a table’s owner skip RLS. The SQL Editor in the dashboard runs as an admin, so a query
there shows every row whatever your policies say. Don’t judge your policies by what the SQL Editor returns.
How to turn RLS on
Tables created in the dashboard’s Table Editor start with RLS on. Supabase’s tables guide says the Table Editor enables it for you, and the editor now shows a warning label on any table with RLS off.
Tables you create in SQL don’t get it by themselves. That includes the SQL Editor, migration files, ORMs such as Prisma or Drizzle, and code an AI app builder writes for you. Turn it on in the same migration that creates the table:
alter table public.notes enable row level security;
The Security Advisor in your dashboard flags tables the API can reach with RLS off (lint
0013_rls_disabled_in_public), and tables with RLS on but no policies
(0008_rls_enabled_no_policy), which is safe but means the API returns nothing for them.
What automatic RLS is
“Automatic RLS” is an event trigger: a function Postgres runs after each create table, which turns RLS on
for the new table straight away. Supabase’s
event trigger docs
give the SQL for one, named ensure_rls, and Supabase’s
security review of 2025 says the
dashboard now offers a one-click setup for it.
Three things to know before you rely on it:
- It only covers tables created after it’s installed. Tables you already have keep whatever setting they had.
-
Supabase’s version covers the
publicschema only. Tables in other schemas you expose to the API need RLS turned on by hand. - It turns RLS on; it doesn’t write policies. New tables start closed, so your app gets no rows from them until you add a policy. That’s the safe failure.
To check a project, list the tables in public with RLS off and see whether a trigger is installed:
-- Tables in public with RLS off
select c.relname as table_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
and c.relkind in ('r', 'p')
and not c.relrowsecurity;
-- Is an event trigger installed? (Supabase's example is named ensure_rls)
select evtname, evtenabled from pg_event_trigger;
Policies: the rules RLS applies
A policy is a condition attached to a table, for one command and one or more roles. The easiest way to understand
one is as a where clause Postgres adds to every query. Take this policy:
create policy "Users read their own notes"
on public.notes for select
to authenticated
using ((select auth.uid()) = user_id);
Postgres treats queries against the table roughly like this:
-- What the browser asks for
select * from notes;
-- What Postgres runs for a signed-in user
select * from notes where (select auth.uid()) = user_id;
-- What Postgres runs for a signed-out visitor: no policy covers anon
select * from notes where false;
A few rules follow from that:
-
Policies add up. If several policies cover the same command, a row gets through when any of them
allows it. One loose policy undoes every careful one. Restrictive policies, created with
as restrictive, work the other way: every one of them must pass, on top of at least one ordinary policy. -
usingfilters rows that already exist;with checktests rows being written. Select and delete policies takeusing, insert policies takewith check, and update policies take both: which rows you may change, and what they may become. -
to authenticatednames who the policy is for. Supabase’s docs say to always name the role. Without it, the policy also runs foranon. - Missing rows aren’t errors. A select that no policy allows returns an empty list, not a permission error. An update or delete on rows the user can’t see changes nothing, and still reports success.
auth.uid() returns the signed-in user’s ID from their token, and auth.jwt() returns the
whole token, so policies can read claims such as app_metadata or the sign-in level aal. For a
visitor who isn’t signed in, auth.uid() is null, so a comparison with it is never true. Wrapping it as
(select auth.uid()) makes Postgres work it out once per query instead of once per row, which Supabase
recommends for speed, along with an index on every column your policies filter on.
Ready-made policies for owner-only data, public reads, roles, MFA and Storage are in the guide on the generator’s page, and the generator writes them for your own tables.
RLS and the rest of Supabase
The same policies protect more than the tables you query:
-
Storage. Files are rows in
storage.objects, and Storage allows no uploads to a bucket until a policy does. Public buckets serve files to anyone with the link; policies still decide uploads, changes and deletes. -
Realtime. Database change events are
checked against each
subscriber’s policies, except deletes, which RLS doesn’t filter. Broadcast and Presence channels use policies on
realtime.messages. -
Views. A view normally runs with its owner’s rights, and Supabase’s docs warn that views bypass RLS
by default. On Postgres 15 and later, create views with
security_invoker = trueso the policies on the tables underneath apply. - Edge Functions and your own server. Code using the secret key skips RLS, so it must make its own checks. Code that passes on the user’s token runs as that user, and policies apply.
Errors you’ll see after turning it on
- An empty list, no error
- No select policy lets this user see those rows. Check the policy’s role and condition, and that the user is signed in.
new row violates row-level security policy for table "…"-
An insert or update failed a
with check. It also appears when you insert and read the row back in one call, such as.insert(…).select()in supabase-js, and no select policy covers the new row. permission denied for table …(42501)-
The role has no grant on the table, so Postgres stops before RLS is asked. Grant the commands your policies use to
anonorauthenticated. infinite recursion detected in policy for relation "…"- A policy queries its own table, often a members table checking membership in itself. Move the lookup into a security definer function in a schema the API doesn’t serve, and call that from the policy.
- An update that reports success but changes nothing
- The update policy’s
using, or a missing select policy, hides the row from the update.
What RLS doesn’t cover
RLS decides which rows a role may touch, not which columns. If users may update their own profile row, they may also
change any column in it, including one your app trusts, such as is_admin or plan. Limit
columns with grants, or keep such fields in a table users can’t write:
-- A policy lets users update their own profile row...
create policy "Users update their own profile"
on public.profiles for update
to authenticated
using ((select auth.uid()) = id)
with check ((select auth.uid()) = id);
-- ...so limit which columns they may change, or they can set is_admin too
revoke update on public.profiles from authenticated;
grant update (display_name, avatar_url) on public.profiles to authenticated;
It also can’t help once a secret key leaks into the browser, or check rules that live only in your head, such as
“trial accounts can create three projects”. Put those in a with check, a trigger or server code.
Check your own project
The free Supabase RLS Generator works both ways. Describe who may do what and it writes the policies, grants and tests; or paste your migrations, or the result of one read-only query, and it lists tables left open, policies that allow everyone and the other leaks above, with SQL to fix each. It runs in your browser.
Policies read the claims in Supabase’s access tokens, so it helps to see what a real token carries: paste one into the JWT decoder. If your roles are multiplying, read RBAC vs ABAC before you add the next one.