Summary
Capgo contains a broken object level authorization flaw where middlewareKey() trusts a client-controlled header to select limited keys without verifying tenant ownership.
Authenticated users can adopt another tenant's limited key ID via the x-limited-key-id header, bypassing authorization checks and accessing cross-tenant resources across multiple API endpoints.
Affected context
This vulnerability appears in Capgo deployments that rely on middlewareKey() to enforce access control for limited keys.
It is relevant when:
- API clients can set or override the x-limited-key-id header
- Limited keys are used to scope access to tenant data or resources
- Ownership checks between the authenticated user (or tenant) and the provided limited key ID are missing or incomplete
In such contexts, APIs that depend on this middleware for tenant isolation become susceptible to cross-tenant data and resource access.
Exploit preconditions
- Attack surface: Capgo HTTP APIs that rely on middlewareKey() and accept the x-limited-key-id header
- Required access: Valid authenticated account on the platform (any tenant)
- Trigger point: Sending requests with a forged or stolen x-limited-key-id value referencing another tenant's limited key
- Why exploitation is possible: The middleware trusts the client-provided header and associates the request with the referenced limited key without verifying that it belongs to the authenticated user or tenant, causing broken object-level authorization.
Why this happens
The root cause is a missing ownership and authorization check for object references provided by the client.
middlewareKey() directly uses the x-limited-key-id header to select a limited key, treating the ID as trusted input.
This maps to CWE-639: Insecure Direct Object Reference (IDOR) / Broken Object Level Authorization, where an application exposes internal identifiers and fails to verify whether the requester is permitted to access the referenced object.
At a pattern level, the code couples authentication to object lookup but omits per-object authorization, allowing any authenticated user to operate on another tenant's scoped key.
Potential impact
- Authenticated users may access other tenants' data through mis-scoped limited keys
- Attackers could invoke privileged operations bound to another tenant's limited key
- Cross-tenant resource exposure and information leakage can occur across affected endpoints
- Abuse of limited keys could lead to data tampering or unauthorized actions within victim tenants
- Regulatory or compliance impact due to violation of tenant isolation guarantees
General mitigation guidance
Effective mitigation focuses on enforcing strict object-level authorization and reducing trust in client-supplied identifiers.
Common defensive patterns include:
- Always verifying that any referenced limited key (or similar object) belongs to the authenticated user or tenant before use
- Resolving key associations server-side based on authenticated context, rather than accepting arbitrary client-provided IDs
- Centralizing authorization checks so that all middleware and endpoints consistently validate ownership and permissions for referenced objects
- Designing APIs to avoid direct exposure of sensitive internal identifiers where possible, or scoping identifiers so they are only meaningful within a tenant context
- Applying least-privilege principles to limited keys, ensuring they cannot grant broader access than intended even if misused
How teams detect issues like this
Detection usually involves analyzing both code and runtime behavior for missing authorization around object references.
Useful approaches include:
- Static analysis rules that flag uses of client-controlled IDs (headers, path params, query params) when used directly in object lookups without prior authorization checks
- Code review practices that require explicit ownership validation whenever limited keys, tenant IDs, or other access-scoping objects are resolved
- API security testing that attempts cross-tenant access by manipulating headers like x-limited-key-id and other ID-bearing fields
- Logging and monitoring that correlate limited key usage with tenant context, alerting on anomalies such as keys crossing tenant boundaries
- Policy-based enforcement in CI/CD pipelines to ensure authorization middleware is consistently applied to all endpoints using scoped keys

