Repository navigation
Closed
Labels
Description
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the [Docs](https://docs.supabase.com), GitHub [Discussions](https://github.com/supabase/supabase/discussions), and [Discord](https://discord.supabase.com).
Describe the bug
A PERMISSIVE RLS INSERT policy with WITH CHECK (true) applied TO PUBLIC (all roles) is still blocking INSERT operations for the anon role, returning error 42501: new row violates row-level security policy for table "orders".
The policy is correctly visible in pg_policies and all necessary GRANTs are in place. The same INSERT succeeds when RLS is disabled, and also succeeds when running SET ROLE anon directly in the SQL Editor — meaning the issue is specific to requests coming through the PostgREST API with an anon JWT.
To Reproduce
- Create a table with RLS enabled:
CREATE TABLE public.orders (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
restaurant_id uuid NOT NULL,
customer_email text NOT NULL,
total_price numeric NOT NULL
);
ALTER TABLE public.orders ENABLE ROW LEVEL SECURITY;- Create a fully permissive INSERT policy for all roles:
CREATE POLICY "allow all insert"
ON public.orders
AS PERMISSIVE
FOR INSERT
TO PUBLIC
WITH CHECK (true);- Grant INSERT to anon:
GRANT INSERT ON public.orders TO anon;
GRANT USAGE ON SCHEMA public TO anon;- Send a POST request via the PostgREST API using the anon JWT:
fetch('https://YOUR_PROJECT.supabase.co/rest/v1/orders', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': 'ANON_KEY',
'Authorization': 'Bearer ANON_KEY',
'Prefer': 'return=representation'
},
body: JSON.stringify({
restaurant_id: 'VALID_UUID',
customer_email: '[email protected]',
total_price: 10.00
})
})- Receive
42501: new row violates row-level security policy for table "orders"
Expected behavior
The INSERT should succeed since the policy is TO PUBLIC WITH CHECK (true), which should allow any role including anon to insert any row.
Additional context
- Running
SET ROLE anonin the SQL Editor and performing the same INSERT succeeds without error — confirming the policy is correctly defined at the database level. - Disabling RLS (
ALTER TABLE orders DISABLE ROW LEVEL SECURITY) makes the API request succeed. - The
debug_current_role()function called via RPC from the browser returnsanon, confirming the correct role is being used. - The anon JWT decodes correctly with
"role": "anon". - All policies are
PERMISSIVE, none areRESTRICTIVE. - GRANTs are confirmed via
information_schema.role_table_grants. - Workaround used: moved the INSERT to a Supabase Edge Function using the
service_rolekey.
System information
- OS: windows
- Browser: Chrome
- Version of supabase-js: 2.x
- PostgreSQL: 17.6 on aarch64-unknown-linux-gnu
Activity
GaryAustin1 commentedon Mar 9, 2026
You are asking for it to return data in your REST call so you also need to meet select RLS.
Hallidayo commentedon Apr 11, 2026
Hi all, We’re going to close this one due to inactivity. Please feel free to reopen if you’re still having issues here or open a new issue.