Summary
Capgo exposes an unauthenticated security-definer RPC function that reveals user identifiers for supplied API keys, effectively acting as an API key validity oracle.
An attacker can probe this endpoint with arbitrary keys to test whether they are valid, map them to user accounts, and then chain this information into other RPCs to derive organization membership and management email PII.
Affected context
This vulnerability affects Capgo deployments where:
- The
get_identity_apikey_onlyRPC function is deployed as a security-definer routine - The function is callable without authentication or strict authorization checks
- API keys exist as a primary authentication or scoping mechanism
- Additional RPCs (such as
get_orgs_v6) can be called with the derived identifiers to return organization or user-related data
The issue is most relevant in environments where API keys are issued to customers or internal systems and are assumed to be secret and unenumerable.
Exploit preconditions
- Attack surface: Public-facing RPC endpoint accessible over the application API
- Required access: No prior authentication; network access to the service is sufficient
- Trigger point: Invoking the
get_identity_apikey_onlyfunction with arbitrary API key values - Why exploitation is possible: The function runs with elevated privileges, trusts the provided API key as input, and returns user identifiers without verifying the caller's identity, effectively creating a validation oracle and identity mapping service.
Why this happens
The root cause lies in an over-privileged, unauthenticated security-definer RPC function that exposes sensitive internal identifiers based solely on user-controlled input.
By returning the owning user_id for any supplied API key, the function leaks information that should remain confidential and unguessable, mapping directly to CWE-200: Exposure of Sensitive Information to an Unauthorized Actor.
Architecturally, the pattern reflects a breakdown between authentication and data access control: a backend routine with elevated privileges is made callable without verifying the caller's legitimacy, and there is no output filtering to prevent disclosure of internal identifiers or key validity.
Potential impact
- Attackers can confirm whether arbitrary API keys are valid or invalid.
- Attackers can map API keys to specific
user_idvalues, aiding targeted attacks. - Attackers can chain the derived identifiers into other RPCs (e.g.,
get_orgs_v6) to enumerate organization membership. - Exposure of management email addresses and related PII tied to organizations.
- Facilitation of further account takeover attempts, phishing, or social engineering using the leaked identity data.
General mitigation guidance
Effective mitigation focuses on constraining who can call privileged routines and what they can learn from them:
- Require strong authentication and authorization before allowing access to any security-definer or elevated RPC functions.
- Avoid designing endpoints that act as key-validity oracles; do not return explicit signals that distinguish valid from invalid credentials.
- Limit the data returned from internal lookup functions so that they expose only what is strictly necessary for the intended workflow, and avoid leaking internal identifiers.
- Introduce a clear separation between internal service functions and public API surfaces, ensuring privileged routines are not directly exposed.
- Apply least-privilege principles to database functions and roles, so that no single function can both validate keys and reveal identity or PII without additional checks.
How teams detect issues like this
Organizations can detect similar issues through:
- Static and schema-based analysis of RPC definitions to identify security-definer functions accessible without authentication.
- Code review checklists that flag any endpoint or function that returns user identifiers, organization IDs, or PII without explicit authorization checks.
- API gateway or service mesh policies that enforce authentication requirements before routing calls to sensitive backend routines.
- Logging and monitoring for anomalous patterns of API key probing, such as repeated calls to identity-related RPCs with varying keys.
- Use of automated API security testing tools that look for identifier enumeration and credential oracle patterns in responses.

