Guides · Updated 2026-11-29
Supabase RLS: USING vs WITH CHECK, and the policy mistake that lets users write rows as someone else
Short answer: In a Row Level Security policy, USING filters existing rows: which rows a user can read, update or delete. WITH CHECK validates new data: what a row is allowed to look like after an INSERT or UPDATE. INSERT policies only take WITH CHECK, SELECT and DELETE only take USING, and UPDATE takes both. If an UPDATE policy has only USING, Postgres reuses it as the check, which is fine. The dangerous cases are an explicit with check (true), an INSERT policy that doesn't compare user_id to auth.uid(), and a second permissive policy that quietly allows more. For an owner-only table, use (select auth.uid()) = user_id in both clauses.
The two clauses in one sentence each
- USING: "which existing rows can this user touch?" Rows that fail it are silently filtered out of SELECT, UPDATE and DELETE. No error, just fewer rows.
- WITH CHECK: "is this user allowed to save this row?" It runs on the new version of a row in INSERT and UPDATE. If it fails, Postgres throws an error and the whole statement is aborted.
So USING protects data that already exists, and WITH CHECK protects what gets written. A table can have perfect read rules and still let anyone write rows that belong to someone else, because the write side is a separate check.
Which policy type takes which clause
- for select: USING only. A SELECT policy can't have WITH CHECK.
- for insert: WITH CHECK only. An INSERT policy can't have USING (there's no existing row to filter).
- for update: both. USING picks the rows the user may update; WITH CHECK decides what the updated row may look like. If you leave out WITH CHECK, Postgres uses the USING expression for both.
- for delete: USING only. There is no new row to check.
- for all: USING applies to reads, updates and deletes; WITH CHECK (or USING, if you left WITH CHECK out) applies to inserts and updates.
Also from the Supabase docs: an UPDATE needs a matching SELECT policy, otherwise it won't work as expected (the user can't see the row it is trying to change).
The owner-only pattern (copy this)
For a table where each row belongs to one user through a user_id column, these four policies are the standard setup from the Supabase docs. Wrapping auth.uid() in (select ...) lets Postgres evaluate it once per query instead of once per row.
alter table public.notes enable row level security; create policy "read own notes" on public.notes for select to authenticated using ( (select auth.uid()) = user_id ); create policy "create own notes" on public.notes for insert to authenticated with check ( (select auth.uid()) = user_id ); create policy "update own notes" on public.notes for update to authenticated using ( (select auth.uid()) = user_id ) with check ( (select auth.uid()) = user_id ); create policy "delete own notes" on public.notes for delete to authenticated using ( (select auth.uid()) = user_id );
The WITH CHECK on the update policy is technically redundant here (Postgres would reuse USING), but writing it out makes the intent obvious and stops someone from later "loosening" only one side.
4 common mistakes in AI-built Supabase apps
- An insert policy that is just with check (true), or checks only that the user is logged in. Any signed-in user can then create rows with someone else's user_id: fake orders, messages "from" another user, comments on their behalf. Fix: with check ( (select auth.uid()) = user_id ).
- An update policy with using (auth.uid() = user_id) and with check (true). The user can only pick their own rows, but they can save them with a different user_id, handing a row to another account or moving it into a team they don't belong to. Fix: make WITH CHECK compare the owner too, or drop it so USING is reused.
- A second permissive policy. Policies of the same kind are combined with OR, so one forgotten "allow all for authenticated" policy (say, one added while debugging a 42501 error) overrides every careful policy next to it. Fix: list all policies on the table and delete the ones you don't need.
- Trusting the row check to protect columns. Even a perfect owner-only update policy lets users change every column of their own row, including plan, credits, role or is_admin if those live there. RLS works on rows, not columns. Fix: keep those fields in a separate table users can't write, or use column privileges (revoke the table-level UPDATE from authenticated and grant UPDATE only on the safe columns), or set them only from server code.
Check your own policies in 2 minutes
In the Supabase SQL editor, list every policy with both clauses side by side. Look for with_check = true, empty with_check on insert, and more than one permissive policy for the same command:
select tablename, policyname, permissive, cmd, roles, qual as using_expr, with_check from pg_policies where schemaname = 'public' order by tablename, cmd;
Then test it like a stranger would: sign up two accounts (A and B). Logged in as A, try to insert a row with B's user id, and try to update one of A's rows to set user_id to B's id. Both should fail with a row-level security error. Also try to update a column like plan or role on A's own row; if it succeeds and that column matters, apply fix 4.
A prompt for your AI builder
Review the Row Level Security policies on every table in my Supabase public schema. For each table that has a user_id (or owner) column: SELECT and DELETE policies must use (select auth.uid()) = user_id in USING; INSERT policies must use it in WITH CHECK; UPDATE policies must use it in both USING and WITH CHECK. Remove any with check (true) and any extra permissive policy that allows all authenticated users. List columns users must never change themselves (plan, credits, role, is_admin) and move them to a table only the server writes, or restrict them with column privileges. Show me the SQL before running it.
What this doesn't cover
Policies only matter if RLS is enabled on the table, and they don't apply to the service_role / secret key, which bypasses RLS. If that key ever ended up in your frontend code, the best policies won't help: rotate it first. A LeakyVibe scan checks your live app for exposed Supabase secret keys and other leaks from the outside in about 15 seconds.
Sources
Checked 2026-11-29. Supabase, "Row Level Security" (https://supabase.com/docs/guides/database/postgres/row-level-security): INSERT policies use with check so a user can't create a row that belongs to someone else; UPDATE combines using and with check, which stops a user reassigning user_id; without with check, using decides both; UPDATE needs a SELECT policy. PostgreSQL, "CREATE POLICY" (https://www.postgresql.org/docs/current/sql-createpolicy.html): USING rows are silently filtered, WITH CHECK failures throw an error and abort the command; INSERT can't have USING, SELECT and DELETE can't have WITH CHECK; an UPDATE policy with only USING uses it for both; permissive policies combine with OR. Supabase, "Column Level Security" (https://supabase.com/docs/guides/database/postgres/column-level-security): RLS doesn't restrict columns; revoke table-level UPDATE and grant column-level UPDATE.