2026-11-15
Every logged-in user reads every row: the always-true authenticated RLS policy
This is the leak I find most often in AI-generated Supabase apps, and it passes the three checks most teams run. RLS is enabled on the table. Policies exist. The free anon-key checker reports the table as not readable— because it isn't, for anonymous callers. Then one signed-in user opens the app and sees every other user's rows.
The cause is almost always a policy that reads like a permissive default and evaluates like an open door: for select using (true) applied to the authenticated role.
Why the scanners and the checker both miss it
Both questions a security advisor and a free checker ask have reassuring answers: "can anonread the table?" — no, so RLS looks healthy. "Are there policies?" — yes, so the table looks covered. The dangerous predicate is attached to a role the anon key cannot impersonate. Supabase's own Security Advisor lint 0024 ("RLS Policy Always True") flags always-true rules on insert, update and delete, and deliberately skips for select using (true) — the read is where the leak lives, and it is exactly the case the linter does not flag.
Nothing errors. No 42501, no empty result. Every query returns the right shape — it just returns everyone's rows.
Find the candidates by reading the predicates, not the boolean
A policy can be always-true without literally saying true: a constant, a comparison to a shared setting rather than a caller identity, or a qual that never references the actor. The catalog query reads the stored expressions, so it catches all of them:
select n.nspname as schema, c.relname as table, p.polname,
pg_get_expr(p.polqual, p.polrelid) as using_expr,
pg_get_expr(p.polwithcheck, p.polrelid) as check_expr,
(select string_agg(r.rolname, ', ')
from unnest(p.polroles) role
join pg_roles r on r.oid = role) as roles
from pg_policy p
join pg_class c on c.oid = p.polrelid
join pg_namespace n on n.oid = c.relnamespace
where n.nspname not in ('pg_catalog', 'information_schema', 'auth', 'storage')
and p.polcmd in ('r', '*')
and (pg_get_expr(p.polqual, p.polrelid) is null
or pg_get_expr(p.polqual, p.polrelid) = 'true')
and exists (select 1 from pg_roles r
where r.oid = any (p.polroles)
and r.rolname in ('authenticated', 'public'));Any row returned is a candidate. Tables with a user_id, org_id or tenantcolumn get checked first — those are the columns the policy was supposed to filter on. The short form (`qual = 'true'` in pg_policies) misses predicates that are true-in-effect but not true-in-text, which is why the expression form matters.
Two lines in that query fail in ways worth knowing, because both failure modes are quiet or misleading rather than obvious. polroles is oid[], so comparing a role name directly against it dies with invalid input syntax for type oid — the join through pg_roles compares names, not OIDs. And polcmd on pg_policy is a one-character internal code (r = select, a = insert, w = update, d = delete, * = all), not the text names — in ('SELECT', 'ALL')doesn't error, it silently returns zero rows, which looks exactly like "no findings". The text names only exist on the pg_policies view.
Prove it as the role — the two-user check
Catalog output gives suspects; only a runtime read gives the verdict. Create two real users, sign in as each, and run the same read through the Data API:
# as user A
curl "$SUPABASE_URL/rest/v1/orders?select=*" -H "apikey: $ANON_KEY" -H "Authorization: Bearer $USER_A_JWT" | jq 'length'
# as user B — same request, different token
curl "$SUPABASE_URL/rest/v1/orders?select=*" -H "apikey: $ANON_KEY" -H "Authorization: Bearer $USER_B_JWT" | jq 'length'If B's response contains A's rows — or a row count that only the owner should see — the policy that applies to authenticatedis the thing to open. It takes minutes and needs no new infrastructure; it is the same check with one role over from the popular anon-key probe, and it is the check that actually answers "can a logged-in user read another user's data".
One caveat that makes the check meaningful: run it against a copy with real grants. Migration-mode local runs start from your migrations, while production grants drift — the leak frequently exists only on the live project.
The write side of the same bug
A policy that scopes reads does nothing for a write without a matching with check. The classic shape is a SELECT policy pinned to auth.uid() = user_idnext to an INSERT policy with no check at all — reads look correct while any user can insert or update rows with someone else's user_id. The runtime probe: as user A, try to write a row owned by user B. Success is the finding, and the read check passes the whole time. On for all policies the same split exists inside one policy — using and with check are separate halves.
What breaks when you paste the fix
The tempting fix is using (auth.uid() = user_id)on every table. It also hides rows your own code legitimately reads: admin screens, exports, aggregate views, and joins your cached queries rely on. Any SECURITY DEFINER function that reads through the table keeps behaving with its owner's privileges, so its behavior changes silently. Inventory the readers before tightening the predicate:
-- views over the table
select n.nspname, v.relname, pg_get_viewdef(v.oid)
from pg_class v
join pg_depend d on d.refobjid = v.oid and d.refclassid = 'pg_class'::regclass
join pg_class t on t.oid = d.objid
where t.relname = 'orders' and d.classid = 'pg_rewrite'::regclass;
-- SECURITY DEFINER functions whose body reads the table
select n.nspname, p.proname, pg_get_functiondef(p.oid)
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where p.prosecdef
and pg_get_functiondef(p.oid) ilike '%orders%';And if tightening leaves a table that must stay broadly readable — shared or org-scoped lookups — the answer is a policy that filters on the caller's org_id claim, not true, not uid.
The kit ships the always-true sweep and the two-user harness
Find this leak in your own schema this afternoon
Supabase RLS Audit Kit · $29 one-time
Seven commented SQL audits and 60 checks expose every table's RLS status, the exact predicate each policy applies per role (including always-true reads for authenticated), definer functions and views that bypass it, grants, and a two-user read/write harness pre-written for the runtime verdict.
Prefer the verdict instead of running the toolkit yourself?
Fixed-price reviews with the evidence, the SQL and the written verdict. Fixes are quoted separately. Instant checkout, no account needed.
Related reading: what a free anon-key check can — and cannot — prove, why your RLS tests pass and your data still leaks, 7 ways your Supabase app still leaks data with RLS enabled and the write leak: using without with check. For a full launch pass, a fixed-price Supabase RLS audit from $95 returns prioritized findings with reproducible evidence.