Skip to main content
Industry

Multi-tenant isolation: technical guide for SaaS vendors

Multi-tenant security challenges. Cross-tenant data leaks, isolation strategies, and how to test your architecture's watertightness.

In a multi-tenant SaaS application, several customers use the same platform while their data remains separate. The central business risk is simple: one customer must never be able to view or change another customer’s information. This guide covers the main control points and a testing method based on two fictional workspaces.

Multi-tenant isolation models

There are several multi-tenant isolation models, each with its advantages and security risks. The choice of model directly impacts the isolation level, implementation complexity, and operational cost.

Shared database with column-based discrimination

Schema per tenant

Each tenant has its own schema within the same database. The application determines which schema to use based on the connected tenant. This model offers better isolation than the tenant_id column because data is physically separated at the schema level. However, risks persist: poor database connection management can lead to using the wrong schema, and cross-schema features (searches, aggregated reports) can create leak points.

Database per tenant

Each tenant has its own database. This is the most isolated model but also the most expensive to operate. Isolation is strong because data is physically separated. Residual risks are related to connection management (connection pooling, configuration), cross-tenant reporting features at the application level, and shared components (cache, message queue, file storage) that can create communication channels between tenants.

The most common cross-tenant vulnerabilities

Leaks via database queries

In the tenant_id column model, forgetting the filter is the most frequent cause of cross-tenant leaks. This typically happens in new features where the developer forgets to add the filter, in complex queries with joins where the filter is present on the main table but not on joined tables, in administration endpoints where the filter is intentionally omitted for admins but the admin role check is flawed, and in misconfigured ORMs where default scopes are not applied. A framework like CASL (authorization library) can help systematize authorization filters, but it doesn't cover all cases and must be correctly configured.

Leaks via cache

Shared cache systems (Redis, Memcached) are a frequent source of cross-tenant leaks. If cache keys don't include the tenant_id, a tenant may receive cached data from another tenant. Example: the cache contains the result of the query "list of invoices for user X." If the cache key is "invoices:user:123" instead of "invoices:tenant:A:user:123," the same user ID on another tenant could receive invoices from the wrong tenant.

Leaks via file storage

Files uploaded by tenants (documents, images, exports) are often stored in a shared bucket (S3, Azure Blob). If file paths are predictable or if file-level access controls don't account for the tenant, a tenant can access another tenant's files. Signed URLs (pre-signed URLs) must include tenant verification at generation time, not just at upload time.

Leaks via message queues and events

In event-driven architectures, messages in queues (RabbitMQ, SQS, Kafka) can contain data from different tenants. If consumers don't verify the tenant of the message, they may process one tenant's data on behalf of another. Shared topics or queues without tenant filtering are an often-forgotten leak vector.

Leaks via webhooks and integrations

Outgoing webhooks (notifications to tenant systems) must include only the data of the recipient tenant. A webhook routing error can send one tenant's data to another tenant's system. Similarly, integrations with third-party services (CRM, ERP) must verify that the exchanged data belongs to the tenant configured for that integration.

Prevention strategies

Cross-tenant leak prevention relies on several complementary defense layers.

Tenant middleware

A centralized middleware that extracts the tenant_id from the request context (JWT token, header, subdomain) and propagates it to all application layers is essential. This middleware must be applied to all endpoints without exception. The tenant_id must never be taken directly from request data (body, query params) but always from the verified authentication context.

Automated isolation tests

How to test multi-tenant isolation

The testing methodology includes several phases. First, create at least two accounts on different tenants with identifiable data (names, descriptions that make it easy to determine which tenant data belongs to). Second, map all accessible endpoints and identify those that handle resource identifiers. Third, for each endpoint, attempt to access tenant A's resources with tenant B's session, using tenant A's resource identifiers. Fourth, also verify secondary channels: cache, files, exports, webhooks, search and listing endpoints.

Multi-tenant and compliance

Dated evidence of tenant isolation can help answer a customer’s or auditor’s security questions. It should state the roles, journeys and layers tested without claiming absolute isolation across the whole architecture.

Architectural best practices

Several measures strengthen isolation: database-level rules, centralised tenant context, unambiguous cache keys, granular storage policies and logging of the relevant tenant. Rerun isolation scenarios after changes that affect these controls.

Frequently asked questions

Is Row-Level Security sufficient to guarantee isolation?

No. RLS covers the database layer, not caches, file storage, message queues or integrations. It should be combined with application-level controls and tests that follow data across the relevant layers.

How to detect cross-tenant leaks in production?

Implement cross-tenant access monitoring: each resource access should be logged with the user's tenant_id and the resource's tenant_id. An alert should trigger if these two values differ. This monitoring detects leaks in production, but prevention through testing is always preferable to detection.

Do microservices make isolation harder?

They create more boundaries where tenant context must be passed and verified. A gateway can centralise part of the control, but each service must still reject missing, inconsistent or unauthorised context.

Jordan Fredj, Founder of Hacksessible -

Sources and reading method


Try on your scope