Deutsch
Free tool

RLS policy builder for Supabase

Pick who may see a table’s rows and get Supabase row level security SQL, a test script and a fix prompt. Every pattern runs on a real Postgres first.

Runs in your browser. Nothing you enter is sent anywhere.

Who may see the rows?
The owner may also…
todos_rls.sql
-- 1. Turn on row level security: without a matching policy, nobody gets a row.alter table public.todos enable row level security;-- Remove every policy this builder may have added before, so changing your choices and running it again leaves nothing behind.drop policy if exists "todos: owner can read" on public.todos;drop policy if exists "todos: anyone can read" on public.todos;drop policy if exists "todos: owner can insert" on public.todos;drop policy if exists "todos: owner can update" on public.todos;drop policy if exists "todos: owner can delete" on public.todos;drop policy if exists "todos: team members can read" on public.todos;drop policy if exists "todos: team members can insert" on public.todos;drop policy if exists "todos: team members can update" on public.todos;drop policy if exists "todos: team members can delete" on public.todos;-- Table rights as Supabase sets them by default (this undoes an earlier "server only"). The policies below decide which rows.grant select, insert, update, delete on public.todos to authenticated;-- 2. Signed-in users see only their own rows.create policy "todos: owner can read"  on public.todos for select  to authenticated  using ((select auth.uid()) = user_id);-- 3. Users can only write their own rows. WITH CHECK stops them from writing rows for someone else.create policy "todos: owner can insert"  on public.todos for insert  to authenticated  with check ((select auth.uid()) = user_id);create policy "todos: owner can update"  on public.todos for update  to authenticated  using ((select auth.uid()) = user_id)  with check ((select auth.uid()) = user_id);create policy "todos: owner can delete"  on public.todos for delete  to authenticated  using ((select auth.uid()) = user_id);-- 4. New rows belong to whoever creates them, even if the app forgets to send the owner.alter table public.todos alter column user_id set default auth.uid();-- Index: keeps the policy check fast on big tables.create index if not exists todos_user_id_idx on public.todos (user_id);

Run it in the Supabase SQL editor or add it as a migration. Changed your choices? Run the new version: it removes what an earlier one added.

Which pattern fits my table?

PatternTypical tablesVisitor without accountSigned-in user
Only the ownernotes, orders, messages, private profilesnothingown rows
Public read, owner writesblog posts, listings, public profilesreads allreads all, edits own
Team membersprojects, documents, invoices of a workspacenothingrows of their teams
Server onlypayouts, audit logs, webhook events, internal settingsnothingnothing

When in doubt, start stricter. Opening a table up later is a small change; finding out after launch that strangers could read it is not.

What the generated SQL does

  • enable row level security switches the table from “everyone with the public key gets everything” to “nobody gets anything unless a policy allows it”.
  • to authenticated limits a policy to signed-in users, so the database skips it for visitors.
  • using decides which existing rows a user can see, change or delete. with check decides which rows they may write. On an update, a with check that is looser than using (for example with check (true)) would let a user change the owner column and hand a row to someone else. The builder repeats the owner check in both, which is the same as what Postgres does when with check is left out.
  • (select auth.uid()) is the signed-in user’s id, worked out once per query.
  • The index on the owner or team column keeps those checks fast as the table grows.
  • drop policy if exists for every policy the builder can create, plus the table rights, makes the script safe to run again after you change your choices: nothing from an earlier run stays behind.

The team pattern also protects the membership table: members can see their own memberships, which the check needs, but nobody can insert themselves into a team. The server-only pattern takes the table rights away from the browser roles altogether, so even a policy added by mistake later would not open it.

Why old policies can still leak

Policies add up. If your table already has a policy such as using (true) from an earlier prompt, it keeps letting every row through next to the new ones. Open the Old policies tab, run the query and drop every policy you don’t recognise. The fix page on policies with using (true) explains the pattern in detail.

How to test the result

The Test it tab gives you two snippets for the Supabase SQL editor. The first acts as a real signed-in user (paste an id from Authentication, Users), the second as a visitor with only the public key. Both only read, so they change nothing, and the role switch ends with the snippet. For a fuller method, including how to test writes, see how to test RLS policies with SQL.

For the background on every line, read the complete guide to Supabase row level security.

Frequently asked questions

Does the order of policies matter?

No. Postgres combines all permissive policies for the same command with OR: a row is visible if any one of them allows it. That is why an old, too open policy keeps leaking even after you add strict ones, and why the builder shows a query to list them.

Why (select auth.uid()) instead of auth.uid()?

Wrapping the call in a select lets Postgres work out the user id once per query instead of once per row. Supabase recommends it in its performance advice for RLS; on large tables the difference is big.

Why is there no insert policy on the team membership table?

If signed-in users could insert into it, anyone could add themselves to any team and read its data. Adding members is a decision your server should make, for example in an edge function that checks an invite.

Can the SQL break my app?

It can if the app relies on the old, open access, for example a page that lists other users’ rows or an insert that sends someone else’s user id. Run the test tab with a real user first, then click through your app with a second account.

Sources

  1. 1.Row Level Security — Supabase Docs
  2. 2.Row Security Policies — PostgreSQL Documentation
  3. 3.CREATE POLICY — PostgreSQL Documentation
  4. 4.Understanding API keys — Supabase Docs
  5. 5.A01:2025 Broken Access Control — OWASP

Updated