Supabase · RLS operations · 7 minute read
Detect Supabase RLS drift: a read-only nightly check
Row level security rarely breaks in one dramatic commit. It drifts: a migration forgets FORCE ROW LEVEL SECURITY, a console click leaves a SELECT policy as USING (true), a helper function gets rewritten without a pinned search_path. Nothing looks broken on the day it changes.
A one-time audit answers the question on the day you run it. Drift is a different problem: it asks whether the answer is still true tonight. That needs a scheduled, read-only comparison against a known baseline.
Why a one-time audit goes stale
Policies live in pg_policies, grants inpg_role_privilege-backed catalogs, and function behaviour in pg_proc. All of them are editable by ordinary migrations. A single CREATE POLICY ... FOR ALL USING (true)in a hotfix can reopen a table that was closed last week, and the application tests will still pass — because tests usually run as the table owner, who bypasses RLS unless FORCE is set.
The practical fix is not another checklist. It is a small nightly job that reads the same catalogs, compares tonight to the first run, and emails only when the finding set changes.
The thirteen checks worth watching
This set is deliberately catalog-only: it never reads application table data and never writes to the database. Each row reports an object, a severity and a concrete fix.
- RLS disabled on a table in the
publicschema. - FORCE missing — the owner still bypasses policies.
- Permissive SELECT/ALL policy with
USING (true). FOR ALLpolicy without an effectiveWITH CHECK.- Write policy without
WITH CHECK— the new row is unchecked. - Policy granted to
PUBLICinstead of a named role. SECURITY DEFINERwithout pinnedsearch_path.SECURITY DEFINERowned by a BYPASSRLS role or superuser.- Write grants to
anon/authenticatedthat outlive the migration. - Direct
EXECUTEgrants on functions inpublic. ALTER DEFAULT PRIVILEGESgranting API roles on tables created in the future — visible only inpg_default_acl.- Views over RLS tables without
security_invoker— the view reads as its owner; FORCE RLS does not close the BYPASSRLS case. - A wrapped helper that still depends on a row column —
(select helper(col))compiles to a correlated SubPlan and is re-evaluated for every row, defeating the point of caching the call.
Baseline first, then diff
The first run must be silent. It captures the current finding set as a baseline. Every later run classifies each known finding as still present, and anything new as NEW or RESOLVED. That is what turns a noisy list into a signal you can trust: a quiet night produces no email at all.
The monitor must also fail closed. If the database credential breaks, the job must stop — never silently write an empty baseline and report “all findings resolved”. A broken reader is not a clean database.
Run it without n8n, too
The same thirteen checks are useful as plain SQL. A standalone.sql file can be run with psql before a migration, after a migration, or in CI against a scratch database. The n8n workflow adds scheduling and the baseline diff; the SQL file needs no account and no automation platform.
Try the free monitor
The workflow, the standalone SQL and a three-step setup note are bundled as a free download. Use a read-only role — noservice_role, no superuser — and test on a scratch database first. For a one-off answer to “what can anon read today?”, the browser-based anon-key readability check probes each table your Data API exposes without installing anything.
Get the free RLS Drift Monitor (n8n + SQL) →
Honest limits
This is a catalog check, not proof of a leak. It cannot tell whether a policy matches what your team intended, whether a service-role key is being used from a client, or whether a hosted platform rewrites a grant behind your back. “Zero findings” does not mean the database is safe. For that you need a person reading the policies in context — a human review starts only after payment is secured.
Read the next guide: the first 15 minutes of a Supabase security audit, or see what a free anon-key check cannot prove, or which paid scope answers which question, or USING vs WITH CHECK: the clause a policy review skips.