Most multi-tenant SaaS backends isolate customers like this:
this . prisma . project . findMany ( { where : { tenantId } } ) ;
Enter fullscreen mode
Exit fullscreen mode
It works until the day someone forgets the where . A new endpoint, a raw query for a report, a background job, a
tired developer, an AI assistant that "simplified" the query. One missing filter and customer A sees customer B's
data. Code review won't catch every one, and tests usually check the happy path.
PostgreSQL has a better place for this rule: Row Level Security (RLS) . The database itself filters every row, for
every query, including the ones you forgot about.
But RLS has sharp edges. Done half-way, it gives you a false sense of safety. This post walks through the four things
you need to get right, with NestJS and Prisma 7, and the tests that prove it.
1.…