For policies on the same role and command, Postgres combines permissive policies with OR.
Adding a second permissive ownership policy does not narrow an existing USING (true) policy; only an AS RESTRICTIVE policy does.
Usually the cleaner fix is to drop or rewrite the broad policy. A restrictive policy also works, but it only narrows access: at least one permissive policy still has to grant access.
Start by checking what is actually installed:
select schemaname, tablename, policyname, permissive,
roles, cmd, qual, with_check
from pg_policies
where schemaname = 'public';
Then test with two real user sessions and one unauthenticated request. The SQL editor usually runs with privileges that bypass RLS, so an administrator query is not proof of user isolation.
I wrote a free read-only script that flags this pattern and 17 others. It reads database metadata, not application rows, and changes nothing. Its findings are leads to verify, not a security certification: https://rowproof.pages.dev/download.html
Disclosure: the script is part of RowProof, where I also offer paid written security reviews.
PostgreSQL documentation on how policies combine: https://www.postgresql.org/docs/current/sql-createpolicy.html
The user discusses a common issue with PostgreSQL's Row-Level Security (RLS) policies, where permissive policies are combined with OR logic. They suggest solutions such as rewriting broad policies or using restrictive policies to narrow access. The user also shares a script for identifying problematic patterns in RLS configurations and provides links to PostgreSQL documentation and related tools.
User needs: explanation of Realtime and RLS interaction
User needs: understanding of RLS behavior on delete operations
Good write-up, the OR between permissive policies trips up a lot of people. I'd add views to the audit: a view without security_invoker runs as its owner and skips RLS entirely, so list those next to pg_policies. After fixing, retest from a fresh client that holds only the anon key. I built Rowly for the last step, an anonymous pass over a published app's data rules, endpoints and storage buckets: https://rowly.me
[ Removed by Reddit ]