Skip to content
← All guides

Security

Every logged-in user can see all rows: fixing "to authenticated" policies without an owner check

By Jan Lipmann, appienceChecked against sources on 8 min read

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.

SupabasePostgreSQL

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 authenticated role 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;
A list to read, not a verdict. It deliberately does not filter out policies that mention 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:

  • qual is just true: every row, for everyone the policy names. Lint 0024 flags an always-true using only on update, delete and all policies (and an always-true with check on insert and update). A for select ... using (true) policy is not flagged, because Supabase treats public reads as often intentional (lint 0024 source).
  • qual is (auth.uid() IS NOT NULL) or auth.role() = 'authenticated': this only checks that someone is signed in, which to authenticated already did. auth.uid() IS NOT NULL contains auth.uid() but compares it with no owner, so treat it like true. Lint 0024 only matches literal conditions like true or 1=1, so do not count on the advisor to catch these.
  • cmd is ALL: 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())). Passing auth.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;
A policy with 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 authenticated role without an account at all (Anonymous sign-ins).
  • The table has no owner column. If orders has no user_id, there is nothing to compare auth.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 a security definer function runs with the rights of the role that owns it, usually the one that created it, often postgres (Row Level Security, PostgreSQL: CREATE FUNCTION).

How to fix it

Warning: Changing policies changes what every user sees the moment the SQL runs. Test on a Supabase branch or a copy of the project first, and keep the old policy definitions from step 1 so you can put them back.

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();
Existing rows get no owner (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;
Use the exact policy names from check 1 in 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 check on update stops a user from moving a row to someone else by changing user_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 ), not using (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 );
Do not add this to tables that are meant to be shared between users (team data, admin views): it will hide those rows too. A restrictive policy grants nothing on its own; the permissive policies from step 2 are still needed.

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 are security definer: they run with the owner's rights, so they must filter by auth.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_anonymous claim 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.

Frequently asked questions

My policy says "to authenticated". Isn't that already secure?
Only against visitors who are not signed in. The to authenticated part decides who the policy applies to; the using condition decides which rows they get. With using (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_policies and 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 literally true, 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 authenticated role, the same as permanent accounts. If anonymous sign-ins are on, a broad to authenticated policy is open to anyone who opens your app. Use the is_anonymous claim 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() in select so 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.