Objective: Implement a "Strict Isolation Layer." Every database query and service call must be forced through a Tenant Resolver that prevents "ID-guessing" and ensures data from Workspace A never leaks into Workspace B. This requires refactoring the entire query pipeline.
Files involved (12):
models/TenantConfig.js (New: Stores workspace-specific constraints)
middleware/tenantResolver.js (New: Injects tenant context into every request)
utils/queryScoper.js (New: Intercepts Mongoose queries to inject workspaceId)
services/workspaceService.js
(Update: Logic for cross-workspace moves)
middleware/leakageGuard.js (New: Validates response data doesn't contain foreign IDs)
routes/workspaces.js
(Update: Access control overhaul)
models/Transaction.js
(Update: Indexing for tenant isolation)
models/User.js
(Update: Workspace role maps)
services/authService.js (Update: Tenant-aware token generation)
routes/admin.js (New: Global tenant monitoring)
tests/tenantIsolation.test.js (New: Data leakage tests)
TENANT_SECURITY_SPEC.md (Technical spec)
Objective: Implement a "Strict Isolation Layer." Every database query and service call must be forced through a Tenant Resolver that prevents "ID-guessing" and ensures data from Workspace A never leaks into Workspace B. This requires refactoring the entire query pipeline.
Files involved (12):
models/TenantConfig.js (New: Stores workspace-specific constraints)
middleware/tenantResolver.js (New: Injects tenant context into every request)
utils/queryScoper.js (New: Intercepts Mongoose queries to inject workspaceId)
services/workspaceService.js
(Update: Logic for cross-workspace moves)
middleware/leakageGuard.js (New: Validates response data doesn't contain foreign IDs)
routes/workspaces.js
(Update: Access control overhaul)
models/Transaction.js
(Update: Indexing for tenant isolation)
models/User.js
(Update: Workspace role maps)
services/authService.js (Update: Tenant-aware token generation)
routes/admin.js (New: Global tenant monitoring)
tests/tenantIsolation.test.js (New: Data leakage tests)
TENANT_SECURITY_SPEC.md (Technical spec)