Multi-Tenant Isolation
Follow a Green workspace member asking for Blue’s data, then preserve the verified workspace through queries, jobs, and downloads.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
Mia belongs to the Green workspace. She changes a request's companyId from Green to Blue. The request still carries her genuine signed-in identity. Should the server return Blue's employees?
No: selecting a workspace is not proof of membership. A tenant is the customer or workspace whose data must stay separate from other customers' data.
We'll first follow the workspace ID into one employee query. Then we'll carry the same permission through lists, pages of results, caches, export jobs, and downloads. Each handoff must preserve what the server verified.
Distinguish selection from authority
Single-tenant accounts may derive their scope directly from verified identity. Multi-workspace accounts may let a user select among several current memberships. Both designs require an explicit server decision before the selected tenant reaches data access. A signed claim is useful only if the verifier checks issuer, audience, lifetime, and current policy as required by the product.
// Unsafe under the stated company-membership policy.
const actor = verifyAccessToken(request);
const companyId = request.query.companyId;
return employees.findMany({ where: { companyId } });
The query has a tenant filter, but it is the wrong authority source. Pagination, search filters, DTO validation, and a valid signature elsewhere do not bind that selected company to the actor. Review the provenance of each scope value, not merely whether a property named tenantId appears.
Follow the same workspace through service and storage.
Select. The request chooses a workspace but grants no membership.
const selected = parseWorkspaceId(body.workspaceId);
Resolve. The server resolves actor, workspace, and action against current policy.
const scope = await resolveWorkspace(actor, selected, "employees.read");
Use. Every query, job, and output lookup preserves the authorized workspace.
SELECT id, display_name
FROM employees
WHERE company_id = :authorized_company;
Review question: A predicate named companyId is useful only when its value has the correct authority source.