{"success":true,"name":"isolate-tenants-one-customer-must-never-see-another-s-data","description":"Building an app where multiple companies or teams share one database","category":"ai-brimind","path":"ai-brimind/isolate-tenants-one-customer-must-never-see-another-s-data/SKILL.md","file":"SKILL.md","content":"---\nname: isolate-tenants-one-customer-must-never-see-another-s-data\ndescription: \"Building an app where multiple companies or teams share one database\"\n---\n\n# Isolate Tenants: One Customer Must Never See Another's Data\n\n## When to use\nThe platform serves multiple organizations/workspaces whose data lives in shared tables, and you are writing queries or designing the schema.\n\n## Example request\nA query filters by projectId only → any user who guesses another project's ID reads a stranger company's data; every query must also filter by the tenant from the session (tenant scoping). Tenant filtering repeated by hand in every query → one forgotten WHERE clause becomes a cross-company leak; centralize scoping in a base query layer or database policy (defense in depth). Tenant ID accepted from the request body → clients can claim any tenant they like; tenant identity derives from the authenticated session only (server-derived tenant). Reports and exports built with raw queries bypass the usual layer → the 'special' code paths are where leaks happen; they need the same scoping as everything else (no unscoped paths).\n\n## Instructions\nAct like an architect for whom one cross-tenant leak equals losing every customer's trust at once — because in B2B reality, it does. Establish a single rule: the tenant identifier comes from the authenticated session or verified token, never from anything the client sends, and every read and write on shared tables is scoped by it. Do not rely on developers remembering the filter: centralize enforcement in one mechanism — a repository/base-query layer that always injects the tenant condition, an ORM global scope, or database-level row security where the platform supports it — so an ordinary mistake cannot produce a leak. Audit the paths that usually escape the rule: raw queries, admin dashboards, exports, reports, background jobs, and search indexes must all pass through the same scoping. Design IDs so guessing them grants nothing, because scoping — not obscurity — is the protection. Test adversarially: with a tenant-A session, request tenant-B's IDs across list, detail, update, and export endpoints, and expect uniform denial. Only proceed once scoping is enforced in one central place with no unscoped paths remaining, and explain how the design survives a forgetful developer rather than depending on one.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #549\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}