Cenk Kurtoğlu©26

Supabase "new row violates row-level security policy" is a check problem, not a credential problem

“New row violates row-level security policy” is the error you get when a write — or the read-back of that write — fails a check. Three different checks produce it, and one of them has nothing to do with the policy you are staring at. I measured twenty-six INSERT-path scenarios on a local PostgreSQL 17.12 container with roles shaped like Supabase's anon and service_role. Four of them look identical in the client and are fixed in completely different places.

The write check itself

The plain cases first. With RLS enabled, an INSERT must pass a WITH CHECK expression on a policy that covers both the INSERT command and your role. These are the modes most people eventually find:

#SetupMeasured signatureWhat it proves
1RLS on, no policy at all, INSERT as authenticatednew row violates row-level security policy for table "s1"With RLS on and no policy, the write side is default-deny. Nothing to grant, nothing to fix in code.
2RLS on, SELECT-only policy USING (true), INSERTnew row violates ... for table "s2"A SELECT policy never authorises a write. USING (true) reads everything and writes nothing.
3Policy FOR INSERT TO anon, INSERT as authenticatednew row violates ... for table "s3"The policy exists but its role list does not include you — same error as having no policy.
4Policy FOR ALL USING (true), WITH CHECK omitted, INSERTINSERT 0 1 — row readable afterwardsFOR ALL covers writes too, and its USING doubles as WITH CHECK. This is the only shape that reads and writes with one clause.
5Policy FOR INSERT WITH CHECK (tenant = jwt sub), own tenantINSERT 0 1The write check passed. This is the healthy baseline.
6Same policy, foreign tenantnew row violates ... for table "s5"WITH CHECK is evaluated against the row you are writing, not the rows you can see.
7Policy WITH CHECK (true), no INSERT grantpermission denied for table s7Different signature entirely: the grant gate, not the policy gate. Policies cannot grant.
8CREATE POLICY ... FOR INSERT USING (...) instead of WITH CHECKERROR: only WITH CHECK expression allowed for INSERTThe DDL refuses before any data moves. USING belongs to read and update paths only.
9INSERT-only policy, INSERT grant only, plain INSERTINSERT 0 1The trap's innocent half: the insert that actually works. Everything below fails on the same table.
10Same table, INSERT ... RETURNING id, no SELECT grantpermission denied for table q2RETURNING reads the row back, and reading needs SELECT privilege. This is the plain 42501 behind many "Supabase insert 403" reports.
11SELECT granted, still no SELECT policy, INSERT ... RETURNING idnew row violates ... for table "q3"Privilege fixed, policy still missing: the read-back now fails the RLS gate with the very error people chase in the policy they just wrote.
12SELECT granted, SELECT policy USING (false), INSERT ... RETURNING idnew row violates ... for table "r5"The read-back is really gated by the SELECT policy. USING (false) turns a passing write into this error.
13SELECT granted, SELECT policy USING (true), INSERT ... RETURNING idINSERT 0 1 — row returnedThree gates passed. RETURNING works only when all of grant + write policy + read policy pass.
14INSERT-only policy, plain INSERT, then SELECT as the same roleINSERT 0 1 — then 0 rows on read-backThe silent twin: the write succeeds and the row is invisible. No error anywhere.

Mode 8 is worth pinning up: an INSERT policy takes WITH CHECK, not USING. PostgreSQL rejects USING on an insert policy with only WITH CHECK expression allowed for INSERT — before any row moves. If you were about to debug that DDL at runtime, stop: it never ran.

The part that isn't your policy at all: RETURNING

Modes 9–11 are one table, one policy, one grant set. Plain INSERT works. Add returning id and it fails — and the error is the same one you were already chasing.

So INSERT ... RETURNING under RLS is really an insert plus a read, and both gates must pass. This matters because return=representation is the default shape of most clients: PostgREST applies it when the request asks for it, and supabase-js .insert() without .select() still resolves the written row back in several call paths. The fix is not to touch the insert policy — it is to add a SELECT policy the new row satisfies.

Mode 14 is the quiet version: no RETURNING, no error, row stored, then a plain SELECT returns 0rows. If your dashboard shows “nothing saved” and no error, check for a SELECT policy before you check anything else.

Upserts need two more policies

An INSERT ... ON CONFLICT reads the table to detect the conflict before it writes. That read path needs a SELECT grant and a SELECT policy; the update branch needs an UPDATE policy as well.

#SetupMeasured signatureWhat it proves
15ON CONFLICT (id) DO UPDATE, insert-only policy, empty tablenew row violates ... for table "r7"No conflicting row exists, so nothing was updated — and it still fails. The conflict check itself needs a read path.
16ON CONFLICT (id) DO NOTHING, insert-only policy, empty tablenew row violates ... for table "r8"DO NOTHING is not a way around the read path either.
17ON CONFLICT (id) DO NOTHING, insert grant but no SELECT grantpermission denied for table r16The upsert needs SELECT privilege before policies matter. supabase-js .upsert() hits this first.
18DO NOTHING + insert policy + select policy, second insert conflictsINSERT 0 0 — RETURNING returns 0 rowsIt works now, and the conflict is silent: the row is still there, nothing was written, no error. This is the quiet data-loss shape.
19DO UPDATE + insert policy + select policy, no update policynew row violates row-level security policy (USING expression) for table "r14"A third message variant. The (USING expression) tag means the failing check was a read/update USING clause, not WITH CHECK.
20DO UPDATE + insert policy + update policy, no select policynew row violates ... for table "r15"The other half of the pair: an upsert needs BOTH a select policy and an update policy.
21DO UPDATE + insert + select + update policiesUPDATE applied — note column changedAll four policies present. The upsert finally does what it says.

Read mode 19 twice. new row violates row-level security policy (USING expression) is a different message from the plain variant, and the parenthetical is the whole diagnosis: the check that failed was a USING clause on a read/update path, not a WITH CHECK on your insert. If you see the tag, stop editing insert policies.

Sequences, owners, and bypass roles

#SetupMeasured signatureWhat it proves
22serial column, insert-only policy, no USAGE on the sequencepermission denied for sequence r10_id_seqThe table grant carried, the sequence grant did not. Sequences have their own ACL.
23Same serial column, id supplied explicitlyINSERT 0 1Supplying the id skips the sequence entirely — a quick bisect for sequence-vs-policy questions.
24Table owner INSERTs with only an INSERT policy TO authenticatedINSERT 0 1Owners bypass RLS by default. The policy never ran for this statement.
25Same owner after ALTER TABLE ... FORCE ROW LEVEL SECURITYnew row violates ... for table "s8b"FORCE RLS closes the owner bypass — and the owner now gets the same error as the app role.
26service_role (rolbypassrls = t, measured) INSERTs under a deny policyINSERT 0 1 — then permission denied on the follow-up SELECTBYPASSRLS skips policies, never ACLs. The insert lands; a SELECT without a grant still 42501s.

Modes 24 and 25 are the pair that makes “it works in the SQL editor” a worthless test. The editor runs as a superuser-like owner, relforcerowsecurity is off by default, and the policy set never applies. Mode 25 shows the same statement failing for the owner the moment FORCE ROW LEVEL SECURITY is on.

The 30-second diagnostic

Run these read-only as the project role. Each one is verified against a fixture table (orders) with deliberately asymmetric policies — insert-only, select granted, update not:

QueryWhat it tells youMeasured result
select polname, polcmd::text as cmd, case when 0 = any(polroles) then 'PUBLIC' else (select string_agg(r.rolname,',') from pg_roles r where r.oid = any(polroles)) end as applies_to, polpermissive::text as permissive, coalesce(pg_get_expr(polqual, polrelid),'-') as using_expr, coalesce(pg_get_expr(polwithcheck, polrelid),'-') as with_check_expr from pg_policy p where polrelid = 'public.orders'::regclass order by polname;Every policy on the table, parsedone row: orders_ins | a | authenticated | true | - | true — cmd a = INSERT only, WITH CHECK true, no USING
select c.cmd, count(p.polname) as policies from (values ('r'),('a'),('w'),('d'),('*')) as c(cmd) left join pg_policy p on p.polcmd::text = c.cmd and p.polrelid = 'public.orders'::regclass group by c.cmd order by c.cmd;Which commands have any policy at allr: 0, a: 1, w: 0, d: 0, *: 0 — the zeros are the RETURNING and upsert gaps
select has_table_privilege('authenticated','public.orders','INSERT') as can_insert, has_table_privilege('authenticated','public.orders','SELECT') as can_select, has_table_privilege('authenticated','public.orders','UPDATE') as can_update, has_sequence_privilege('authenticated','public.orders_id_seq','USAGE') as can_use_seq;The grant gate, per commandt | t | f | t on my fixture — insert and select open, update closed, sequence usable
select grantee, privilege_type from information_schema.role_table_grants where table_schema='public' and table_name='orders' order by grantee, privilege_type;Who actually holds whatauthenticated: INSERT, SELECT — and nothing else
select relrowsecurity, relforcerowsecurity from pg_class where relname = 'orders';Whether policies apply, and to the owner toot | f — policies on for app roles, still off for the owner

The second query is the one that finds the RETURNING and upsert failures in a single look: r: 0 and w: 0 against an a: 1 is the exact shape of a table where plain inserts work, .select() chains break, and .upsert() throws.

The fix, in gate order

  1. Separate the gates before editing policies. permission denied for table and permission denied for sequence are grant problems;new row violates is a policy problem; the (USING expression) tag is a read/update-policy problem. Three fixes, three places.
  2. Match the policy set to the commands you actually run. If the client reads the row back, the table needs a SELECT policy; if it upserts, it needs SELECT and UPDATE policies beside the INSERT one. Four statements, four command types.
  3. Check the role list. Empty polroles means PUBLIC; a named list excludes everyone else (mode 3). TO authenticated on a policy that anon calls is indistinguishable from no policy.
  4. Grant sequences separately — grant usage, select on all sequences in schema public to anon, authenticated; — and remember that alter default privileges is what keeps the next table from restarting at mode 7.
  5. Test as the app role. set local role authenticated; with request.jwt.claimsset reproduces the app path exactly; the SQL editor will not (modes 24–25).

Honest limits of these measurements

What this has to do with RLS reviews

Modes 1–13 are the missing-policy direction. The free drift monitor I publish checks the opposite direction — policies that exist but do not protect: owner bypass without FORCE, USING (true) on write commands, missing WITH CHECK on insert policies, SECURITY DEFINER functions without a pinned search_path. A table that passes every check in this article can still be wide open, and a table that fails one of them can still be perfectly safe to read. Both directions, nightly, against your own baseline.

The free drift monitor checks thirteen read-only catalogue conditions nightly and alerts only on changes from your own baseline. The $95 spot check is when you want a second pair of eyes on exactly these signatures before you touch production.

Prefer the verdict instead of running the toolkit yourself?

Fixed-price reviews with the evidence, the SQL and the written verdict. Fixes are quoted separately. Instant checkout, no account needed.

Want the free first step? The RLS Drift Monitor runs 13 read-only catalog checks on a schedule. It never reads application rows; zero findings is not proof of safety.

Prefer escrow? $49 drift monitor setup or $95 exposed-key triage on Upwork. Work starts only after the fixed-price milestone is funded.

Work starts only after payment is secured. Catalogue checks are read-only; no write credentials, no service_role key, no application rows.

Free entry

If you would rather run these checks yourself

Honest limit: a catalog check is not proof of a leak, and an empty log is not proof the key was never used. Zero findings does not mean safe. If you want a human: $29 self-run kit · $95 spot check (five tables, one working day) · $195 full audit — work starts only after payment is secured.

Template bundle

Review all 20 frontend starters in one bundle

20 editable frontend starters with live demos are $79 — one payment, no subscription.

View the Bundle — $79↗