Cenk Kurtoğlu©26

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.

  1. RLS disabled on a table in the public schema.
  2. FORCE missing — the owner still bypasses policies.
  3. Permissive SELECT/ALL policy with USING (true).
  4. FOR ALL policy without an effective WITH CHECK.
  5. Write policy without WITH CHECK — the new row is unchecked.
  6. Policy granted to PUBLIC instead of a named role.
  7. SECURITY DEFINER without pinned search_path.
  8. SECURITY DEFINER owned by a BYPASSRLS role or superuser.
  9. Write grants to anon / authenticated that outlive the migration.
  10. Direct EXECUTE grants on functions in public.
  11. ALTER DEFAULT PRIVILEGES granting API roles on tables created in the future — visible only in pg_default_acl.
  12. Views over RLS tables without security_invoker — the view reads as its owner; FORCE RLS does not close the BYPASSRLS case.
  13. 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.

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↗