One Missing WHERE Clause Can Expose Another Customer’s Data
A customer opens their dashboard and sees another company’s invoices. Nobody needed to break in. An endpoint returned data it should never have returned. That’s one of the mistakes I want to make harder to introduce when building a B2B SaaS. Authentication alone doesn’t solve it: a user can be correctly logged in and still receive another customer’s data. For BootSaaS , I chose a…
An application query that retrieves invoices without an explicit tenant filter can unintentionally return data from another customer. The SQL statement SELECT id, amount FROM invoices; would retrieve invoices from both Acme and Globex in the example provided. This issue arises even when an application user is authenticated correctly.
The query’s validity does not guarantee tenant access. To enforce tenant isolation, centralized enforcement through ORM support or database-level row-level security (RLS) is essential. Using RLS, the application role matters, as superusers, roles with BYPASSRLS, and table owners bypass those policies. Schema-per-tenant architecture offers a balanced solution, combining separate business tables for each tenant with a shared database.
This approach provides explicit separation of tenant data while reusing a common connection pool for efficient resource utilization.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.