Skip to content

RLS INSERT policy for anon role rejected by PostgREST despite correct policy configuration #48302

Open

Description

@AMARealone

The REST API systematically returns a 42501 RLS violation error on INSERT to a table
where all prerequisites are verified correct:

  • Policy exists, PERMISSIVE, command=INSERT, roles={anon}, with_check=true
  • GRANT INSERT exists for anon on the table (confirmed via information_schema.table_privileges)
  • RLS is enabled normally (relrowsecurity=true, relforcerowsecurity=false)
  • anon role has rolbypassrls=false, rolsuper=false, rolinherit=true (normal, non-superuser role)
  • A direct SQL test via SET ROLE anon; INSERT INTO ...; succeeds without any error
  • The same INSERT via the REST API (same payload, same columns) fails with 42501
  • Ran NOTIFY pgrst, 'reload schema'; — no change
  • Performed a full project restart (Settings > Restart project) — no change, error persists identically

This strongly suggests a PostgREST-level issue (JWT role mapping, internal cache, or
similar) rather than a database/RLS configuration problem, since Postgres itself accepts
the exact same operation when tested directly.

Table: prospects
Policy: prospector_insert (INSERT, anon, WITH CHECK true)
Project ref: mifljhsusidgzelnswma

  1. Go to '…'
  2. Click on '…'
  3. Scroll down to '…'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

Add any other context about the problem here.

Activity

  1. added
    bug
    on Jul 24, 2026
  2. added
    external-issue
    on Jul 24, 2026
  3. coderabbitai commented on Jul 24, 2026

    @coderabbitai
    Contributor
    ⚠️ Possible Duplicate Issue(s)

    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  4. rohanpatel2002 commented on Jul 24, 2026

    @rohanpatel2002

    Triage

    This looks like expected PostgREST / RLS behavior rather than a misconfigured INSERT policy or a PostgREST bug.

    When the REST client asks for the inserted row back (Prefer: return=representation, or supabase-js .insert(...).select()), PostgREST runs INSERT … RETURNING *. Postgres then also evaluates SELECT RLS on the new row. An INSERT policy with WITH CHECK (true) plus GRANT INSERT is enough for a plain SQL insert, which is why this succeeds:

    set role anon;
    insert into prospects …;  -- no RETURNING
  5. added
    documentation
    pr-opened
    and removed on Jul 26, 2026
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

    bugdocumentationexternal-issuepr-opened

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions