Cenk Kurtoğlu©26

Your Supabase RLS test passes. Your tenant data still leaks.

A green test suite is not a tenant isolation proof. It is a proof about whichever role the test ran as — and in most Supabase projects the test runs as the one role that bypasses row level security entirely.

The same query, three different answers

I built a 12,000-row table with three tenants on PostgreSQL 17, oneFOR SELECT policy on tenant_id, and ran the same SELECT count(*) as six different roles:

ModeActorRows seenWhat it proves
Apostgres (superuser)12,000Everything. The dashboard SQL editor runs here by default.
BTable owner, FORCE RLS off12,000Owners are exempt from their own policies unless FORCE RLS is on.
CNon-owner + tenant-1 claim4,000The only mode that measures what production does.
DNon-owner, no claims0An anon request with no JWT sees nothing. Correct — but often mistaken for a broken policy.
EBYPASSRLS (service_role shape)12,000The role your seed scripts and admin tools use. It never sees a policy.
FOwner + FORCE RLS + claim4,000FORCE RLS closes the owner hole — one ALTER, easy to forget.

One policy. Six actors. The answer swings between 12,000, 4,000 and 0 depending purely on the role — not on the policy text, not on the data. If your CI test asserts “the count equals the full table” as the owner, it passes. It has measured nothing about RLS. Superusers and roles with BYPASSRLS always skip row security, and table owners skip it too unless FORCE ROW LEVEL SECURITY is set on the table.

Why this shape shows up in real projects

The typical integration test opens a pooled postgresconnection, inserts two users, and checks that user A cannot read user B. Every step runs as the owner. The assertion passes for the wrong reason: no rows were ever filtered, because no policy was ever evaluated. Ship it, hit the endpoint with a real anon token, and the question “what can this role actually read?” has never been answered by any test in the repo.

The second shape is the inverse. A developer writes a test with a fresh anon connection and no request.jwt.claimsset, gets 0 rows, and concludes the policy is broken — then “fixes” a correct policy into a permissive one. Mode D is not a bug; it is an unauthenticated session behaving exactly as configured.

The matrix that actually proves something

A passing RLS suite needs the negative cases, run as the role that production traffic uses:

The recipe, minimally

Standard Postgres session settings are enough — no Supabase client SDK needed. The pattern below is the one I run; the set local role line is the whole point, because it is the step everybody skips.

-- 1. positive: non-owner + tenant-1 claim
begin;
  set local role appreader;
  set local request.jwt.claims =
    '{"sub":"11111111-1111-1111-1111-111111111111","tenant_id":"tenant-1"}';
  select count(*) from app.documents;   -- expect 4000, not 12000
rollback;

-- 2. negative: different tenant claim, same role
begin;
  set local role appreader;
  set local request.jwt.claims =
    '{"sub":"22222222-2222-2222-2222-222222222222","tenant_id":"tenant-2"}';
  select count(*) from app.documents
   where tenant_id = 'tenant-1';        -- expect 0
rollback;

-- 3. unauthenticated: no claims at all
begin;
  set local role appreader;
  select count(*) from app.documents;  -- expect 0
rollback;

-- 4. document the owner escape hatch
begin;
  set local role appuser;              -- table owner, FORCE RLS off
  select count(*) from app.documents;  -- expect 12000 = accepted gap
rollback;

In Supabase, auth.jwt() reads the same request.jwt.claims GUC the PostgREST edge sets from the Authorization header, so a local transaction with the claims set is the closest local stand-in for an authenticated request. If your policy calls auth.uid(), set sub; if it calls a custom claim, set that. The fixture I measured with used a stand-in auth.jwt() reading request.jwt.claims with coalesce to {} — the same null-tolerance the hosted function has, and the reason mode D returns 0 instead of erroring.

What most teams never test: the catalog itself

The matrix above tests one table. The failures that reach production usually live outside the table you were looking at: a table created last month with RLS never enabled, a policy that is PERMISSIVE and uses USING (true), a view without security_invoker that runs as its owner and re-exposes the rows, a pg_default_acl entry that grants anon write on tables that do not exist yet. None of those show up in a per-table test, because there is no per-table test for them — there is only the pg_policies/pg_class view over all of them.

The read-only drift monitor I ship for free diffs exactly that view every night: RLS disabled, USING (true) on select/insert paths, policies granted to PUBLIC, SECURITY DEFINER functions without a pinned search_path, missing security_invoker on views, and write grants to anon/authenticated in default privileges. It runs as a catalogue-only role that can read the system views and read nothing else — no service_role key, no application rows.

How to check yours in about five minutes

  1. In the dashboard SQL editor you are postgres — every count you run there is a mode-A result. It proves nothing about policies. Stop counting there.
  2. For one table, run the four-mode recipe above. If mode C does not return exactly the tenant rows, you have found the bug.
  3. Run the catalogue check over every table once. If any table comes back with RLS disabled, that is a bigger leak than the one you were testing for.
  4. Then keep it honest: any auth change is a migration, so re-run the catalogue diff after each one, not once before launch.

Measured on PostgreSQL 17.12 locally: one SELECT count(*) per mode, 12,000 rows across three tenants, one policy. I did not run this against a hosted project; hosted PostgREST sets the claims GUC from the Authorization header, and the local stand-in reproduces the shape, not the wire path. The catalogue view output depends on your revision and extensions — a clean run is a signal to look, never a certificate.

Related: the (select auth.uid()) fix, measured — and the owner-only trap that hides the cost · USING vs WITH CHECK, the half of policy review that gets skipped · pg_default_acl and view-owner RLS, the two checks your review does not cover · the full pre-launch RLS testing workflow.

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.

Want the free first step? The RLS Drift Monitor runs 13 read-only catalog checks on a schedule. It never reads application rows; zero findings is not proof of safety.

Prefer escrow? $49 drift monitor setup or $95 exposed-key triage on Upwork. Work starts only after the fixed-price milestone is funded.

Work starts only after payment is secured. Catalogue checks are read-only; no write credentials, no service_role key, no application rows.

Free entry

If you would rather run these checks yourself

Honest limit: a catalog check is not proof of a leak, and an empty log is not proof the key was never used. Zero findings does not mean safe. If you want a human: $29 self-run kit · $95 spot check (five tables, one working day) · $195 full audit — work starts only after payment is secured.

Template bundle

Review all 20 frontend starters in one bundle

20 editable frontend starters with live demos are $79 — one payment, no subscription.

View the Bundle — $79↗