Fix "new row violates row-level security policy for table" (Supabase)
Updated · Applies to: Supabase, Lovable, Bolt, v0, Cursor, Replit
TL;DR fix: Row Level Security is on, but no policy allows this write for the role making the request. Add an INSERT policy with a WITH CHECK clause (for example (select auth.uid()) = user_id), make sure the insert actually sets user_id to the signed-in user, and add a SELECT policy if your code chains .select() after the insert. Never "fix" it by disabling RLS.
Steps
- Read the table name in the error. The message names the table, e.g. new row violates row-level security policy for table "messages". That is the table that needs a policy.
- Check which policies exist for that table. In the Supabase dashboard open Authentication → Policies (or the table in Table Editor) and look for a policy covering the operation that failed: INSERT, UPDATE, or SELECT.
- Add a policy with WITH CHECK for inserts. INSERT policies are written with a WITH CHECK expression. UPDATE policies need USING (which rows) and WITH CHECK (what the new row may look like).
- Make sure the row passes the check. If the policy compares auth.uid() to user_id, the insert must set user_id to the signed-in user's id, or the column needs default auth.uid(). The user must actually be logged in, otherwise the request runs as anon.
- Add a SELECT policy if you use insert().select(). supabase-js .insert().select() reads the new row back. Without a SELECT policy that allows it, the call fails with the same 42501 error.
- Retest as a real user. Log in as a normal user in the app (not the SQL editor, which bypasses RLS) and retry the action.
The fix in SQL
Run this in the Supabase SQL editor. Replace messages and user_id with your table and owner column:
-- Make sure RLS is on (it should be)
alter table public.messages enable row level security;
-- Let signed-in users insert rows they own
create policy "users insert own rows"
on public.messages for insert
to authenticated
with check ((select auth.uid()) = user_id);
-- Let them read their own rows (needed for .insert().select())
create policy "users read own rows"
on public.messages for select
to authenticated
using ((select auth.uid()) = user_id);
-- Optional: fill user_id automatically so the frontend can't get it wrong
alter table public.messages alter column user_id set default auth.uid();
Supabase’s docs describe the insert case directly: “The with check expression ensures that any new row adheres to the policy constraints, so a user cannot create a row that belongs to someone else.”
Why AI-built apps hit this so often
App builders usually create the table, turn on RLS, and wire up the form in separate steps. When the policy step is skipped or written only for SELECT, every save fails. The dangerous “fix” an AI tool may suggest is disable row level security or with check (true), which makes the error disappear by letting anyone write to your table.
Prompt for Cursor, Lovable or Bolt
Inserts into public.<table> fail with "new row violates row-level security policy".
Do NOT disable RLS and do NOT use USING (true) / WITH CHECK (true).
Add an INSERT policy for authenticated with WITH CHECK ((select auth.uid()) = user_id),
a matching SELECT policy, and set user_id default auth.uid(). Show me the SQL first.
Getting permission denied for table (also 42501) on a table you just created instead? That’s a missing GRANT, not a policy: see Fix Supabase “permission denied for table” on new tables after Oct 30, 2026.
If an AI tool “fixed” writes with USING (true) / WITH CHECK (true), that opens the table: Fix RLS USING (true) publicly readable.
App says “saved” but no row appears, or a Stripe webhook returns 200 without writing? See Form says success but no row in Supabase.
Related: Supabase’s October 30, 2026 change and “permission denied for table” · Check RLS in two minutes.
When to get help
Get help if the policy needs to depend on teams, roles or joins between tables, if your AI tool keeps "fixing" this by disabling RLS or using USING (true), or if you're not sure which tables are currently readable by anyone with your public key.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
FAQ
What does "new row violates row-level security policy" mean?
It means Row Level Security is enabled on the table and no policy allows the current role (anon or authenticated) to write that row. Postgres returns error code 42501 and the Supabase API returns HTTP 403. The fix is to add or correct an INSERT or UPDATE policy with a WITH CHECK clause, not to disable RLS.
Why does the same insert work in the Supabase SQL editor?
The SQL editor runs as a privileged database role that bypasses Row Level Security. Your app runs as anon or authenticated, so policies apply. Always test policies through the app or by impersonating a user.
Should I just disable RLS to make the error go away?
No. With RLS disabled, anyone with your public anon or publishable key can read and change that table. That is the misconfiguration behind CVE-2025-48757 in Lovable apps. Write the missing policy instead.
Is this the same as "permission denied for table"?
No. "permission denied for table" (also 42501) means the role has no GRANT on the table at all, which is common for new tables after Supabase's October 30, 2026 change. "new row violates row-level security policy" means the grant exists but an RLS policy blocked the row.
Sources
- Supabase docs: Row Level Security
- Supabase troubleshooting: Database API 42501 errors
- Matt Palmer: statement on CVE-2025-48757
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)