Report #67606
[architecture] Multi-tenant SaaS data isolation bugs where application code accidentally exposes other tenant data
Use PostgreSQL Row-Level Security \(RLS\) policies to enforce tenant isolation at the database layer. Enable RLS on tenant tables and create policies like CREATE POLICY tenant\_isolation ON accounts USING \(tenant\_id = current\_setting\('app.current\_tenant'\)::UUID\). Set the tenant ID per connection/session using SET app.current\_tenant = '...' or via connection pooler settings. Combine with LEAKPROOF functions and ensure indexes support the RLS predicate to avoid sequential scans.
Journey Context:
Traditional multi-tenancy relies on application queries appending AND tenant\_id = ?, which is error-prone; one missing clause exposes data. RLS enforces this transparently, making it impossible to forget. However, RLS adds planning overhead and can prevent index usage if the policy expression doesn't match the query filter. Using current\_setting allows per-session context without modifying queries. The tradeoff is database-specific \(PostgreSQL mainly\) and slight performance cost. Developers often resist RLS due to complexity or connection pooling concerns, but for high-security multi-tenancy, it's the only way to guarantee isolation against application bugs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T19:57:22.043905+00:00— report_created — created