Skip to content
ShipCheck
Guides

Supabase RLS for insert, update and delete (and turning RLS on for every new table)

Updated 25 October 2026

Most Supabase RLS advice is about reads: can a stranger see your rows? Writes are where vibe-coded apps break more quietly. A user edits someone else's post, gives their row to another account, or deletes a whole table through the API, and nothing looks wrong in your app. This guide covers policies for insert, update and delete, how to test them, and how to make sure every new table starts with RLS on.

Check your own app for this, free.

Paste your live URL. ShipCheck looks for leaked API keys in your page and JavaScript, exposed files like /.env and /.git, missing security headers, SSL certificate problems, domain expiry (custom domains only) and what Google sees without running JavaScript. You'll see your score without signing up.

See an example report

What ShipCheck checks here: the free scan detects your Supabase project and its public key. Verify you own the app (free) to unlock the table check, which tests which tables answer anonymous reads and counts rows without downloading them. It doesn't test writes, so use the steps below for insert, update and delete.

USING vs WITH CHECK: which one each command needs

A policy can have two expressions. using (…) filters the existing rows a command can see or target. with check (…) checks the new row a command is trying to write. If a write fails its check, Postgres rejects it with "new row violates row-level security policy".

CommandUSINGWITH CHECKWatch out for
selectYesNoRows that fail it are hidden, not an error.
insertNoYesReturning the new row (.insert().select()) also needs a SELECT policy.
updateYes (which rows you can edit)Yes (what the row may become)Supabase says UPDATE also needs a matching SELECT policy, or it won't work as expected.
deleteYesNoRows that fail it are skipped silently: 0 rows deleted, no error.

If an update policy has no with check, Postgres reuses the using expression for the new row. Writing both out is still clearer, and AI-generated policies often get one of them wrong. Source: Supabase Row Level Security docs.

Policies keyed on auth.uid()

Example table: each row belongs to the user who created it. The default auth.uid() means the client doesn't even need to send user_id.

create table public.notes (
  id bigint generated always as identity primary key,
  user_id uuid not null default auth.uid() references auth.users (id) on delete cascade,
  body text not null,
  created_at timestamptz not null default now()
);
alter table public.notes enable row level security;

-- Read own rows (UPDATE and insert-then-select need this too)
create policy "notes: select own" on public.notes
  for select to authenticated
  using ((select auth.uid()) = user_id);

-- Insert only rows that belong to you
create policy "notes: insert own" on public.notes
  for insert to authenticated
  with check ((select auth.uid()) = user_id);

-- Update only your rows, and they must still be yours afterwards
create policy "notes: update own" on public.notes
  for update to authenticated
  using ((select auth.uid()) = user_id)
  with check ((select auth.uid()) = user_id);

-- Delete only your rows
create policy "notes: delete own" on public.notes
  for delete to authenticated
  using ((select auth.uid()) = user_id);

Notes on the pattern:

  • to authenticated keeps logged-out visitors (the anon role) out of every write. There is no policy for anon, so anonymous writes are denied.
  • Wrapping it as (select auth.uid()) is Supabase's recommended form, because Postgres can then evaluate it once per query instead of once per row.
  • Don't use using (true) or auth.role() = 'authenticated' on update or delete. Either one lets any signed-in user edit or delete everyone's rows, and anyone can create an account.

Stop a user moving a row to someone else

Without with check (or with a loose one), a user can send {"user_id": "<someone else's id>"} in an update and plant content in another account, or move their own row there. The with check ((select auth.uid()) = user_id) above blocks that, because the row has to still be theirs after the update. To make user_id impossible to change at all, take away column-level update rights and grant back only the columns users may edit:

revoke update on public.notes from authenticated;
grant update (body) on public.notes to authenticated;

An update that touches user_id now fails with "permission denied" before RLS even runs.

Delete

Delete needs only using. The common mistake is the opposite: no delete policy, so the app's delete button "does nothing", and someone fixes it by adding using (true). Keep delete keyed on the owner. For team apps, check membership instead, for example using (exists (select 1 from public.members m where m.team_id = notes.team_id and m.user_id = (select auth.uid()))). If users should never hard-delete, leave delete without a policy and use a soft-delete column through an update policy.

Never give the client service_role

The service_role key, and the newer sb_secret_ key, map to a Postgres role with BYPASSRLS. Every policy on this page stops applying. If an AI builder "fixes" a failing insert by switching the browser client to the service key, anyone who opens DevTools can copy the key and read, change or delete every row in every table. Supabase's new secret keys refuse requests that look like they come from a browser, but an attacker uses curl, so that isn't protection. Keep the service key in server code (an Edge Function or API route that runs its own permission checks) and fix the policy instead. More on this: is the Supabase anon key safe? If a service key has already leaked, see which keys to rotate after a breach.

Test your write policies

Only run these on your own project, ideally a staging copy or a test table, because a policy that's wrong will let the write happen. SB is your project URL and ANON your public key. With a legacy eyJ… anon key, also add -H "Authorization: Bearer $ANON" to the logged-out requests.

1. Logged out (anon)

# Insert: expect a 401/403 error mentioning row-level security
curl -i -X POST "$SB/rest/v1/notes" -H "apikey: $ANON" \
  -H "Content-Type: application/json" -d '{"body":"rls test"}'

# Update and delete: expect [] (nothing matched, nothing changed)
curl -s -X PATCH "$SB/rest/v1/notes?id=eq.1" -H "apikey: $ANON" \
  -H "Content-Type: application/json" -H "Prefer: return=representation" -d '{"body":"x"}'
curl -s -X DELETE "$SB/rest/v1/notes?id=eq.1" -H "apikey: $ANON" -H "Prefer: return=representation"

If a row comes back from the PATCH or DELETE, anonymous visitors can change your data.

2. As a second user

Create two test accounts, A and B. Make a note as A, then try to change it as B:

# Sign in as user B and keep the access token
TOKEN_B=$(curl -s "$SB/auth/v1/token?grant_type=password" -H "apikey: $ANON" \
  -H "Content-Type: application/json" -d '{"email":"b@example.com","password":"..."}' | jq -r .access_token)

# Edit or delete A's note: expect []
curl -s -X PATCH "$SB/rest/v1/notes?id=eq.<A's note id>" -H "apikey: $ANON" -H "Authorization: Bearer $TOKEN_B" \
  -H "Content-Type: application/json" -H "Prefer: return=representation" -d '{"body":"hacked"}'

# Insert a row owned by A, or move B's own row to A: expect a row-level security error
curl -i -X POST "$SB/rest/v1/notes" -H "apikey: $ANON" -H "Authorization: Bearer $TOKEN_B" \
  -H "Content-Type: application/json" -d '{"body":"planted","user_id":"<A user id>"}'
curl -i -X PATCH "$SB/rest/v1/notes?id=eq.<B's note id>" -H "apikey: $ANON" -H "Authorization: Bearer $TOKEN_B" \
  -H "Content-Type: application/json" -d '{"user_id":"<A user id>"}'

Then do the same for every table users can write to. To test reads in the same way, see the Supabase RLS checker guide.

Turn RLS on for every new table automatically

Supabase's docs say tables created in the Dashboard get RLS enabled by default, but tables created in the SQL Editor or by other tools don't. Many AI-generated migrations fall into that second group. Two ways to close the gap:

  • An event trigger. Supabase's event triggers guide includes an rls_auto_enable() function and an ensure_rls event trigger that runs alter table … enable row level security on each new table in public. Copy it from that page rather than from a blog post. It only affects tables created after you install it, so existing tables still need RLS turned on by hand.
  • Security Advisor. Under Advisors → Security Advisor, Supabase flags tables in exposed schemas that have RLS off. Check it after every big change your AI builder makes.

The 30 October 2026 grants change

According to Supabase's changelog, from 30 October 2026 new tables in the public schema of existing projects are no longer exposed to the Data API automatically (new projects have had this default since a rollout that started 30 May 2026). After the change, a new table needs an explicit grant before anon or authenticated can reach it. Tables that already exist keep their current grants.

Grants and RLS are separate layers. A grant decides whether a role can reach a table at all, and RLS decides which rows it can touch. If a new table fails with permission denied for table … (42501), add the grant your app actually needs. Don't turn RLS off. Supabase's suggested order for each new table is grant, enable RLS, add policies:

grant select, insert, update, delete on public.notes to authenticated;
alter table public.notes enable row level security;
-- then the policies above

Only grant anon what logged-out visitors really need, which is often nothing, or select on public content. See Securing your API. More detail: fixing "permission denied for table" (42501) safely.

Checklist

  1. RLS is enabled on every table in public (Security Advisor shows no RLS errors).
  2. Every write policy is to authenticated and keyed on (select auth.uid()) or a membership check. No using (true) on writes.
  3. Insert policies use with check, and update policies have both using and with check, plus a SELECT policy.
  4. user_id can't be changed to another user, through with check or column-level grants.
  5. Delete is owner-only, or has no policy if users shouldn't delete.
  6. No service_role or sb_secret_ key in client code.
  7. Logged-out curl and second-user tests return [] or an RLS error for every write.
  8. The ensure_rls event trigger is installed, and new-table migrations include grants, RLS and policies.

FAQ

What's the difference between USING and WITH CHECK in Supabase RLS?

USING filters which existing rows a command can see or act on (SELECT, UPDATE, DELETE). WITH CHECK validates the new row being written (INSERT, UPDATE). UPDATE uses both: USING decides which rows you may edit, WITH CHECK decides what the row may look like afterwards. If an UPDATE policy has no WITH CHECK, Postgres applies the USING expression to the new row as well.

Why does my Supabase update or delete succeed but change nothing?

RLS filters out rows the policy doesn't allow instead of raising an error, so the request matches 0 rows. The usual causes: no UPDATE or DELETE policy, a USING expression that doesn't match the signed-in user, or (for UPDATE) no SELECT policy. Supabase notes that UPDATE needs a matching SELECT policy to work. Don't fix it with using (true) or the service_role key.

How do I stop users changing user_id to someone else's in Supabase?

Add WITH CHECK ((select auth.uid()) = user_id) to the update policy, so the row must still belong to the user after the change. To block edits to user_id entirely, revoke UPDATE on the table from authenticated and grant UPDATE only on the columns users may change, for example grant update (body) on public.notes to authenticated.

How do I enable RLS by default on new tables in Supabase?

Tables created in the Supabase Dashboard have RLS on by default, but tables created with SQL don't. Supabase's event triggers guide includes an rls_auto_enable() function and ensure_rls event trigger that enables RLS on each new table in the public schema. It only covers tables created after you install it, so enable RLS on existing tables by hand and check Security Advisor.

What changes for new Supabase tables on 30 October 2026?

Per Supabase's changelog, new tables in the public schema of existing projects stop being exposed to the Data API automatically. You need an explicit GRANT before anon or authenticated can reach them. Existing tables keep their grants. RLS is unchanged and still required, so a 'permission denied for table' error means add the right grant, not disable RLS.

Does ShipCheck test my insert, update and delete policies?

No. The anonymous free scan detects your Supabase project and public key but doesn't test tables. Verify you own the app (free) to unlock the table check, which tests which tables answer anonymous reads, using HEAD requests that only return a row count. It never writes to your database, so test write policies yourself with the curl steps in this guide.

Run the same checks on your app.

A free scan takes under a minute. No card, and no sign-up to see your score and the list of issues.

See an example report