Your first check is free. No card needed.Run a free security check

Multi-tenant SaaS on Supabase: can one team see another team's data?

It can if a policy checks that the user belongs to some organisation instead of the organisation that owns the row, if inserts and updates have no with check on org_id, or if users can add themselves to an organisation's member list. The safe pattern is an org_members table that only admins or your server can write, a security definer helper in a private schema that returns the caller's organisation ids, and a policy on every tenant table, for select, insert, update and delete, that compares the row's org_id with that list. Confirm it by querying as a user of one organisation and checking that no other organisation's rows come back.

Imagine your app is used by a design studio and a dental clinic. Each has its own workspace, and every table has an org_id column. Your AI coding tool wrote the policies, the studio's staff see their projects, and the clinic's staff see theirs.

Then someone at the studio opens the Network tab, copies the request that loads projects, removes the org_id filter from the address and sends it again. The list comes back with the clinic's patient notes in it. The screens were scoped to one organisation; the database was not.

What should a multi-tenant policy actually check?

In the usual Supabase layout, every tenant table has an org_id, and an org_members table links users to organisations. A correct read policy answers one question for each row: is the caller a member of the organisation that owns this row?

Supabase's performance guide shows the shape, with a membership table called team_user: team_id in (select team_id from team_user where user_id = (select auth.uid())) (RLS performance). Most leaks between tenants are policies that drifted from that question. OWASP lists cross-tenant data leakage first among the risks of shared databases (OWASP Multi-Tenant Security Cheat Sheet).

We ran each broken policy below on a local PostgreSQL 17 copy with two organisations and Supabase's authenticated role. Each returned the other organisation's rows; each fix returned only the caller's.

Mistake 1: "is a member of something" instead of "is a member of this"

-- Broken: true for any user who belongs to any organisation
create policy "Members read projects" on public.projects
for select to authenticated
using (
  exists (select 1 from public.org_members
          where user_id = (select auth.uid()))
);

The subquery never mentions projects.org_id, so anyone with one membership reads every organisation's projects.

-- Fixed: the row's org_id must be one of the caller's organisations
create policy "Members read projects" on public.projects
for select to authenticated
using (
  org_id in (select om.organization_id from public.org_members om
             where om.user_id = (select auth.uid()))
);

Mistake 2: a column name that quietly means the outer table

This one looks correct. The membership table calls its column organization_id, the projects table calls it org_id, and the policy was written as if both used org_id:

-- Broken: org_members has no org_id column, yet this runs without error
using (
  org_id in (select org_id from public.org_members
             where user_id = (select auth.uid()))
)

PostgreSQL raises no error. When a name in a subquery is not a column of the subquery's own table, it is looked up in the outer query, so select org_id returns projects.org_id and the test becomes org_id in (org_id), true for every row whenever the caller has at least one membership. The PostgreSQL wiki explains this behaviour, which follows the SQL standard, and recommends qualifying column names so the mistake raises an error instead (PostgreSQL FAQ).

The fix is the one from mistake 1: give every table an alias and write om.organization_id. With the alias, a wrong column name fails loudly.

Mistake 3: reads are scoped, writes are not

Generated schemas often pair a careful select policy with a loose one for writes:

-- Broken: any signed-in user can create rows in any organisation
create policy "Members add projects" on public.projects
for insert to authenticated
with check (true);

The same goes for an update policy whose using checks membership but whose new row is never checked against the caller's organisations. PostgreSQL evaluates with check "against the proposed new contents of the row" (PostgreSQL, CREATE POLICY), so it is the clause that stops a user writing org_id for an organisation they are not in, or moving their own row into someone else's workspace. Supabase's linter flags WITH CHECK (true) and a missing WITH CHECK on insert and update policies as unrestricted access (lint 0024).

create policy "Members add projects" on public.projects
for insert to authenticated
with check (org_id in (select private.my_org_ids()));

create policy "Members edit projects" on public.projects
for update to authenticated
using (org_id in (select private.my_org_ids()))
with check (org_id in (select private.my_org_ids()));

private.my_org_ids() is defined further down.

Mistake 4: anyone can join any organisation

-- Broken: a user may insert a membership row for themselves, in any organisation
create policy "Users join orgs" on public.org_members
for insert to authenticated
with check (user_id = (select auth.uid()));

Every tenant policy trusts org_members, so whoever can write to it widens their own access. In our test, one insert of (the other organisation's id, my user id) was enough for every correctly written policy to start returning the other organisation's rows. Membership rows should be created by an organisation admin, or by your server when it accepts an invitation:

create policy "Admins add members" on public.org_members
for insert to authenticated
with check ((select private.is_org_admin(organization_id)));

private.is_org_admin is a helper like the one below that also checks role in ('owner', 'admin'). Your server adds the first owner when it creates an organisation.

Mistake 5: the organisation comes from somewhere the user controls

Three versions of the same mistake:

  • The client filters, the policy does not. The app sends .eq('org_id', currentOrg) and the policy is using (true) for authenticated. Removing the filter from the request removes the isolation.
  • The organisation is read from user_metadata. Supabase warns that users can edit their own user metadata, "so a role or tenant ID stored there lets a user grant themselves access" (managing user data). Use app_metadata or the membership table.
  • An old permissive policy is still there. PostgreSQL combines permissive policies with OR (PostgreSQL, CREATE POLICY), so a forgotten using (true) from an early prototype cancels the careful policy written later.

The pattern that holds up

Supabase recommends a security definer function in a schema the API does not expose for membership checks, which also avoids the infinite recursion error when org_members has policies of its own (row level security):

create schema if not exists private;

create function private.my_org_ids()
returns setof uuid
language sql stable
security definer
set search_path = ''
as $$
  select om.organization_id from public.org_members om
  where om.user_id = (select auth.uid())
$$;

revoke execute on function private.my_org_ids() from public;
grant usage on schema private to authenticated;
grant execute on function private.my_org_ids() to authenticated;

alter table public.projects enable row level security;

create policy "Members read projects" on public.projects
for select to authenticated
using (org_id in (select private.my_org_ids()));

-- plus the insert and update policies above, and a delete policy with the same using

create index on public.projects (org_id);
create index on public.org_members (user_id);

Supabase notes that a composite primary key on (team_id, user_id) does not index user_id on its own, so the membership lookup needs its own index (same page).

Supabase also shows a policy that reads organisation ids from the token's app_metadata, with a caveat: removing someone from a team only takes effect when their token is refreshed (same page).

How do I check my own app?

1. Read every policy on every tenant table. In the SQL Editor:

select c.relname as table_name,
       c.relrowsecurity as rls_on,
       p.policyname, p.cmd, p.roles, p.qual, p.with_check
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
join pg_attribute a on a.attrelid = c.oid
  and a.attname in ('org_id', 'organization_id', 'team_id', 'workspace_id', 'tenant_id')
  and not a.attisdropped
left join pg_policies p on p.schemaname = n.nspname and p.tablename = c.relname
where n.nspname = 'public' and c.relkind = 'r'
order by 1, 4, 3;

Look for rls_on false, a qual of true or one that never mentions the tenant column, insert policies with a loose with_check, and any membership insert policy that lets users add themselves.

2. Query as a real user of one organisation. Supabase's own policy tests switch role and user inside a transaction (testing RLS with pgTAP). You can do the same by hand:

begin;
set local role authenticated;
set local request.jwt.claim.sub = 'USER-ID-FROM-ORG-A';
select org_id, count(*) from public.projects group by org_id;
rollback;

One row, for organisation A, is a pass. Repeat for each tenant table, then try an insert with organisation B's id; it should fail with "new row violates row-level security policy".

3. Repeat it through the app. Create test accounts in two organisations, copy a request from the Network tab, change or remove the org_id filter and send it as the other account. OWASP advises testing through the role and connection path the app uses, proving that cross-tenant operations fail and same-tenant ones work (OWASP cheat sheet).

Views and security definer functions in public can skip these policies; our article on views and functions that skip row level security shows how to list them.

Checklist

CheckPass
RLS on every table with a tenant columnrls_on true for each
Read policy ties the row to the caller's organisationsMentions org_id and the membership list
Insert and update check the new org_idwith check uses the same list
Membership table writable only by admins or the serverNo self-insert policy
Tenant id never from user_metadata or the requestPolicies read org_members or app_metadata
No leftover using (true)Advisor lint 0024 is clear
Two-organisation test passesZero rows from the other organisation

Where does Saqr fit?

To have this tested on the live app after each release, give a Saqr Full task two test logins from different organisations. It tries to read, change and create records across them through your app's real requests and reports any that work, with the request, the response and a fix prompt for your AI coding tool. Your first check is free, no card needed.

Saqr (usesaqr.com) is AI security for web apps. Its AI agents attack your live app from the outside, the way a real attacker would, and show you exactly what to fix. From $19 a month, cancel any time. Tests only apps you have shown are yours.

Questions

Should org_id come from the JWT or from a membership table?

Either can be safe if the user cannot write it. A membership table takes effect immediately when someone is removed. Organisation ids in app_metadata avoid a lookup, but Supabase notes the change only applies once the user's token is refreshed. Never use user_metadata, which users can edit.

Why does my membership policy fail with infinite recursion?

Because the policy on org_members reads org_members, or two tables' policies read each other. Supabase's fix is a security definer function in a private schema that reads the membership table as its owner, which breaks the cycle.

Does my server code with the secret key respect these policies?

No. The secret key and the legacy service_role key bypass row level security, so server code that uses them must check the caller's organisation itself. OWASP advises against serving ordinary tenant requests through a role that bypasses row security.

What about users who belong to more than one organisation?

Test them specifically. A user in two organisations should see both, an outsider with no membership should see nothing, and a user removed from an organisation should lose its rows on the next request, or on the next token refresh if your policies read app_metadata.

Sources

The facts above were checked against these pages on 29 November 2026. Products and documentation change; follow the links for the current wording.

  1. Supabase documentation: Row level security
  2. Supabase documentation: Row level security performance
  3. Supabase documentation: Testing row level security with pgTAP
  4. Supabase documentation: Managing user data
  5. Supabase database linter: 0024 permissive RLS policy
  6. PostgreSQL documentation: CREATE POLICY
  7. PostgreSQL wiki: FAQ, wrong column name in a subquery
  8. OWASP Multi-Tenant Security Cheat Sheet

Saqr is independent and is not affiliated with Supabase or PostgreSQL. Each name is a trademark of its owner.