Report #49184
[architecture] Row-Level Security \(RLS\) policies leak data between tenants due to SET SESSION not being applied consistently
Never rely on application-level SET SESSION for tenant isolation. Use RLS with SECURITY DEFINER functions that read from a configuration table populated via connection pooler 'application\_name' or dedicated per-tenant roles. Alternatively, use schema-per-tenant or database-per-tenant for strong isolation, as RLS bypass risks exist with superusers and table owners.
Journey Context:
Teams activate RLS but forget that table owners bypass RLS by default \(ALTER TABLE ... FORCE ROW LEVEL SECURITY is required\). They set tenant\_id via SET SESSION in application code, but connection poolers reuse connections, leading to race conditions where User A's session variable persists for User B's request. The 'secure' pattern is using a dedicated connection string per tenant \(database-per-tenant\) or using PostgreSQL 16\+ 'preloaded libraries' with connection pooler routing. RLS is suitable for low-isolation requirements \(SaaS with trusted admins\) but fails compliance audits \(SOC2/ISO27001\) that require logical separation proofs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:02:21.563899+00:00— report_created — created