TL;DR
Test Supabase row level security the way a member meets it: sign in as each role, run the real action with one permission off and then on, and check that the result changes. On a production app with five editable roles, this found that 30 of the 87 permission boxes an admin could save changed nothing in the database. A policy-by-policy test cannot see that, because it tests the policy you wrote, not the box on the screen.
I’m Denys, a Forward Deployed Engineer. Earlier this year I built a project and time tracker for an audit firm on Supabase, where every access rule lives in the database. Below is the method I use to prove those rules, what it found, and what it costs to run. If you are new to RLS, the first two sections cover what it is and how to turn it on.
What is RLS in Supabase?
Row level security (RLS) is a Postgres feature that attaches rules, called policies, to a table. Each policy decides which rows a role may read or change. In Supabase it matters more than in most stacks, because the browser talks to the database directly through the Data API with the publishable (anon) key, and anyone can copy that key from your page. RLS is what stands between that key and your rows.
What a table hands out depends on its state:
| Table state | What a request with the publishable key gets |
|---|---|
| RLS off, table in an exposed schema | Every row, and writes too wherever the role has a grant |
| RLS on, no policies | Nothing, until a policy allows it |
| RLS on, with policies | Only the rows the policies allow, for the operations grants allow |
Two things sit outside this table. The secret key (sb_secret_, or the legacy service_role key) bypasses RLS, so it never goes in the browser. And grants are a separate layer that decides whether a role can touch the table at all; my Lovable app security checklist covers both. Source: Supabase RLS guide, October 2026.
How do you enable RLS in Supabase?
One statement per table, then one policy per operation. Put both in a migration, so every environment gets the same rules:
alter table public.orders enable row level security;
create policy "Members read their own orders"
on public.orders for select
to authenticated
using ((select auth.uid()) = user_id);
To list the tables in public that still have RLS off:
select c.relname
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind in ('r', 'p') and not c.relrowsecurity;
New tables do not get RLS by themselves. Supabase can add an event trigger that enables it on every table created in public afterwards: it is an option when you create a project, and the event triggers guide has the SQL for an existing one. Tables that already exist still need the statement above. What the public key, two users and the secret key get back after each step is in how to enable RLS in Supabase.
Enabled is the easy part to verify. The free Supabase security check lists tables with RLS off, policies that allow every row, views and roles that bypass RLS, and write policies open to anonymous visitors. Whether each policy does what your settings screen promises is a harder question, and the rest of this article is about that.
Why are policy tests not enough to test Supabase RLS?
A policy test answers “does this policy do what I wrote?”. Your users ask a different question: “if I untick this box for this role, can they still do it?”. On a small app those questions have the same answer. On an app with a settings page where admins edit a permission matrix, they drift apart.
The app had 41 tables with RLS enabled and 402 CREATE POLICY statements across 255 migrations. The admin screen showed a matrix of areas (projects, tasks, timesheets, files and so on) against actions (view, create, edit, archive), one column per role. Every saved box was a promise to the admin. Nothing checked that the database kept it.
Supabase documents the standard tools well: pgTAP tests and the test helpers let you create users, switch to them and assert what they can read. Use them. The method below sits on top: it is driven by the matrix the admin sees, not by the list of policies.
How does the matrix proof work?
Each box in the matrix becomes a probe. A probe signs in as a member of the role, performs one real action, and records the outcome. It does this twice: once with the box off and once with the box on, everything else equal. If the outcome changes, the box is enforced. If it does not, the box does nothing, however convincing it looks on screen.
- One box in the matrixExample: Standard Member · Tasks · Create
- Box off: act as a member of the roleCreate a task through the same path the app uses. Record the outcome.
- Box on: repeat the same actionSame user, same data. Only the box changed.
- Compare the two outcomesThe verdict depends only on what the database did.
- Outcome changedEnforced. Refused when off, allowed when on.
- Same both waysDoes nothing. The screen promises control that does not exist.
- Screen and database disagreeA bug. The page shows a button the database refuses, or the reverse.
“Outcome” here means whatever a consumer of the permission does: a policy returns rows or refuses a write, a database function raises, a trigger blocks, or an edge function answers 403. One box can guard several of these, so the 87 boxes took 279 checks per role. Each check ended in one of these verdicts:
| Verdict | Checks per role | What it means |
|---|---|---|
| Effect | 227 | The outcome flipped with the box |
| Dead | 30 | The outcome stayed the same with the box off and on |
| Unreachable | 19 | The action cannot be reached for this role at all, proven separately |
| Edge function | 1 | Enforced by an edge function, checked over HTTP |
| Screen only | 1 | Changes only what the page shows, covered by a front-end test |
| Screen and database agree | 1 | What the page offers matches what the database allows |
| Fail | 0 | A check whose outcome did not match its expectation |
What did the proof find?
The run on 15 September 2026 covered all five roles an admin can edit (Admin, Senior, Standard, Restricted and a cloned custom role). The results were identical across roles.
None of the 30 let anyone in. For 29 of them, no policy, function or trigger ever read the box; the last one stopped mattering after a policy was rewritten. That is still a real problem: an admin who unticks “Delete” for a role believes the role cannot delete. We hid all 30 rather than wire them up, because each one would have needed a product decision, and a box that does nothing should not be on the screen while you make it.
The same work surfaced four more defects:
| What was wrong | How it showed | Fix |
|---|---|---|
| 30 boxes did nothing | Dead verdict, identical outcome off and on | Hidden from the matrix |
| Three database functions let an action through when a task had no assignee | A probe that should have been refused was allowed | The functions now refuse when the value is missing |
| Resetting a timesheet to draft depended on the wrong box | Screen and database disagreed for one role | Gated on the reopen permission it belongs to |
| A member saw new permissions only after a reload | The database had changed, the page had not | Permissions refresh every 60 seconds and on window focus |
| A column default broke its own check constraint, so inserts without that column failed | Found by the security review of the fix, during the same work | Default changed to a value the constraint allows |
The missing-assignee bug was the one that mattered. The guards were written like this in PL/pgSQL:
if not (has_permission or assignee_id = auth.uid()) then
raise exception 'forbidden';
end if;
When assignee_id is null, assignee_id = auth.uid() is null, false or null is null, not null is still null, and if treats null as false. The exception never fires. In production no task had an assignee set, so this was not an edge case: it applied to every task in scope. The fix wraps the condition in coalesce(…, false) so a missing value refuses, and it shipped first, on its own, before the rest of the batch. I wrote this bug up separately, with the sweep I used to find every copy of it: a NULL in a PL/pgSQL IF NOT skipped the check on 3683 tasks.
How do you run it against a copy of production?
A proof against a schema that differs from production proves nothing about production. The harness runs on the local Supabase stack, in a separate database that is a copy of the production schema plus the migrations under review. Before every run it compares a fingerprint of both local databases: 799 rows describing tables, policies, functions and grants. Any difference stops the run.
- Production schemaCopied to one trusted machine. It never goes to a hosted CI runner.
- Local stack: app databaseServed by the local API and auth, used by the end-to-end checks.
- Local stack: isolated proof databaseSame schema, used only by the matrix proof.
- Fingerprint check799 rows per database. Any difference stops the run before a single probe.
- Probes run as each roleAs real signed-in members, through the same paths the app uses.
- No trace leftRow counts at the end must equal row counts at the start.
Two details made the harness trustworthy:
- Break it on purpose first. Before trusting a green run, I replaced one insert policy with one that accepts everything and ran the proof again. It had to go red on the boxes that policy guards. A harness that stays green under a broken policy is decoration.
- Check the saved state too. The first pass starts every role from a clean baseline. A second pass starts from each role’s current saved matrix, because a box can behave differently next to the boxes an admin actually ticked.
How do you keep it green after release?
A proof you run once goes stale with the next migration. The proof now runs before every push that touches migrations, the auth code or the matrix itself.
- git pushThe change touches migrations, auth or the matrix.
- Pre-push hook: matrix proofRuns locally against the proof database. Red blocks the push.
- Push reaches mainDeploy runs as usual.
- Self-hosted CI runThe same proof again, on the machine that holds the production schema copy.
The proof is 135 tests in 11 files, next to about 3,100 ordinary unit tests in the same project.
What did not work?
- Hosted CI could not run it. The proof needs the production schema copy, and I did not want that on a hosted runner. So the blocking gate is a pre-push hook, and CI on a self-hosted machine is a second check that the deploy does not wait for.
- Fixed row counts broke. The first “no trace” check compared against fixed numbers. The next legitimate migration added a permission row and turned it red. It now compares the counts at the end with the counts at the start.
- Skipped is not passed. The end-to-end checks need the local edge runtime. When it is down, they skip, and a skip is easy to read as green.
- It is slow on a busy laptop. Per-role passes needed longer timeouts on a loaded machine.
- It proves what the probes describe. A box nobody wrote a probe for is reported as a coverage gap, not as safe.
How to repeat this on your Supabase app
- List every permission the screen lets someone save: role × area × action. That list is the spec, not your policies.
- For each box, write down the real action it should control and how a refusal shows (no rows, an error, a 403).
- Build a database that matches production and fingerprint it, so a schema drift stops the run.
- Run each action as a signed-in member, box off then box on, and compare.
- Break one policy on purpose and confirm the proof goes red.
- Hide or wire every box that does nothing, then make the proof a gate before push.
Two holes sit outside a role matrix, so check them separately: a user who belongs to two orgs and a role taken from sign-up metadata. The rest of what I check on a Lovable or Supabase app, from grants to rate limits, is in my Lovable app security checklist.
For a first pass before the matrix, the free Supabase security check reads a project’s roles, grants, policies and auth settings against 46 OWASP Top 10:2025 rules. It finds the obvious gaps; whether each permission box does what it says is the proof above.
If your app already has RLS but you are not sure it does what the settings screen says, the same method works as an audit of an existing codebase, the first step of a project rescue. I wrote about the project behind these numbers in the audit firm time tracking case. What else that tracker got wrong without any screen showing it, from report totals to a confidential client, is in time tracking for audit firms.
My similar case
Building a time tracker for an audit firm, I found 4 errors no screen showed, including a confidential client leaking through report totals and tag counts. Every access rule now lives in the database and is tested before each deploy; the full story is in the audit firm case.
Not sure your RLS matches your settings screen? Write to me and we’ll test it the same way.
Not sure your RLS holds?
Tell me what you have now and what you need. I'll reply with the option I'd pick.
Free consultation: a second look at your idea or your app.
Write to me