Two users, one table
Two users. One table. User A can read User B's order. RLS is on. The policy exists. Your tests pass.
This is common. A static audit of 60 open-source Supabase apps found at least one high or critical RLS pattern in 63% of them. One in four had a critical finding. The median RLS Score was 38/100.
The five mistakes below account for most of it. Each one is a real finding from rls-doctor, with the severity the tool assigns and the SQL that fixes it.
The short version
# mistake severity finding id
1 RLS off on a granted table high rls-disabled-exposed
2 to public + using (true) high/crit public-unconditional-read/write
3 UPDATE without WITH CHECK medium write-policy-missing-check
4 TRUNCATE reachable high reachable-truncate
5 FORCE RLS off info force-rls-disabledThe severity matters as much as the mistake. If your CI runs `--fail-on high`, mistake 3 will not fail the build. Keep that in mind when you wire up the gate.
1. RLS is off on a granted table
A grant says a role may read a table. RLS is the row filter. If RLS is off, the grant is the only boundary, and it is an all-rows boundary.
grant select on rls_doctor_demo.orders to authenticated;
-- RLS was never enabled. No policy is even consulted.
-- authenticated can select every row in the table.The catalog finding is High: `rls-disabled-exposed`. A probe makes it concrete:
rls_doctor_demo.orders
authenticated rows sampled 2 row(s), 2 distinct owner_id
- [high] probe-cross-owner-read rls_doctor_demo.orders:
Role authenticated reads rows across 2 distinct owner_id valuesalter table rls_doctor_demo.orders enable row level security;
create policy "users read own orders"
on rls_doctor_demo.orders
for select
to authenticated
using (owner_id = (select auth.uid()));Do this for every table an application role can reach, including join tables and audit logs. One unguarded table is a tenant leak.
2. TO public with an unconditional USING (true)
This is the most common leak in Supabase projects. A policy exists, RLS is on, and the policy allows everyone to read everything.
create policy "anyone can read profiles"
on rls_doctor_demo.profiles
for select
to public
using (true);Two problems stack. `to public` reaches every role that can use the schema, including `anon`. `using (true)` places no row-level condition on the result. For reads, the finding is High. For writes, it is Critical.
alter policy "anyone can read profiles"
on rls_doctor_demo.profiles
to authenticated
using ((select auth.uid()) = id);If a row is genuinely public, scope it with a `published` flag or a dedicated public view. Do not put an unconditional predicate on a multi-tenant table.
3. UPDATE without WITH CHECK
`USING` decides which rows the command can see. `WITH CHECK` decides which rows it can write. Without `WITH CHECK`, an update can move a row into another tenant.
create policy "anon can update profiles"
on rls_doctor_demo.profiles
for update
to public
using (true); -- can update any row
-- no WITH CHECK: can set owner_id to anyoneThe finding is Medium: `write-policy-missing-check`. This is the one people miss in CI. `--fail-on high` will not fail on it. Use `--fail-on medium` if you want the build to catch it.
alter policy "anon can update profiles"
on rls_doctor_demo.profiles
to authenticated
using ((select auth.uid()) = id)
with check ((select auth.uid()) = id);Audit rule: every INSERT and UPDATE policy needs an explicit `WITH CHECK`. If the write path cannot be described as a predicate over the new row, the policy is incomplete.
4. TRUNCATE reachable by application roles
RLS does not protect `TRUNCATE`. Not partially. At all. If an application role can truncate a table, it can empty another tenant's rows regardless of every policy on that table.
grant select, update, truncate
on rls_doctor_demo.profiles to authenticated;
-- Every policy on profiles is irrelevant for TRUNCATE.
truncate rls_doctor_demo.profiles; -- wipes every tenantThe catalog finding is High: `reachable-truncate`. Application roles should never hold it. Reserve it for a maintenance role that is not reachable from the app connection string.
revoke truncate on rls_doctor_demo.profiles from authenticated;
grant truncate on rls_doctor_demo.profiles to maintenance_role;
-- Tighten current grants and the defaults that create future ones.
revoke all on all tables in schema rls_doctor_demo from authenticated;
alter default privileges in schema rls_doctor_demo
revoke all on tables from authenticated;5. FORCE RLS is off, so the owner bypasses every policy
By default, the table owner is exempt from RLS. If your application connects as the owner, the role that ran the migrations, every policy you wrote is decorative.
This is silent. Tests pass because the test connection is the owner. Production leaks because the production connection is also the owner.
alter table rls_doctor_demo.profiles force row level security;The finding is Info: `force-rls-disabled`. That is not a typo. It matters, but it is not a leak on its own. If an app role can reach a SUPERUSER or BYPASSRLS role, that is a separate High finding: `rls-bypass-role`.
Pair FORCE RLS with a separate application role. The app connects as `authenticated`, not as the migration owner. FORCE RLS is then the second lock, not the first.
Where this fits
Postgres documents RLS semantics; Supabase's guides show policy patterns. Most reviews stop at one of three layers: the SQL text, the catalog, or an application test.
layer question it answers
SQL lint does the migration text look risky?
catalog audit (this tool) which roles can reach which rows, given grants and policies?
application test does this endpoint leak for this fixture?
probe (this tool) can this role or subject read another tenant's rows now?The catalog audit and the probe are complementary. The catalog sees every table and role; the probe sees actual rows, but only for the fixtures you seed. Neither replaces an application test.
Prove it, do not just read the policies
The fastest way to see this is the demo. It starts a disposable Postgres, applies an unsafe schema, seeds two users, runs `check` and `probe`, and proves the leak. No credentials, no cleanup.
npx rls-doctor demoSummary: 3 tables, 3 policies, highest risk CRITICAL
Findings: critical 1, high 4, medium 1, low 2, info 1
RLS Score: 29/100
- [high] probe-cross-owner-read rls_doctor_demo.orders:
Role authenticated reads rows across 2 distinct owner_id valuesFor a real database, `probe` can impersonate actual Supabase users. Pass `--subjects` to prove one user can read another user's rows:
npx rls-doctor probe --schema public --app-roles authenticated --subjects 00000000-0000-0000-0000-000000000001 00000000-0000-0000-0000-000000000002 --owner-columns owner_idWithout `--subjects`, the probe proves that a role sees multiple owners. With `--subjects`, it proves that a specific user sees another user's rows. The second is the stronger claim.
authenticated@000...001 rows 1 foreign row(s), 1 own row(s)
authenticated@000...002 rows 1 foreign row(s), 1 own row(s)
- [high] probe-cross-subject-read rls_doctor_demo.orders:
Role authenticated reads rows belonging to other usersPut it in CI
The whole point of these mistakes is that they survive code review. A repeatable check is the durable fix. You can run the catalog audit without a database at all:
# No database, no credentials: audit the migration itself.
npx rls-doctor@0.5.8 check --schema-file supabase/migrations/0001_init.sql --fail-on medium
# Live database: adopt without failing on day one.
npx rls-doctor check --schema public --baseline rls-baseline.json --update-baseline
npx rls-doctor check --schema public --baseline rls-baseline.json --fail-on medium
# Before release: prove access with seeded users.
npx rls-doctor probe --schema public --app-roles authenticated --subjects <uuid-a> <uuid-b> --owner-columns owner_idWhy `medium`? Missing `WITH CHECK` is Medium. `FORCE RLS` off is Info; if you want that to fail too, use `--fail-on info` or a separate check. The score penalties are critical 25, high 10, medium 4, low 1.
The GitHub Action uploads SARIF to the Security tab. JSON reports include stable fingerprints and a baseline diff, so a team can turn the check on without a hundred failures on day one.
Reproduce this
The demo and the 60-repo study are from RLS Doctor commit `c942d25` (v0.5.8). Clone it and run the same demo:
git clone https://github.com/subhajitlucky/rls-doctor
cd rls-doctor
git checkout c942d25
npm ci
npm run build
node dist/cli.js demoSummary: 3 tables, 3 policies, highest risk CRITICAL
Findings: critical 1, high 4, medium 1, low 2, info 1
RLS Score: 29/100
- [high] probe-cross-owner-read rls_doctor_demo.orders:
Role authenticated reads rows across 2 distinct owner_id valuesFor the study, run `node scripts/study-supabase-rls.mjs --limit 60 --pages 2 --out results.json` with a GitHub token. The script writes aggregate records, not repository names.
What a catalog audit cannot prove
The catalog is one layer. It is not the whole security model. These are the gaps that matter:
question answer
Did the study measure false positives? no; static findings, not ground truth
Was the sample random? no; first 60 unique GitHub results
Can a catalog audit prove app authz? no; it sees catalog state only
Can probe see custom session GUCs? not unless reproduced; Medium finding
Does service_role bypass RLS? yes, by design; keep it server-side- Application-level authorization. A policy can be correct and the API can still return another tenant's rows through a join the policy never touches.
- Views and SECURITY DEFINER functions. A view can run with the owner's permissions and bypass the base table's policies.
- Hosted Supabase settings. The Data API configuration is outside the catalog.
- Custom session settings. Probe sets `request.jwt.claims`; a policy that reads another GUC may return zero rows and hide a leak. The tool reports `probe-session-dependent-policy` as Medium.
- Empty fixtures. A probe that sees zero rows on empty tables proves nothing. Seed two owners before you trust a green result.
- Offline parser coverage. `--schema-file` turns unsupported statements into limitations, not findings. Read them.
- service_role bypasses RLS by design. The catalog audit cannot protect a leaked service key; keep it server-side.
Use both layers. Catalog analysis answers 'are the policies shaped safely?' Probe answers 'can this role read another tenant's rows right now?' Neither replaces the other.
Try it
The point is not to trust the policy text. Prove who can read what.
RLS Doctor on GitHubSource, the 60-repo study, the proof mode, and the CI examples.npm packageInstall-free usage: npx rls-doctor demo.The 60-repo studyMethod, headline numbers, and the coverage limits, including what the sample cannot prove.