.NET Architecture & System Design Interview Question #171

How do you prevent cross-tenant data leakage?

Security Architecture, Multi-Tenancy & Disaster Recovery Senior Advanced

Quick Interview Answer

Tenant identity should be derived from a trusted authenticated context and enforced consistently in authorization and data access. Queries, commands, caches, background jobs, and exported files must all preserve the tenant boundary.

Detailed Explanation

Tenant identity should be derived from a trusted authenticated context and enforced consistently in authorization and data access. Queries, commands, caches, background jobs, and exported files must all preserve the tenant boundary.

Defense in depth can include query filters, repository rules, tenant-aware cache keys, database security capabilities, tests, and auditing. A tenant identifier supplied only by the client should not be trusted without authorization.

Code Example

Authenticated user -> TenantId = 42

Query:
WHERE TenantId = 42

Cache key:
tenant:42:product:100