Start with two customers sharing an identifier
Suppose two enterprises both have an investigation numbered 1042. An analyst from one company changes a URL, replays an old export request, or switches workspaces while a background job is running. The system must preserve the customer boundary in every case. A dropdown showing the right company name cannot provide that guarantee; it is only a way to express the user's intended context.
A practical design treats tenant ownership as part of every resource relationship and operation. The server must establish which enterprise the caller can access, what action is permitted, and whether the requested record belongs to that enterprise. The same discipline must continue after the request leaves the page.
Derive authorized context on the server
Microsoft's claims-validation guidance identifies audience, tenant, subject and actor as authorization checks for APIs. Apply the appropriate signature, issuer, lifetime and claim validation before using identity information. Then map that verified identity to an explicitly provisioned SaaS membership. An email suffix, a submitted tenant ID or a successful login alone should not create administrator access to an enterprise.
For a user who legitimately belongs to multiple customers, tenant switching is a new authorization decision. Recheck current membership and role, create the appropriate server context, and invalidate or isolate stale work. OWASP recommends denying access by default and checking permissions on every request. Apply that to downloads and exports as carefully as to the visible investigations page.
Make the database enforce a second boundary
PostgreSQL row-level security can restrict which rows a role can read or modify. Its documentation also describes important bypasses: superusers and BYPASSRLS roles bypass policies, while owners normally do unless forced row security applies. Whole-table operations such as TRUNCATE are outside ordinary row-security filtering. These details make runtime role design part of the isolation control, not merely a deployment preference.
For this project, the intended database design combines tenant-scoped context, forced row-level security and composite relationships that include tenant ownership. A device in one company should not be attachable to another company's event even if an application bug supplies a valid device identifier. Migration administration and everyday application access need separate privileges, with connection-pool behavior tested under real workload roles.
Follow the boundary outside SQL
An export job is a useful threat-model exercise. The request is authorized when queued, but the user may be removed before the file is downloaded. The worker needs trusted tenant context, the generated object needs tenant ownership, and the download needs a fresh authorization decision. A long-lived URL should not become a shortcut around revoked membership.
Repeat that exercise for caches, search indexes, queued retries, email notifications and support tooling. A cache key needs the relevant tenant and authorization dimensions. A retry must not accept a tenant override from its payload. Support access needs an explicit, time-bounded reason and an audit trail. Design these paths before adding them, because an isolated primary table cannot compensate for an unscoped downstream copy.
Test the operations that must fail
Build fixtures with deliberate identifier collisions across two controlled tenants. Exercise the real API and database connection pool, including transactions that fail, time out or are canceled. After every failure, confirm that the next request cannot inherit the previous tenant's context. A passing happy-path query says little about these failure modes.
Also test changes over time. Revoke membership during a queued export, suspend a tenant, rotate signing keys and remove a connector's consent. The expected result should be a safe denial or a clearly reported unavailable operation, never a fallback to another tenant's data. Preserve evidence of the actual runtime version, permissions and test environment so reviewers know what was exercised.
- Guess, replace or reuse a record identifier from the other tenant.
- Attempt cross-tenant relationships, writes, exports and cached reads.
- Confirm that runtime roles cannot disable isolation or rewrite audit history.
- Repeat with concurrent pooled connections and revoked authorization.
The current implementation boundary
AI Tool Tracking has server-side identity and PostgreSQL isolation foundations with automated tests, but they are not mounted as a live customer service. The public app is a browser-local preview. Its fictional enterprise switcher and separate local state help demonstrate workflows; they are not authenticated tenant isolation. Native production-environment verification, secure sessions, downstream controls and independent security assessment remain activation requirements.