Any signed-in user can add themselves to any team
Your data is scoped to team members, but the members table lets any user insert their own row with someone else's team id.
- Severity
- High (critical with personal data)
- Who can exploit it
- Anyone who can sign up
- Found by
- patchlabs-cli and the free RLS check (static, from 17 Nov 2026)
- Lab proof
- Not lab-proven per app: file and line in the report
What it is
Multi-tenant apps (teams, organisations, workspaces, clinics, stores) usually scope data with one rule: “you can see this row if you are a member of its team”. In Supabase that is a policy like team_id in (select team_id from team_members where user_id = auth.uid()). The rule is only as strong as the team_members table behind it.
PL-038 means that table has an INSERT or UPDATE policy that only checks “the row is mine”, for example with check (user_id = auth.uid()). Any signed-in user can then insert (their id, your team id), or change the team id on their own row, and every policy that asks “is the caller a member?” now says yes. Team ids are not secrets: they appear in URLs, invite links and API responses.
Why AI builders produce it
The first time a builder wires up “create a team” or “accept an invite”, the insert into team_members fails with “new row violates row-level security policy”. The quickest policy that makes the error go away is with check (user_id = auth.uid()). It reads as safe (users can only add themselves) and nothing in testing breaks, because the only person testing is already in every team.
Example of vulnerable code
Simplified from the patterns we see in AI-built apps. Synthetic: not taken from any real app.
-- Data is scoped to team members...
create policy "Members read customers" on public.customers
for select to authenticated
using (team_id in (select team_id from public.team_members
where user_id = (select auth.uid())));
-- ...but anyone can make themselves a member of any team
create policy "Users can join" on public.team_members
for insert to authenticated
with check (user_id = (select auth.uid()));
Check it yourself
# the free, open-source scanner (reads the SQL files as text, sends nothing)
uvx --from git+https://github.com/manra399/patchlabs-cli patchlabs scan .
-- or in the SQL editor: write policies on tables that other policies trust
select tablename, policyname, cmd, with_check, qual
from pg_policies
where schemaname = 'public'
and cmd in ('INSERT', 'UPDATE', 'ALL')
and tablename ~ '(member|membership|users_to|_users)';
-- a with_check that only compares user_id with auth.uid() is PL-038
The fix
Users should never write their own membership. Remove the self-service policy and add members through a function that checks the caller is an admin of that team (or holds a valid invite).
create policy "Users can join" on public.team_members
for insert to authenticated with check (user_id = (select auth.uid()));
create function public.is_team_admin(t uuid) returns boolean
language sql stable security definer set search_path = '' as $$
select exists (select 1 from public.team_members
where team_id = t and user_id = (select auth.uid()) and role = 'admin') $$;
create policy "Admins add members" on public.team_members
for insert to authenticated with check (public.is_team_admin(team_id));
Creating a team needs its first admin row, so do that in one security definer function (create_team(name)) that inserts the team and the caller as admin together. Accepting an invite goes through another (accept_invite(token)) that checks the token, its email and its expiry. If the table has an UPDATE policy, drop it or add a with check that keeps team_id and role unchanged. The multi-tenant guide has the full set.
Code findings come with the file, the line and a one-line fix in the report, for your engineer to make. PatchLabs never pushes to your repo.
Ask your AI builder to fix it
Built with Lovable, Bolt, Replit or Cursor? Paste this into the chat. It asks for this one fix and nothing else, and to see the change before it’s applied. Read the change, or have your engineer read it, before you accept.
My Supabase app scopes data to team (or organisation, workspace) members, but the members table has an INSERT or UPDATE policy that only checks user_id = auth.uid(), so any signed-in user can add themselves to any team or move their row to another team. Remove those self-service policies. Add a security definer function create_team(name) that creates the team and adds the caller as admin, an accept_invite(token) function that checks the invite token, email and expiry before adding the caller, and an insert policy that only lets an existing admin of that team add members. If an UPDATE policy stays, make it keep team_id and role unchanged. Show me the exact change before you apply it, and don't change anything else.
Then check again with the free open-source CLI (patchlabs scan .), or run the full free check on your repo.
How PatchLabs finds it
[BEFORE] stranger customers → 0 rows OK [JOIN] stranger insert (me, victim team) → accepted [AFTER] stranger customers → 2 rows LEAK [FIX] admin-only insert through is_team_admin() [PROVE] stranger insert → refused DENIED stranger customers → 0 rows DENIED admin adds a member to own team OK
patchlabs-cli finds the membership tables your other policies rely on (directly, or through a helper function such as is_member()), then reads that table's INSERT, UPDATE and ALL policies. It flags a policy whose check is only “the row is mine” and passes one that checks a role, an invite, a subquery or a helper function. It ran clean on six open-source Supabase SaaS starters, including basejump and makerkit, which add members through functions. The free RLS check runs the same rule on a public repo, no sign-up. It reads SQL text and never connects to your database.
When the pattern is intended
A few apps really are open to anyone: a public community where joining a space is the point. That is fine when every row behind the membership check is meant for anyone who signs up. Say so in a migration comment, because the same pattern on a table that guards customer data is a breach.
Why it’s rated high (critical with personal data)
High: anyone who can sign up gets everything a team member sees. Critical when the tables behind the membership check hold personal columns (customer emails, patient names), because then it is PL-002 for every team at once, one insert per team.
Related findings
Any signed-in user can read every row
Signing up unlocks other people's rows. If sign-up is open, that means anyone.
PL-004UPDATE policy missing WITH CHECK
Users may edit their own row, and nothing stops them changing its role, plan or owner.
PL-019Access decided by user_metadata, which users can edit
Roles stored where users can rewrite them. One call from the browser and they're an admin.
Guides
Free check
Does your app have PL-038?
Paste your public repo. PatchLabs Code reads it for this and every other code finding, and the Lab rebuilds your database to test who can read what.
Last reviewed 10 Nov 2026. Finding IDs are stable: link to them freely. Spotted a mistake? Tell us.