Summary
An authorization bypass in Supabase Capgo's SECURITY DEFINER record_build_time RPC function lets unauthenticated callers insert arbitrary build-time records using only a public API key.
When exposed, this can be abused to poison billing and quota data across organizations, enabling cross-tenant resource exhaustion and billing manipulation.
Affected context
This vulnerability appears in Supabase Capgo deployments that expose the record_build_time RPC function over the REST interface via /rest/v1/rpc/record_build_time.
The risk exists when the function runs with elevated privileges under SECURITY DEFINER, while access control relies primarily on a public API key rather than tenant-scoped authorization checks.
In such configurations, the function may accept arbitrary input to create billing-related records that are not reliably bound to the caller's own organization context.
Exploit preconditions
- Attack surface: Public REST endpoint at
POST /rest/v1/rpc/record_build_time - Required access: Possession of a public Supabase API key and network reachability to the Capgo backend
- Trigger point: Invoking the record_build_time RPC with crafted payloads to insert build-time records for chosen organizations or projects
- Why exploitation is possible: The RPC function runs as a
SECURITY DEFINERwith elevated privileges and lacks sufficient tenant-aware authorization checks, allowing untrusted callers to perform actions reserved for privileged roles.
Why this happens
The underlying issue is an authorization design flaw where a SECURITY DEFINER function is exposed through a public-facing API without robust access control and tenant scoping.
In database-backed applications, SECURITY DEFINER routines execute with the owner's privileges, which can override row-level security or role-based checks when not carefully constrained.
This maps to CWE-269: Improper Privilege Management, where privileged operations are unintentionally made available to low-privilege or unauthenticated users due to missing or incomplete authorization logic.
Potential impact
- Attackers may poison billing data by inserting arbitrary build-time records.
- Attackers could manipulate quotas, leading to incorrect enforcement for affected organizations.
- Tenant isolation can be undermined, enabling cross-tenant billing and usage manipulation.
- Target organizations may suffer unexpected resource exhaustion or financial impact from falsified usage.
General mitigation guidance
Effective mitigation focuses on tightening authorization checks around privileged routines and avoiding unnecessary use of SECURITY DEFINER for externally accessible functions.
Common defensive patterns include:
- Ensuring RPC functions that alter billing or quota data are restricted to authenticated, tenant-bound roles, with explicit checks on organization ownership.
- Applying row-level and tenant-scoped access control that cannot be bypassed by elevated function privileges.
- Refactoring critical operations to run under
SECURITY INVOKERsemantics where feasible, so they inherit the caller's permissions. - Segregating billing and quota manipulation logic behind internal-only services or admin APIs, rather than public endpoints keyed by project-level API tokens.
- Adopting least-privilege principles for database roles and functions to minimize the blast radius of any exposed procedure.
How teams detect issues like this
Detection often centers on identifying over-privileged functions and unexpected public access patterns. Potential strategies include:
- Static analysis or schema review to flag
SECURITY DEFINERfunctions exposed via REST/RPC endpoints, especially for billing or quota operations. - Security-focused code review of database functions and access policies to ensure tenant scoping and role checks are applied consistently.
- Logging and monitoring of calls to sensitive RPC endpoints, alerting on anomalous usage patterns such as high-volume build-time inserts from public keys.
- Periodic audits of privilege assignments, row-level security, and API exposure policies to catch misconfigurations in multi-tenant environments.

