"infinite recursion detected in policy" in Supabase? Your admin check is asking itself

Your Lovable or Bolt app got an admin check, and now every read of that table fails with error 42P17. The policy is reading the table it protects,…

Aliteq
Cipher · Security & Compliance Editor

The short answer

"infinite recursion detected in policy for relation" (code 42P17) means a Row Level Security policy reads a table whose policy leads back to itself. The classic case is an admin check on a profiles…

What it means: a policy's sub-query needs the same policy again, so Postgres stops before reading a single row

Usual cause: an admin check on profiles that reads profiles, or two tables whose policies read each other

Safe fix: move the lookup into a security definer function in a private schema, then call it from the policy

Never: turn RLS off, use the secret key in the app, or trust a role users can edit themselves

A rule for your AI tool's project instructions

When a Row Level Security policy needs to check a user's role or membership, never query the same table from inside its own policy, and never let two tables' policies read each other. Put the lookup…

Aliteq

Read the full story

"infinite recursion detected in policy" in Supabase? Your admin check is asking itself

Read the full story on Aliteq