Why Supabase needs it
In a typical Supabase app, the browser talks to the database directly through Supabase's API, using the project's public key. That key is in your front-end code, so anyone can copy it and call the same API. Supabase's API key docs are clear that this is by design: the public key is safe to share as long as Row Level Security (RLS) controls what it can do.
RLS is a PostgreSQL feature. When it's on for a table, every query is checked against that table's policies, row by row. A policy is a rule like "a user may read a row if the row's user_id is their own id".
Three states a table can be in
RLS off
The policies don't apply, and what the public key can do depends only on the database permissions it has. For tables in an exposed schema, that can mean anyone with your public key reads, and possibly writes, the whole table.
RLS on, no policies
Nothing is readable through the API with the public key. Supabase's RLS docs describe this: once RLS is enabled, no data is accessible with the public key until you create policies. It's safe, but your app won't see its data either, which is when people are tempted to add a policy that allows everything.
RLS on, with policies
This is where you want to be. Each operation (select, insert, update, delete) has a policy saying who may do it.
How a policy knows who's asking
When a signed-in user calls the API, Supabase passes their identity to the database. Inside a policy, auth.uid() returns that user's id. Requests with the public key and no signed-in user run as the anon role; signed-in users run as authenticated.
A common "owner only" policy for reading looks like this:
create policy "Users read their own orders"
on orders for select
to authenticated
using ( (select auth.uid()) = user_id );
For inserts and updates, the check goes in with check, so users can't write rows that belong to someone else:
create policy "Users add their own orders"
on orders for insert
to authenticated
with check ( (select auth.uid()) = user_id );
Mistakes that expose data
A policy of "true"
using (true) on a select policy means everyone can read every row. That's right for public content like a product list and wrong for anything personal.
"Signed in" instead of "owner"
A policy that only checks that someone is signed in lets every user read every other user's rows. Sign-up is usually open, so this is barely better than public.
Forgetting update and delete
Locking down select and leaving update open lets users change other people's rows, or change their own row in ways you didn't intend, like setting their own role to admin or their plan to paid.
Storage buckets
Files have policies too, on Supabase Storage (storage access control docs). A public bucket or a broad policy can let anyone list and download your users' uploads.
Functions that skip RLS
Database functions declared security definer run with their owner's rights, which can bypass RLS. If such a function can be called with the public key, it can become a way around your policies. Revoke execute permission for anon on functions that shouldn't be public.
The service key in the front end
The secret (service_role) key bypasses RLS completely. If it's in your website's code, your policies don't matter. It belongs only on servers.
A worked example: a small notes app
Say your app has two tables: profiles (a display name and avatar for each user) and notes (private notes). The access you want is different for each.
Profiles: everyone reads, owners edit
Other users need to see display names, so reading can be open. Changing a profile can't.
alter table profiles enable row level security;
create policy "Profiles are visible to everyone"
on profiles for select
to anon, authenticated
using ( true );
create policy "Users update their own profile"
on profiles for update
to authenticated
using ( (select auth.uid()) = id )
with check ( (select auth.uid()) = id );
Note what "visible to everyone" means: anyone with your public key can list every profile. Only put columns in this table that you're happy to publish. An email address or a phone number belongs somewhere else.
Notes: owners only, for everything
alter table notes enable row level security;
create policy "Users manage their own notes"
on notes for all
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );
With these two tables, a stranger can see display names and nothing else, and a signed-in user can see and change only their own notes.
How to test your policies
- Read them. In the Supabase dashboard, each table shows whether RLS is enabled and lists its policies. Read each one and ask "who does this allow?"
- Try it as a stranger. With only the public key and no login, query each table. Anything that comes back is public.
- Try it as another user. Sign in as user A, then try to read and change user B's rows.
What Securick tests
We don't read your policies. We test their effect from outside, on a domain you verify, with the public key your app already ships. We count rows and never store your data.
- #59 Supabase tables not readable with the public key Deep
- #60 Supabase storage buckets not listable Deep
- #147 Database functions not callable by anyone Deep
- #96 Data isolation between users Deep
- #97 User files and profiles isolated Deep
- #148 Users can't make themselves admin Deep
- #149 Users can't upgrade their own plan Deep
From the public URL alone, the free scan also checks that the secret key isn't in your code:
- #5 Supabase service key exposed Free
- #111 Supabase personal access token exposed Free
More on what we check in the Supabase security check.
Questions
Is RLS enabled by default on new tables?
Check each table in the dashboard rather than relying on a default: how a table was created can matter, and the dashboard shows clearly whether RLS is on.
Does RLS slow my app down?
Policies run on every query, so complex ones can. Supabase's docs recommend wrapping auth.uid() in a select, as in the examples here, and adding indexes on the columns your policies check, like user_id.
Do I need RLS if I only use the service key on my server?
If no browser ever talks to Supabase directly, the public key matters less. But it's still published in many apps, so turning RLS on everywhere is the safe default.