All 8 tasks checked off. Change archived to openspec/changes/archive/
per OpenSpec protocol. Implementation committed in 5943ff1.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3.7 KiB
Proposal: Enforce Tenant Isolation on All Agent Endpoints
Title
Enforce tenant (organization) isolation on all agent CRUD endpoints — P0 Security Fix
Problem Statement
Field trial Test C.7 — Org Isolation Failure — has identified a critical security defect.
All five agent endpoints (POST /agents, GET /agents, GET /agents/{agentId},
PATCH /agents/{agentId}, DELETE /agents/{agentId}) perform no tenant isolation.
Any authenticated agent from Organization A can:
- Read the full agent list of Organization B (
GET /agents) - Read any individual agent record across any organization (
GET /agents/{agentId}) - Modify any agent's metadata across any organization (
PATCH /agents/{agentId}) - Decommission any agent across any organization (
DELETE /agents/{agentId}) - Register agents under any organization by supplying an arbitrary
organizationIdin the request body (POST /agents)
The JWT issued by the system already contains an organization_id claim (present in ITokenPayload). The enforcement layer between this claim and the data access layer is entirely absent.
This is a P0 security incident — it breaks multi-tenancy at its most fundamental level and must be resolved before any field trial continues.
Proposed Solution
Enforce organization scoping at the service layer, driven by the organization_id claim extracted from the verified JWT on every request. No request body value or query parameter may override the caller's organization context.
Three enforcement rules are applied:
Rule 1 — List scoping (GET /agents): Results are always filtered to the caller's organization_id. The owner query parameter may further sub-filter within the caller's org, but can never widen the scope beyond it.
Rule 2 — Ownership guard (GET /agents/{agentId}, PATCH /agents/{agentId}, DELETE /agents/{agentId}): After retrieving the target agent record, the service compares the agent's stored organization_id against the caller's organization_id. If they do not match, the operation is rejected with 403 Forbidden and error code AUTHORIZATION_ERROR.
Rule 3 — Register scoping (POST /agents): The organizationId field in the request body is ignored. The agent is always registered under the caller's organization_id from the JWT, regardless of what the body contains.
Scope of Changes
src/types/index.ts— addorganizationIdfield toIAgentListFilterssrc/repositories/AgentRepository.ts— filterfindAll()byorganizationIdsrc/services/AgentService.ts— passorganizationIdintogetAgentById(),updateAgent(),decommissionAgent(); throwAuthorizationErroron mismatchsrc/controllers/AgentController.ts— extractreq.user.organization_idand apply to all five endpoint handlersdocs/openapi/agent-registry.yaml— document enforcement rules and 403 responses on all five endpointssrc/tests/— add Test C.7 regression suite and ownership guard tests
Acceptance Criteria
GET /agentsnever returns agents from a different organization than the caller'sGET /agents/{agentId}returns403 AUTHORIZATION_ERRORif the target agent belongs to a different organizationPATCH /agents/{agentId}returns403 AUTHORIZATION_ERRORif the target agent belongs to a different organizationDELETE /agents/{agentId}returns403 AUTHORIZATION_ERRORif the target agent belongs to a different organizationPOST /agentsignores anyorganizationIdin the request body; agent is always registered under the caller's org- OpenAPI spec documents these rules and all 403 responses on all five endpoints
- Test C.7 regression suite passes
- All ownership guard paths have test coverage
- Overall test coverage remains above 80%