Summary
Capgo's backend can incorrectly honor a user-supplied limited-key identifier without verifying that the referenced key is a valid child of the authenticated key. An authenticated API-key user may therefore have a more privileged same-owner key selected as the effective principal, potentially granting access to application operations that the original key cannot perform.
Affected context
The issue occurs in Capgo backend deployments that process the x-limited-key-id header and use API keys as independent RBAC principals. Risk arises when key lookup validates expiration and ownership but does not validate the parent-child delegation relationship or ensure that the requested key is within the authenticated key's authorized scope. The condition is particularly relevant where keys belonging to the same user have different application or organization permissions.
Exploit preconditions
- Attack surface: Authenticated Capgo API requests processed by the backend key middleware
- Required access: A valid API key with permission to authenticate requests, such as an
apikey_managerkey - Trigger point: Processing of the attacker-controlled
x-limited-key-idheader - Required condition: The requester must know or obtain the numeric identifier of another key owned by the same user
- Why exploitation is possible: Key resolution checks the identifier, expiration state, and user ownership but does not establish that the selected key is a delegated child authorized by the authenticating key
Why this happens
The underlying flaw is an incomplete authorization decision in the limited-key substitution flow. checkKeyByIdPg() resolves a requested key using identity and status attributes, while hasLimitedRbacSubkeyScope() accepts broad non-organization RBAC bindings and validateSubkeyUser() only compares owner IDs. Because API keys are separate RBAC principals, same-user ownership does not prove a valid delegation relationship. This maps to CWE-863: Incorrect Authorization, where the system permits an operation without verifying the required relationship and scope between the requester and the selected principal.
Potential impact
- An authenticated user may gain permissions associated with a more privileged sibling API key
- The attacker could access application functions outside the original key's authorized scope
- Administrative or application-management operations may be performed without the corresponding key secret
- Application data or configuration could be modified, depending on the substituted key's permissions
- Audit records may attribute actions to the wrong effective API-key principal
General mitigation guidance
Mitigation generally focuses on making delegation explicit and enforcing authorization at every principal-substitution boundary.
Common defensive patterns include:
- Require the requested key to be an actual child of the authenticating key, rather than merely sharing the same owner
- Bind delegated keys to an explicit parent identifier and verify that relationship server-side
- Enforce application, organization, role, and scope containment when resolving a limited key
- Avoid treating user ownership alone as sufficient authorization for key substitution
- Preserve the original authenticated principal unless the delegation relationship has been fully validated
- Apply least privilege to API-key roles and separate administrative credentials from application-scoped credentials
- Record both the authenticating key and delegated key in security-relevant audit events
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis and code review checks for authorization decisions based only on resource ownership
- Tests that attempt to substitute sibling, unrelated, expired, and cross-application key identifiers
- Review of middleware that replaces authenticated principals or effective secrets from request-controlled identifiers
- Policy checks requiring explicit parent-child and scope-containment validation for delegated credentials
- Runtime monitoring for API requests where a low-privilege key selects a different principal or unexpectedly invokes administrative operations
- Automated security review tools that flag user-controlled identifiers used in authorization or principal-switching logic

