Summary
An information disclosure flaw in Capgo allows unauthenticated callers to invoke a SECURITY DEFINER PostgreSQL function via a public RPC endpoint and retrieve sensitive API key metadata.
When a valid key value is supplied to the exposed function, attackers can learn user association, org scoping, mode, and expiration details, increasing the risk of targeted abuse and account mapping.
Affected context
This vulnerability appears in Capgo deployments where:
- The
find_apikey_by_valuePostgreSQL function is markedSECURITY DEFINER - The function is exposed through
/rest/v1/rpc/find_apikey_by_value - The
anonrole is allowed to execute the function without strong authentication
In such configurations, any party able to reach the REST endpoint and supply a valid API key value can obtain detailed metadata about that key.
Exploit preconditions
- Attack surface: Public or semi-public HTTP interface at
/rest/v1/rpc/find_apikey_by_value - Required access: Network access to the Capgo REST endpoint; a valid API key value (not necessarily belonging to the attacker)
- Trigger point: Calling the RPC endpoint that wraps the
find_apikey_by_valuePostgreSQL function - Why exploitation is possible: The function runs as
SECURITY DEFINERand is bound to theanonrole, permitting metadata queries by unauthenticated users who know or can obtain a key value
Why this happens
The underlying issue is a mismatch between the privilege level of a database function and the trust level of the caller that can reach it.
Marking find_apikey_by_value as SECURITY DEFINER grants elevated database rights to the function, yet exposing it to the anon role via a REST RPC endpoint fails to constrain who can access the resulting sensitive data.
This aligns with CWE-200: Exposure of Sensitive Information to an Unauthorized Actor, where internal metadata about API keys (user_id, mode, org scoping, expiration) is made available to parties lacking appropriate authorization guarantees.
Potential impact
- Attackers may map API keys to specific users and organizations
- Attackers could profile key usage modes and scopes to plan targeted attacks
- Attackers can identify expiration timelines, aiding timing-based abuse
- Attackers may combine metadata with other leaks to escalate or pivot into account compromise
General mitigation guidance
Effective mitigation focuses on reducing who can access sensitive metadata and limiting the privileges of helper functions:
- Avoid exposing SECURITY DEFINER functions directly to unauthenticated or low-trust roles
- Enforce strict authorization checks on RPC endpoints that reveal API key details
- Return only minimal, non-sensitive fields to untrusted callers, or use separate, reduced-view functions
- Apply least-privilege design to database functions, avoiding broad access patterns to security-critical tables
- Treat API key metadata as sensitive and design interfaces that reveal such data only under verified ownership or admin context
How teams detect issues like this
Organizations can identify similar issues by:
- Reviewing database functions marked
SECURITY DEFINERand mapping where they are exposed via HTTP or RPC interfaces - Using static analysis or schema inspection to flag functions callable by anonymous or low-privilege roles that touch security-related tables
- Conducting code reviews focused on API key handling paths, checking for endpoints that return metadata without explicit authorization checks
- Applying policy controls that require security review for new RPC functions and database procedures involving authentication or authorization data

