Skip to content

RLS INSERT policy WITH CHECK (true) TO PUBLIC blocks anon role via PostgREST API despite succeeding with SET ROLE anon in SQL Editor #43528

Closed

Description

@Alexandre91300

Bug report

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

  1. 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;
  1. 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);
  1. Grant INSERT to anon:
GRANT INSERT ON public.orders TO anon;
GRANT USAGE ON SCHEMA public TO anon;
  1. 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
  })
})
  1. 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 anon in 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 returns anon, confirming the correct role is being used.
  • The anon JWT decodes correctly with "role": "anon".
  • All policies are PERMISSIVE, none are RESTRICTIVE.
  • GRANTs are confirmed via information_schema.role_table_grants.
  • Workaround used: moved the INSERT to a Supabase Edge Function using the service_role key.

System information

  • OS: windows
  • Browser: Chrome
  • Version of supabase-js: 2.x
  • PostgreSQL: 17.6 on aarch64-unknown-linux-gnu

Activity

  1. added
    bug
    on Mar 8, 2026
  2. added
    external-issue
    on Mar 8, 2026
  3. GaryAustin1 commented on Mar 9, 2026

    @GaryAustin1
    Collaborator

    You are asking for it to return data in your REST call so you also need to meet select RLS.

  4. Hallidayo commented on Apr 11, 2026

    @Hallidayo
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugexternal-issueto-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions