Summary
Capgo exposes a SECURITY DEFINER PostgREST RPC function that is callable with only the public Supabase publishable anon key, allowing misuse across tenants.
An unauthenticated attacker can insert or overwrite build log records for arbitrary organizations, potentially tampering with billing data and inflating billable usage.
Affected context
This vulnerability arises in Capgo deployments that use Supabase/PostgREST with a SECURITY DEFINER function public.record_build_time granted to the anon role.
The function is callable using only the public Supabase publishable sb_publishable_* anon key, and operates directly on the public.build_logs table.
In environments where this function is exposed without additional authentication or tenant scoping checks, arbitrary organizations' build log and billing data can be modified.
Exploit preconditions
- Attack surface: Public PostgREST RPC endpoint for
public.record_build_time. - Required access: Possession of the Supabase publishable anon key (
sb_publishable_*), which is typically embedded in client-side code and not secret. - Trigger point: Calling the
record_build_timeRPC with chosenbuild_idandorg_idparameters. - Why exploitation is possible: The SECURITY DEFINER function runs with elevated privileges, is granted to the
anonrole, and does not sufficiently enforce tenant isolation or verify that the caller is authorized to write to the targetedorg_id. TheON CONFLICT (build_id, org_id) DO UPDATEclause allows both insertion and overwriting of existing records.
Why this happens
The root cause is improper access control on a privileged database function that mutates shared billing data.
By marking public.record_build_time as SECURITY DEFINER, the function executes with the owner's permissions but is still exposed to the low-privilege anon role, which is reachable with only a publishable key.
The function lacks robust authorization checks to ensure the caller is acting on its own tenant or organization, resulting in cross-tenant data modification.
This pattern maps to CWE-284: Improper Access Control, where a resource-modifying operation is available to identities that should not have such capabilities.
Potential impact
- An attacker may insert bogus build logs for arbitrary organizations.
- An attacker may overwrite existing build log and billing records by reusing chosen
build_idandorg_idcombinations. - Organizations could experience inflated billable build time, causing financial-impact denial of service.
- Billing audits, usage analytics, and operational metrics can be corrupted or rendered unreliable.
- In multi-tenant environments, trust between tenants and the service provider can be undermined due to cross-tenant tampering.
General mitigation guidance
Effective mitigation focuses on tightening authorization around privileged database functions and enforcing strict tenant isolation.
Common defensive patterns include:
- Removing or limiting grants to the
anonrole for any SECURITY DEFINER or privileged billing-related functions. - Requiring authenticated, tenant-bound roles (e.g., per-user or per-organization roles) for operations that write billing or usage data.
- Enforcing tenant scoping within functions by deriving
org_idfrom the authenticated context or JWT claims rather than trusting client-supplied identifiers. - Applying row-level security (RLS) and policy checks on billing tables so that only authorized principals can create or modify records for their own tenant.
- Using least-privilege design for database roles and avoiding exposing SECURITY DEFINER routines via public API endpoints unless absolutely necessary and tightly constrained.
How teams detect issues like this
Detection typically involves reviewing database- and API-layer permissions alongside logs for anomalous usage patterns.
Possible strategies include:
- Static review of database schema for SECURITY DEFINER functions granted to low-privilege or public roles, especially where they write to billing or multi-tenant tables.
- Code and migration review processes that flag new or changed RPC functions that accept tenant identifiers from clients without deriving them from authenticated context.
- Automated checks or linters for PostgREST/Supabase configuration that surface functions mapped to the
anonrole with write capabilities. - Runtime monitoring for suspicious billing activity, such as sudden spikes in build time, repeated updates to the same
build_idfrom diverse IP addresses, or cross-organization patterns. - Periodic access control audits that compare intended authorization rules with actual grants at the database and API layers.

