Report #24734
[architecture] Data leakage between tenants due to missing WHERE clauses in multi-tenant shared-schema designs
Enforce tenant isolation using database-native Row-Level Security \(RLS\) policies that automatically filter by tenant\_id based on connection context, rather than application-level filtering
Journey Context:
Shared-schema multi-tenancy \(single database, tenant\_id column\) relies on developers adding 'AND tenant\_id = ?' to every query. One missing clause exposes data. RLS uses CREATE POLICY to enforce filters at the database level transparently. Implementation: Set tenant context via SET app.current\_tenant = 'id' on connection; policies reference current\_setting\('app.current\_tenant'\). Queries look clean but return filtered results. Tradeoffs: Performance overhead \(extra filter per row\), complex policies can confuse query planner causing seq scans, connection pooling requires strict context resetting \(SET app.current\_tenant = '' on return to pool\) to prevent leakage between requests. Debugging is opaque \(queries look simple but fail mysteriously\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:55:34.437595+00:00— report_created — created