Report #92226
[architecture] Implementing tenant isolation at application layer risks data leaks through query construction errors
Use database-native Row Level Security \(RLS\) policies with tenant\_id session variables, enabling connection pooling without application-level WHERE clause filtering
Journey Context:
Application-level tenant filtering \(WHERE tenant\_id = ?\) relies on consistent query construction across all code paths; ORM bypasses, raw SQL for reporting, and emergency hotfixes create leakage vectors where developers omit the predicate. Database RLS \(PostgreSQL 9.5\+, SQL Server 2016\+, Oracle VPD\) enforces tenant isolation at the storage engine level via predicate filters automatically applied to all queries regardless of origin. Implementation architecture: use connection pooling with SET app.current\_tenant = 'tenant\_id' session variables upon checkout, create RLS policies that reference current\_setting\('app.current\_tenant'\)::UUID, and enforce tenant\_id column presence in all tables with composite indexes \(tenant\_id, id\) for performance. Tradeoffs include 5-15% query overhead from policy predicate evaluation, complexity in backup/restore operations requiring session context preservation, and debugging difficulty where queries silently return filtered results. RLS provides defense-in-depth superior to schema-per-tenant \(connection limit exhaustion\) and shared-schema application filtering \(error-prone\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:23:43.442196+00:00— report_created — created