Supabase security · worked example · 6 minute read
What a read-only RLS drift check actually reports
Abstract security advice is easy to ignore. Below is the real output of thirteen read-only catalogue checks against a deliberately misconfigured local PostgreSQL 17 container. It is a synthetic fixture — no customer project, no hosted database, no production connection — but the report shape is exactly what the free monitor produces.
The setup (and the access it used)
The check ran as a catalogue-only role: CONNECT on the database and USAGE on public, with no SELECT grant on any table. All thirteen checks completed. A direct SELECT * FROM public.orders as that same role returned permission denied for table orders. No service_role, no superuser, no BYPASSRLS, no writes, and no application row data was read.
That distinction matters: a nightly drift check should be able to see security-relevant catalogue state without being able to see customer data. The role template is included in the free package.
The fixture
public.orders— row level security disabled.public.accounts— RLS enabled but notFORCEd; a plain view sits over it.public.events— RLS enabled, permissiveSELECT ... USING (true)policy.public.lookup—SECURITY DEFINER, no pinnedsearch_path, owned bypostgres.ALTER DEFAULT PRIVILEGES ... GRANT SELECT ON TABLES TO anon.
Ten findings, and what each one means
| Severity / check | Object | Why it is flagged |
|---|---|---|
| HIGH · A | public.orders | RLS is disabled — any role with table privileges reads all rows. |
| HIGH · C | public.events :: p_read_all | Permissive SELECT/ALL policy with USING (true). |
| HIGH · G | public.lookup | SECURITY DEFINER without a pinned search_path — object hijack risk. |
| HIGH · H | public.lookup (owner postgres) | Definer function owned by a role that bypasses RLS. |
| HIGH · K | default privileges / anon | Future tables will grant SELECT to anon — invisible in role_table_grants until the table exists. |
| HIGH · L | public.accounts_view | View runs with owner rights (security_invoker not set); the owner bypasses RLS. |
| MEDIUM · B | public.accounts | RLS is on but not FORCEd, so the table owner bypasses policies. |
| MEDIUM · B | public.events | RLS is on but not FORCEd, so the table owner bypasses policies. |
| MEDIUM · J | public.lookup / PUBLIC | An API role can EXECUTE the function directly. |
| MEDIUM · M | public.accounts :: p_org_guard | The policy calls a helper with a row column inside a scalar subquery — a correlated SubPlan, re-evaluated for every row. |
Three of these rows are the ones a per-table policy review typically misses. K lives in pg_default_acl, not in the grants of any existing table. Lis a property of the view, not of the underlying table's policies. M looks like a safely wrapped call, but the argument is a row column, so Postgres plans it as a correlated SubPlan. That is why the check reads the catalogue rather than re-reading policy text.
How to read the report
Each row is a catalogue signal plus a suggested fix, not proof of a leak. A view flagged by L might be intentional; a definer function flagged by G might have a fully qualified body. The value is that the state change is visible the day it happens, while the migration diff is still fresh.
The inverse matters just as much: zero findings does not mean safe. It means no catalogue signal was found. It cannot tell you whether a policy matches what your team intended, whether a key is being used from a browser, or whether a hosted platform rewrites a grant behind your back.
The nightly workflow is also fail-closed: if the credential breaks or the query errors, the run stops. A broken connection must never be recorded as “all findings resolved”. The baseline is a snapshot of finding fingerprints, and new fingerprints alert until a human reviews and refreshes it.
Run it on a scratch database
The complete workflow, the standalone SQL, the TR/EN start guides, the catalogue-only role template, and this exact sample output are in the free package: Supabase RLS Drift Monitor — free. Start on a scratch database, connect the least-privileged role, and use the manual trigger to capture a baseline before you enable the nightly schedule.
If you want a person to read the policies in context, that is a separate, bounded engagement — a 24-hour read-only spot check starts only after payment is secured. The free package stays free with no support commitment.
Continue with how to detect RLS drift with a nightly catalogue diff or the two gaps a per-table policy review will not show you, or which scope answers which question — spot check vs full audit.