Prompt
What are the most common security mistakes in multi-tenant SaaS apps and how do I avoid them?
Latest observation
The biggest security risk in multi-tenant SaaS is tenant isolation failure: one customer can see or modify another customer’s data. Most other mistakes are variations of that.
Here are the most common mistakes and how to avoid them:
1) Relying only on the UI for access control
Mistake: Hiding buttons or pages in the frontend and assuming users can’t reach data they shouldn’t.
Fix: Enforce authorization on the server for every request, every time.
- Check tenant membership in APIs
- Never trust client-side IDs or tenant IDs
- Deny by default
2) Missing tenant filters in database queries
Mistake: Forgetting tenant_id = ? in one query, or using the wrong tenant context.
Fix: Make tenant scoping automatic.
- Add tenant filters in a shared data access layer
- Prefer query helpers/ORM scopes that require tenant context
- Use database constraints and row-level security where possible
3) Using weak or predictable object identifiers
Mistake: Sequential IDs like /invoices/12345 make enumeration easy.
Fix: Use indirect references plus authorization.
- Use UUIDs or random IDs
- Still verify access on the server
- Don’t treat “hard to guess” as security
4) Broken role/permission models
Mistake: Roles are too broad, inconsistent, or checked only in some places.
Fix: Design a clear authorization model.
- Define tenant roles and resource-level permissions
- Centralize authorization logic
- Test edge cases like admin, member, billing-only, support staff
5) Storing tenant context in insecure session state
Mistake: Trusting a session or JWT claim without validation, or allowing users to switch tenants without proper checks.
Fix: Treat tenant context as sensitive state.
- Verify tenant membership server-side on every switch
- Keep tokens short-lived
- Re-check permissions when tenant context changes
6) No separation between tenants in storage or encryption
Mistake: Sharing buckets, tables, queues, or encryption keys without clear boundaries.
Fix: Separate and scope infrastructure carefully.
- Tag all records with tenant ID
- Partition data where needed
- Consider per-tenant keys for sensitive data
- Restrict access to background jobs and service accounts
7) Logging or exposing sensitive cross-tenant data
Mistake: Logs, traces, analytics, or error messages reveal other tenants’ data.
Fix: Minimize and sanitize telemetry.
- Redact PII and secrets
- Avoid logging full request bodies or tokens
- Ensure support tools are tenant-aware
- Segment observability access by tenant
8) Insecure support/admin backdoors
Mistake: Internal staff can impersonate users or access all tenants without audit trails.
Fix: Build controlled support access.
- Require approval or just-in-time access
- Record every impersonation/admin action
- Limit blast radius with scoped tools
9) Vulnerable background jobs and async processing
Mistake: Jobs run later with lost tenant context, causing cross-tenant data access.
Fix: Include tenant ID in job payloads and validate it.
- Rehydrate authorization from authoritative data
- Don’t rely on ambient/global tenant state
- Isolate queues or workers if needed
10) Cross-tenant cache poisoning or leakage
Mistake: Cache keys don’t include tenant ID, so one tenant sees another’s cached data.
Fix: Scope cache keys and invalidate safely.
- Prefix every cache key with tenant ID
- Be careful with shared CDN content
- Avoid caching personalized responses without proper variance
11) Overly permissive service-to-service access
Mistake: Internal services can access all tenants because “it’s internal.”
Fix: Apply zero-trust principles internally.
- Use least privilege for service accounts
- Authenticate and authorize service calls
- Scope access by tenant and operation
12) Weak testing for tenant isolation
Mistake: Testing only happy paths within one tenant.
Fix: Test isolation explicitly.
- Write tests for unauthorized cross-tenant access
- Add property-based or fuzz tests for ID substitution
- Include security tests in CI
- Run regular penetration tests focused on isolation
Practical design rules
If you want a simple checklist:
- Every data access must be tenant-scoped
- Authorize on the server, not the client
- Assume any ID can be tampered with
- Make tenant context explicit in code
- Scope caches, jobs, logs, and keys by tenant
- Test cross-tenant access as a first-class requirement
- Audit all privileged support/admin actions
Good architectural patterns
Common approaches that help:
- Row-level security (RLS): Strong protection for shared databases
- Tenant-aware repositories/services: Require tenant context in code paths
- Separate schemas or databases for high-risk tenants: Better isolation at higher cost
- Scoped encryption: Reduce impact if data stores are exposed
A quick rule of thumb
If a feature works only because “the frontend won’t let them,” it’s probably insecure.
If you want, I can also give you:
- a tenant-isolation security checklist,
- a reference architecture for shared-db SaaS, or
- a threat model template for multi-tenant apps.