Report #92470
[architecture] Multi-tenant data leaks across tenants with shared schema due to missing isolation
Use PostgreSQL Row-Level Security \(RLS\) policies with tenant\_id checks, set tenant context via application\_name or current\_setting, and never rely solely on WHERE clauses in application code
Journey Context:
The standard approach to multi-tenancy in shared PostgreSQL schemas is adding tenant\_id to every table and filtering in the app \(WHERE tenant\_id = current\_tenant\). This is error-prone: missing one WHERE clause in a complex query leaks data. The robust solution is PostgreSQL's RLS: create policies like CREATE POLICY tenant\_isolation ON table USING \(tenant\_id = current\_setting\('app.current\_tenant'\)::int\);. The application sets the tenant ID per connection/session using SET app.current\_tenant = '123'. Now the database enforces isolation at the row level, making it impossible to forget a filter. Critical: use separate connections per request or reset the setting, never allow connection reuse across tenants without clearing the context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:48:09.934067+00:00— report_created — created