Security
Every logged-in user can see all rows: fixing "to authenticated" policies without an owner check
RLS is switched on and the anonymous test looks fine, yet one customer sees another customer's orders. The usual reason: a policy says who may ask ("to authenticated") but not which rows they get, or a broad policy sits next to a correct one and wins. Below: how to find those policies in your own project, how to test as a real user, and the SQL that limits each user to their own rows.
What you are seeing
This one is harder to spot than an open table, because a stranger without an account sees nothing. The data leaks only between people who are signed in. Signs to take seriously:
- A customer writes that they see orders, messages, invoices or files that are not theirs.
- A list in your app shows more entries for a new test account than that account ever created.
- Supabase's Security Advisor reports lint 0024 (
rls_policy_always_true, "RLS Policy Always True"), or the Performance Advisor reports lint 0006 (multiple_permissive_policies), on a table with private data (Database Advisors). - A policy in your project has a name like "Authenticated users can read" and you are not sure what it actually allows.
- Your app has anonymous sign-ins turned on: Supabase gives anonymous users the same
authenticatedrole as real accounts (Anonymous sign-ins), so "signed in" may mean anyone who opened the app.
How to check it yourself
Run these against your own project only. All queries below only read data, and the user test runs inside a transaction that is rolled back. Everything happens in the Supabase dashboard, in SQL Editor.
1. List every policy that applies to signed-in users
select tablename, policyname, permissive, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
and roles && array['authenticated', 'public']::name[]
order by tablename, cmd;auth.uid(): a policy can call auth.uid() and still check no owner. qual is the using condition (which rows a user can see or change), with_check is the condition new or edited rows must meet.Go through each row the query returns. A policy that compares auth.uid() with an owner column, such as (( SELECT auth.uid() AS uid) = user_id), is the pattern you want. For every other row, ask: for this table, should every signed-in user see every row? For a product catalogue or public posts, yes. For orders, messages, profiles with contact details, payments or uploads, no. Typical findings:
qualis justtrue: every row, for everyone the policy names. Lint 0024 flags an always-trueusingonly on update, delete and all policies (and an always-truewith checkon insert and update). Afor select ... using (true)policy is not flagged, because Supabase treats public reads as often intentional (lint 0024 source).qualis(auth.uid() IS NOT NULL)orauth.role() = 'authenticated': this only checks that someone is signed in, whichto authenticatedalready did.auth.uid() IS NOT NULLcontainsauth.uid()but compares it with no owner, so treat it liketrue. Lint 0024 only matches literal conditions liketrueor1=1, so do not count on the advisor to catch these.cmdisALL: one policy covers select, insert, update and delete at once. Read its condition with that in mind.- The condition calls a helper function (for example
is_member(org_id, auth.uid())). Passingauth.uid()in does not prove an owner check; open the function and check what it compares.
2. Look for a broad policy sitting next to a correct one
A table can have a perfect owner policy and still leak. Postgres combines permissive policies (the default kind) with OR: a row is visible if any one of them allows it (PostgreSQL: CREATE POLICY). One leftover using (true) policy cancels every careful policy beside it. List tables with more than one permissive policy for the same operation:
select tablename, cmd, count(*) as policies,
string_agg(policyname, ' | ') as names
from pg_policies
where schemaname = 'public'
and permissive = 'PERMISSIVE'
group by tablename, cmd
having count(*) > 1
order by tablename, cmd;cmd = ALL also applies to select, insert, update and delete, so check those tables as well.3. Test as a real user, inside the database
Supabase's docs describe switching role and identity with set local role and set local request.jwt.claim.sub to test policies (Row Level Security). First pick one of your own test accounts:
select id, email, created_at
from auth.users
order by created_at desc
limit 10;Then run the following as one block, with the test account's id pasted in both places. Replace orders and user_id with your table and its owner column:
begin;
set local role authenticated;
set local request.jwt.claim.sub = 'TEST-USER-UUID';
select count(*) as rows_visible,
count(*) filter (where user_id is distinct from 'TEST-USER-UUID'::uuid) as rows_of_other_users
from public.orders;
rollback;rows_of_other_users should be 0. Anything above 0 means this account can read other people's rows through the API exactly as the query shows. rollback ends the test and resets the role. SQL Editor may show only the result of the last statement: if you see "Success. No rows returned" instead of the two counts, that is not a pass. Select the lines from begin; through the select, run only that selection, read rows_of_other_users, then run rollback;.If you prefer to test from the outside, the signed-in curl test in our guide to open Supabase tables sends the same kind of request your app sends, with a test user's access token.
Why it happens
A Supabase policy answers two separate questions. The to clause says which role the policy applies to: anon for visitors who are not signed in, authenticated for signed-in users. The using condition says which rows that role gets. Supabase recommends always naming the role (Row Level Security), but naming the role does not narrow the rows. to authenticated using (true) reads as "logged-in users only" and works as "every logged-in user gets every row".
- Generated code tends to fix the error in front of it. When a screen shows nothing because RLS blocks it, the fastest change that makes the screen work is a policy that lets every signed-in user through.
- Permissive policies add up. Postgres grants access if any permissive policy passes, so adding a correct owner policy does nothing while an old broad policy is still there (PostgreSQL: CREATE POLICY).
- "Signed in" can be cheaper than it sounds. If sign-up is open, anyone can create an account in seconds. With anonymous sign-ins enabled, every visitor who opens the app gets the
authenticatedrole without an account at all (Anonymous sign-ins). - The table has no owner column. If
ordershas nouser_id, there is nothing to compareauth.uid()with, so the only policies that work are broad ones. - Data reaches users around the table's policies: views bypass RLS by default unless created with
security_invoker(Postgres 15+), and asecurity definerfunction runs with the rights of the role that owns it, usually the one that created it, oftenpostgres(Row Level Security, PostgreSQL: CREATE FUNCTION).
How to fix it
1. Make sure each private row has an owner
Skip this if the table already has a column holding the owner's user id. If it does not, add one. The default fills it with the id of the user who creates the row:
alter table public.orders
add column user_id uuid references auth.users (id) default auth.uid();null) and, after step 2, nobody can see them through the API. Fill them in before you switch policies, or decide they belong to no one.2. Replace the broad policies with owner policies
Drop every broad policy you found in checks 1 and 2, then create one policy per operation. This is the pattern from Supabase's docs, with auth.uid() wrapped in select so Postgres evaluates it once per statement instead of once per row (Row Level Security):
begin;
drop policy if exists "Authenticated users can read orders" on public.orders;
create policy "Owners can read their orders"
on public.orders for select
to authenticated
using ( (select auth.uid()) = user_id );
create policy "Owners can create their orders"
on public.orders for insert
to authenticated
with check ( (select auth.uid()) = user_id );
create policy "Owners can update their orders"
on public.orders for update
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );
create policy "Owners can delete their orders"
on public.orders for delete
to authenticated
using ( (select auth.uid()) = user_id );
commit;drop policy. Running it all in one transaction means users never see a moment with no policies, or with both old and new ones.- Leave out operations users should never do. If customers must not delete orders, do not create the delete policy.
- Keep the select policy even if you only care about updates: Supabase notes that an update needs a matching select policy to work as expected (Row Level Security).
- The
with checkon update stops a user from moving a row to someone else by changinguser_id. - If part of a table really is public (for example published posts), write that as its own select policy with a narrow condition such as
using ( published = true ), notusing (true).
3. Add an index on the owner column
Every query now filters by user_id. Supabase recommends an index on every column your policies filter on (Row Level Security):
create index if not exists orders_user_id_idx
on public.orders using btree (user_id);4. Optional: a safety net that later changes cannot undo
For tables where every row is strictly private, a restrictive policy adds a check that must pass on top of any permissive one - Postgres combines restrictive policies with AND (PostgreSQL: CREATE POLICY). If an AI tool later adds a broad using (true) policy to fix a bug, this one still limits users to their own rows:
create policy "Only the owner, whatever other policies say"
on public.orders
as restrictive
for all
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );5. Check what else can reach the same data
- Views that select from the table: recreate them with
with (security_invoker = on)so they apply the caller's policies, or move them out of the exposed schema (Row Level Security). - Database functions your app calls with
rpc(...)that aresecurity definer: they run with the owner's rights, so they must filter byauth.uid()themselves. - Anonymous sign-ins: if they are on and some data should be for permanent accounts only, Supabase shows a restrictive policy that checks the
is_anonymousclaim in the user's token (Anonymous sign-ins).
Verify
Run the three checks again. Check 1 should list only tables that are meant to be readable by every signed-in user, and the user test should show rows_of_other_users = 0 for two different test accounts. Then use the app as a normal user: a screen that now shows an empty list either reads data the user does not own (which is the point) or needs a policy you have not written yet - for example data shared within a team.
When to get help
The owner pattern covers rows that belong to exactly one user. Get a second pair of eyes when:
- Rows are shared - teams, organisations, workspaces, invitations, a chat between two users. Those policies need a membership check, and that is where a wrong join quietly exposes another company's data.
- You have roles such as admin, staff and customer, and the admin checks currently live only in the app's screens.
- Existing rows have no owner and you need to work out who owns what before switching policies.
- A customer has already seen someone else's data on a live app. If you are subject to the GDPR, a personal data breach generally has to be reported to the supervisory authority within 72 hours of becoming aware of it, unless it is unlikely to result in a risk to people (GDPR, Article 33). Get legal advice on that part.
- You changed the policies and parts of the app broke in ways you cannot trace.
Sources
Primary documentation this guide was checked against. Platforms change - if something here no longer matches, the source wins.
- Row Level SecuritySupabase docs
- Database Advisors (lint reference)Supabase docs
- Anonymous sign-insSupabase docs
- Lint 0024: rls_policy_always_true (source)Supabase splinter on GitHub
- Lint 0006: multiple_permissive_policies (source)Supabase splinter on GitHub
- CREATE POLICYPostgreSQL documentation
- CREATE FUNCTIONPostgreSQL documentation
- General Data Protection Regulation, Article 33EUR-Lex
Frequently asked questions
- My policy says "to authenticated". Isn't that already secure?
- Only against visitors who are not signed in. The
to authenticatedpart decides who the policy applies to; theusingcondition decides which rows they get. Withusing (true)or a condition that only checks that someone is signed in, every logged-in user gets every row. Add an owner check such as(select auth.uid()) = user_id. - I added an owner policy, but users still see each other's data. Why?
- Most likely an older broad policy is still on the table. Postgres combines permissive policies with OR, so if any one of them lets a row through, the user sees it. List all policies on the table in
pg_policiesand drop the broad ones. - Does the Supabase Security Advisor catch this?
- Partly. Lint 0024 flags always-true conditions on update, delete and all policies, but not a select policy with
using (true), which is the usual read leak. Lint 0006 (a performance lint, shown in the Performance Advisor) flags several permissive policies for the same role and action. A condition that only checks that a user is signed in is not literallytrue, so it passes the advisor too. Run the SQL checks yourself. - Are anonymous users affected by "to authenticated" policies?
- Yes. Supabase gives anonymous users the
authenticatedrole, the same as permanent accounts. If anonymous sign-ins are on, a broadto authenticatedpolicy is open to anyone who opens your app. Use theis_anonymousclaim in a policy where only permanent users should have access. - Will the owner policies slow down my app?
- Not if you follow Supabase's recommendations: wrap
auth.uid()inselectso it is evaluated once per statement, and add an index on the owner column.
Related guides
Fixed-price audit
Want someone to check the whole app, not just this?
A review of data security, production readiness and App Store readiness for apps built with AI tools. 900 USD, a ranked list of fixes within 5 business days.