Summary
Capgo contains an authentication bypass in the public.get_org_user_access_rbac function, where a flawed NULL comparison in the authorization gate allows access without a valid user identity.
Unauthenticated attackers using only a public API key can query the PostgREST RPC endpoint to retrieve RBAC role bindings and member email addresses, exposing organization membership and role information.
Affected context
This vulnerability manifests in Capgo deployments where RBAC checks are enforced through database functions exposed via PostgREST RPC endpoints.
The issue arises specifically in the public.get_org_user_access_rbac function when authorization logic depends on NULL-sensitive comparisons to determine whether a request is associated with an authenticated user.
In environments that rely on a public API key for initial access, mis-handled NULL values in the auth gate can cause the system to treat unauthenticated callers as authorized to view RBAC bindings and member details, even though no verified user context is present.
Exploit preconditions
- Attack surface: PostgREST RPC endpoint exposing
public.get_org_user_access_rbac - Required access: Possession of a public API key; no valid user session or credentials needed
- Trigger point: Invocation of the RBAC access function with parameters that cause the authorization gate to misinterpret NULL user identity
- Why exploitation is possible: The authorization logic relies on incorrect or incomplete NULL comparison, allowing the function to skip or incorrectly evaluate authentication checks, effectively treating unauthenticated calls as permitted and returning RBAC role bindings and associated email addresses.
Why this happens
The underlying bug is an authentication logic flaw where the system attempts to gate access based on the presence of a valid user identity but uses NULL handling and comparison patterns that do not reliably distinguish authenticated from unauthenticated contexts.
In SQL and stored procedures, conditions involving NULL can behave unexpectedly if operators and default values are not carefully chosen, leading to cases where a missing identity is treated as acceptable.
This behavior aligns with CWE-287: Improper Authentication, because the mechanism intended to verify that a caller is authenticated fails to enforce that requirement, allowing unauthorized parties to access RBAC metadata and user-related information.
Potential impact
- Unauthorized disclosure of organization membership lists
- Exposure of RBAC role bindings and role assignment structures
- Leakage of member email addresses associated with organizations
- Facilitation of targeted phishing, social engineering, or account takeover attempts
- Enhanced reconnaissance for attackers mapping organizational relationships and privilege levels
General mitigation guidance
Mitigation typically focuses on hardening authentication checks and removing ambiguity from authorization logic:
- Ensure that all RBAC-related functions explicitly require a verified user identity or session and fail closed when identity is NULL or missing.
- Use clear, deterministic authorization predicates that do not depend on implicit NULL behavior; prefer explicit IS NULL / IS NOT NULL checks and conservative defaults.
- Separate public, non-sensitive endpoints from those that expose organizational or user-related data, and gate sensitive RPC calls behind authenticated API keys or session tokens.
- Implement least-privilege principles for data exposure, returning only the minimal fields required for functionality and excluding sensitive contact information from general RBAC queries.
- Centralize authentication and authorization decisions in well-tested middleware or policies rather than duplicating complex checks inside individual database functions.
How teams detect issues like this
Organizations can detect similar authentication bypass issues by:
- Reviewing RBAC-related SQL functions and stored procedures for logic that depends on ambiguous NULL comparisons or defaults that treat unauthenticated callers as valid.
- Applying static analysis or rule-based checks to identify authorization conditions that lack explicit enforcement of a user identity or rely solely on public API keys.
- Incorporating security-focused code review practices that flag exposure of user-identifiable information (such as emails) via endpoints that are reachable without authentication.
- Configuring automated tests or security regression suites that simulate unauthenticated calls to sensitive RPC endpoints and verify that data access is denied by default.
- Using database auditing and API logging to monitor for unusual access patterns, such as repeated RBAC metadata queries from clients presenting only public keys.

