Summary
Capgo before 12.128.2 contains an authorization bypass in its middleware key handling, where subkey scope constraints are not properly enforced.
By abusing the x-limited-key-id header, attackers can cause downstream routes to run under a less restricted parent key instead of the intended scoped subkey, enabling unauthorized access to organization- or app-limited resources.
Affected context
This vulnerability appears in environments using Capgo middleware key functionality to enforce subkey scoping based on organization or application constraints.
It is relevant where the x-limited-key-id header is trusted to select scoped subkeys, and downstream route handlers rely on these subkeys for enforcing limited_to_orgs and limited_to_apps restrictions.
The risk is higher in APIs or services that expose sensitive operations under parent keys and depend on subkeys for fine-grained authorization.
Exploit preconditions
- Attack surface: HTTP(S) endpoints protected by Capgo middlewareKey logic.
- Required access: Ability to send requests with custom headers, particularly x-limited-key-id, using a valid key and subkeys owned by the attacker.
- Trigger point: Invocation of middlewareKey where the x-limited-key-id header is processed and the effective key context for the request is derived.
- Why exploitation is possible: The middleware fails to enforce limited_to_orgs and limited_to_apps constraints on subkeys referenced by x-limited-key-id, causing the unrestricted parent key to be applied to downstream route handlers instead of the scoped subkey.
Why this happens
The underlying issue is a flawed authorization control flow where the system trusts a header-driven selection of subkeys without revalidating the associated scope constraints.
Instead of ensuring that the effective key context honors limited_to_orgs and limited_to_apps, the middlewareKey implementation allows a referenced subkey to resolve back to its parent key, which may lack those limitations.
This maps to CWE-863 (Incorrect Authorization), where access control decisions are made based on incomplete or incorrect authorization data, allowing operations to proceed with broader privileges than intended.
Potential impact
- Attackers can access data or operations restricted to specific organizations that their scoped subkeys should not reach.
- Attackers may interact with applications outside the intended limited_to_apps scope.
- Fine-grained authorization boundaries can be bypassed, leading to privilege escalation from scoped subkeys to parent key capabilities.
- Misuse of administrative or management APIs that rely on subkey scoping for multi-tenant isolation.
General mitigation guidance
Effective mitigation focuses on enforcing authorization constraints consistently across all key and subkey resolution paths.
Defensive patterns include:
- Ensuring that any header-driven selection of keys or subkeys is accompanied by explicit checks of limited_to_orgs and limited_to_apps before constructing the effective authorization context.
- Designing middleware such that parent keys cannot silently replace or override subkey scopes for downstream handlers.
- Centralizing access control logic so that route handlers validate the effective key scope rather than trusting upstream assumptions.
- Applying least-privilege principles to keys and subkeys, limiting parent key capabilities where possible to reduce blast radius if scoping fails.
How teams detect issues like this
Detection commonly involves:
- Reviewing middleware and authorization code paths to ensure that scoped keys and subkeys are not upgraded to broader contexts without explicit policy checks.
- Using static analysis or linters to flag constructs where request headers can influence authorization state without corresponding scope validation.
- Implementing audit logging that records which key or subkey is used for each request, including its associated organization/app scopes, and monitoring for anomalies where scoped subkeys appear to grant parent-level access.
- Enforcing security policies during code review that require centralized authorization enforcement and prohibit implicit fallback from scoped subkeys to parent keys.

