Prompt
How do I stop one tenant from seeing another tenant's data?
Latest observation
Oct 23, 2026
OpenAI APIWeb search: off
To keep one tenant from seeing another tenant’s data, you need strong tenant isolation at every layer where data can be accessed.
Core approach
-
Attach a tenant ID to every tenant-owned record
- Every row/document/object should include
tenant_id(or equivalent). - Never trust the client to provide it without validation.
- Every row/document/object should include
-
Enforce tenant scoping in all queries
- Always filter by the authenticated user’s tenant.
- Example:
WHERE tenant_id = current_tenant_id - Avoid “load by ID” queries that don’t also check tenant.
-
Authenticate and authorize correctly
- Authentication: who is the user?
- Authorization: what tenant(s) can they access?
- Put tenant claims in the session/JWT, but verify them server-side.
-
Use database-level isolation when possible
- Strongest options:
- Separate database per tenant
- Separate schema per tenant
- Row-level security (RLS)
- RLS is especially effective because it reduces the chance of application bugs leaking data.
- Strongest options:
-
Isolate files/blobs/object storage
- Include tenant prefixes in object paths.
- Enforce access checks before generating download URLs.
- Don’t expose raw bucket paths publicly.
-
Cache safely
- Include tenant ID in cache keys.
- Never reuse cached results across tenants.
-
Prevent cross-tenant access in APIs
- Every endpoint must verify the requested resource belongs to the caller’s tenant.
- Don’t rely on obscurity of IDs.
-
Audit and test for leakage
- Add automated tests for cross-tenant access attempts.
- Log access with tenant context.
- Periodically review for missing tenant filters.
Best-practice options by strength
- Best isolation: separate database per tenant
- Good compromise: shared DB + row-level security
- Common SaaS pattern: shared DB + tenant_id everywhere + strict query enforcement
Common mistakes
- Forgetting tenant filters on a single endpoint
- Using global admin-style lookups by ID
- Putting tenant checks only in the UI
- Reusing cache entries across tenants
- Storing tenant ID in the client and trusting it blindly
If you want, I can help you design this for your specific stack, such as:
- PostgreSQL + RLS
- Django
- Node/Express
- Rails
- .NET
- MongoDB