</>RescueMyRepoFree scan

// guide · Supabase · RLS · data leaks · Dec 2, 2026

RLS is on and your Supabase data still leaks: 5 policy mistakes to check

Short answer

  • “RLS enabled” only means your policies decide. If one policy is true for every row, the table is open.
  • Permissive policies are combined with OR, so one bad policy beats all your strict ones.
  • The 5 usual culprits: using (true), a login-only check, an or auth.uid() is null branch, user_id = user_id, and a subquery like m.org_id = org_id.
  • Find them in 2 minutes with pg_policies, replace them with owner checks, then test as two users and as anon.

Why “RLS is on” isn't the same as “safe”

When an AI tool hits permission denied or new row violates row-level security policy, the quickest fix that makes the page work is usually a policy that allows everything. The page renders, the error is gone, the Security Advisor still shows RLS as enabled, and every visitor with your public anon key can read the table.

The PostgreSQL CREATE POLICY docs explain why one bad policy is enough: policies are permissive by default, and “all permissive policies which are applicable to a given query will be combined together using the Boolean ‘OR’ operator.” Your careful owner policy and a leftover “allow all” policy together mean “allow all.”

Find them in 2 minutes

-- Run in the Supabase SQL editor. Postgres prints each policy the way it resolved it.
select tablename, policyname, permissive, roles, cmd, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename, cmd;

Then shortlist the patterns below. It's a filter, not a proof, so still read every row of the full list:

-- Shortlist the usual suspects (still read the full list above)
select tablename, policyname, roles, cmd, qual, with_check
from pg_policies
where schemaname = 'public'
  and permissive = 'PERMISSIVE'
  and (
       qual = 'true' or with_check = 'true'
    or qual ilike '%auth.uid() IS NULL%' or with_check ilike '%auth.uid() IS NULL%'
    or qual ilike '%AS uid) IS NULL%'    or with_check ilike '%AS uid) IS NULL%'
    or qual ilike '%auth.uid() IS NOT NULL%' or qual ilike '%auth.role() = ''authenticated''%'
    or qual ~ '\m((?:[a-z_]+\.)?[a-z_]+) = \1\M' or with_check ~ '\m((?:[a-z_]+\.)?[a-z_]+) = \1\M'
  );

Prefer not to read SQL output? The free Supabase RLS policy checker runs one read-only query and flags all five mistakes, plus tables with RLS off, views that skip RLS and policies that trust user_metadata, with fix SQL. It runs in your browser.

The 5 mistakes

1. using (true) on private data

create policy "Enable read access for all users"
  on public.orders for select
  using (true);            -- every visitor, every row

The dashboard template “Enable read access for all users” is fine for a public product catalog and a leak on orders, profiles or messages. On INSERT/UPDATE/DELETE, true lets anyone change anyone's rows.

2. Checking that someone is logged in, not who they are

create policy "Authenticated users can read"
  on public.orders for select
  to authenticated
  using (auth.uid() is not null);   -- anyone who signs up

auth.uid() is not null and auth.role() = 'authenticated' pass for every account, and anyone can make one. Fine for shared data, a leak for per-user rows.

3. An or auth.uid() is null branch

-- Insecure (Supabase's own docs example)
create policy "rls_test_select" on rls_test
using ( auth.uid() is null or auth.uid() = user_id );

This one is straight from the Supabase RLS docs, marked as a danger: auth.uid() returns null for any request without a subclaim, “that includes every anon request,” so the branch “returns every row to any request without a user ID.” With no to clause the policy applies to anon too, and “every unauthenticated visitor reads the whole table.” Adding to authenticated isn't enough either: Supabase notes an authenticated JWT with no sub (for example one your server signs) still gets every row. Drop the branch.

4. A column compared with itself

create policy "Users edit own notes"
  on public.notes for update
  to authenticated
  using (user_id = user_id)          -- always true
  with check (user_id = user_id);

user_id = user_id is true for every row where user_id isn't null. It usually appears when an AI tool rewrites auth.uid() = user_id or renames a variable. It never looks at the user.

5. A subquery whose bare column points at the wrong table

create policy "Members can view projects"
  on public.projects for select
  to authenticated
  using (
    exists (
      select 1 from public.org_members m
      where m.org_id = org_id            -- bare org_id = m.org_id!
        and m.user_id = (select auth.uid())
    )
  );

-- What pg_policies shows Postgres actually stored:
-- (EXISTS ( SELECT 1 FROM org_members m
--   WHERE ((m.org_id = m.org_id) AND (m.user_id = ( SELECT auth.uid() AS uid)))))

The most subtle one, common in team and multi-tenant apps. The PostgreSQL docs (Table Expressions) say qualifying an outer column “is only necessary if c1 is also the name of a column in the derived input table of the subquery.” The flip side: when the subquery's table does haveorg_id, a bare org_id means m.org_id. The condition becomes “is this user a member of any org?”, so every member of any team can read every team's projects. We reproduced it on PostgreSQL 17: user A saw both orgs' projects until org_id was written as projects.org_id.

Tip: pg_policies prints the resolved names, so the bug shows up as (m.org_id = m.org_id) even though your migration says m.org_id = org_id.

The fixed policies

-- Per-user rows
drop policy if exists "Users edit own notes" on public.notes;
create policy "Users edit own notes"
  on public.notes for update
  to authenticated
  using ((select auth.uid()) = user_id)
  with check ((select auth.uid()) = user_id);

-- Team rows: qualify the outer column with the table name...
drop policy if exists "Members can view projects" on public.projects;
create policy "Members can view projects"
  on public.projects for select
  to authenticated
  using (
    exists (
      select 1 from public.org_members m
      where m.org_id = projects.org_id
        and m.user_id = (select auth.uid())
    )
  );
-- ...or use the IN form, which can't be mixed up:
--   using (org_id in (select m.org_id from public.org_members m
--                     where m.user_id = (select auth.uid())))

-- Logged-out visitors need some rows? A separate, explicit, read-only policy:
create policy "Anyone can read published posts"
  on public.posts for select
  to anon, authenticated
  using (published = true);

Wrapping auth.uid() in (select ...) is the form Supabase's own RLS examples use; it doesn't change who matches. Keep public access as its own read-only policy on an explicit flag, never as a branch inside a per-user policy.

Also check

RLS can also be skipped entirely by views, SECURITY DEFINER functions and a service_role or sb_secret_ key in the browser.

Test as two users and as anon

begin;
set local role authenticated;
set local request.jwt.claim.sub = '<user A uuid>';
select count(*) from public.projects;   -- only A's org

set local request.jwt.claim.sub = '<user B uuid>';
select count(*) from public.projects;   -- only B's org

set local role anon;
set local request.jwt.claim.sub = '';
select count(*) from public.projects;   -- expect 0
rollback;

Policies run for the role and sub you set, so this shows exactly what each user would get through the API. Run it for every table that holds personal or team data.

Prompt to paste into Lovable, Cursor or Claude Code

Audit my Supabase RLS policies for conditions that are always true. Don't change behavior for intentionally public data.
1. List every CREATE POLICY in supabase/migrations (after applying later DROP POLICY statements) with table, command, roles, USING and WITH CHECK.
2. Flag: using (true) / with check (true) on tables with personal or per-user data; policies that only check auth.uid() is not null or auth.role() = 'authenticated' on per-user tables; any "auth.uid() is null" branch; any column compared with itself (user_id = user_id); and any subquery where an unqualified column is compared to the same column of the subquery's table (m.org_id = org_id).
3. Remember permissive policies are OR'd: one always-true policy opens the table even if others are strict.
4. Write one new migration that drops and recreates each flagged policy with an owner or membership check ((select auth.uid()) = user_id, or projects.org_id qualified in the subquery), scoped to authenticated. Keep public read-only policies only where I confirm the data is public.
5. Give me a SQL test that runs as two different users and as anon in a transaction and shows the row counts.
Do NOT disable RLS or use the service_role key in the browser.

Check it automatically

RescueMyRepo's free scan reads your Supabase migrations and flags all 5 patterns, plus tables without RLS, write grants to anon, views and SECURITY DEFINER functions that skip RLS, secret keys in your code or git history, unverified Stripe webhooks and unauthenticated AI routes.

Scan my repo freePublic GitHub repos · no signup · about a minute

FAQ

Supabase's Security Advisor says RLS is enabled. Am I safe?

Not necessarily. Enabling RLS only means every query is filtered by your policies. If one policy's condition is true for every row, the table is as open as it was without RLS. The page still works, nothing errors, and the dashboard still shows RLS as enabled, which is why these leaks get missed.

Why does one open policy override my strict ones?

Policies are permissive by default, and the PostgreSQL CREATE POLICY docs say all permissive policies that apply to a query are combined with OR. So a strict owner policy plus a leftover "Enable read access for all users" policy with using (true) means everyone can read every row. Only restrictive policies are combined with AND.

What's wrong with "or auth.uid() is null"?

Supabase's RLS docs: auth.uid() returns null for any request whose JWT has no sub claim, which includes every anon request. A condition with an or auth.uid() is null branch returns every row to any request without a user ID, and with no TO clause the policy also applies to anon, so every logged-out visitor reads the whole table.

How can a subquery in my policy be always true?

PostgreSQL looks up an unqualified column name in the innermost FROM first, and only falls back to the outer table if the subquery's tables don't have that column (PostgreSQL docs, Table Expressions). In exists (select 1 from org_members m where m.org_id = org_id ...), both sides refer to m.org_id, so the check never looks at the row being read. pg_policies shows what Postgres actually resolved: (m.org_id = m.org_id).

Is auth.uid() is not null (or auth.role() = 'authenticated') OK?

Only for data every signed-in user should see. It checks that someone is logged in, not which rows are theirs, and on most apps anyone can sign up. For per-user tables compare the owner column: (select auth.uid()) = user_id.

Does RescueMyRepo check for these?

Yes. The free scan reads your SQL migrations (applying drops in order) and flags using (true) policies, login-only policies on per-user tables, and since Dec 2, 2026 policies with an auth.uid() is null branch, a column compared to itself, or a subquery comparison whose bare column resolves to the subquery's own table. Policies you only created in the dashboard aren't in your repo, so also run the pg_policies query below.

Sources

Behavior per the linked docs, read Dec 2, 2026; mistakes 3-5 reproduced on PostgreSQL 17.