/

CVE-2026-56239

Severity:

HIGH RISK

(7.6)

Privilege Escalation (CWE-269) in Capgo Billing RPC

CVE-2026-56239

Deferred

Vulnerability type

Category:

Privilege Management Error

CWE:

CWE-269

Impact:

Privilege Escalation and Billing Manipulation

Severity:

HIGH RISK

(7.6)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A privilege escalation flaw in Capgo's public.apply_usage_overage SECURITY DEFINER function allows sensitive billing actions to run without proper internal authorization checks.

When exposed to authenticated or anonymous roles through Supabase RPC, an attacker can manipulate billing data for organizations they do not control, potentially depleting credits or injecting fraudulent overage events.

Affected context

This vulnerability manifests in Capgo deployments where the public.apply_usage_overage function is defined as SECURITY DEFINER and exposed through Supabase RPC.

It becomes risky when authenticated or anonymous roles have EXECUTE privileges on the function, either directly or via default grants, and when internal checks (such as auth.uid(), organization membership verification, or minimum rights validation) are not enforced.

In such configurations, Row Level Security is effectively bypassed because the function executes with the owner's elevated privileges.

Exploit preconditions

  • Attack surface: Database-level function exposed via Supabase RPC or direct SQL access.
  • Required access: Ability for an authenticated or anonymous role to EXECUTE the public.apply_usage_overage function.
  • Trigger point: Invoking the SECURITY DEFINER function with crafted parameters targeting organizations or accounts the caller does not legitimately control.
  • Why exploitation is possible: The function performs sensitive billing operations while running with the owner's privileges, does not validate the caller's identity (auth.uid()), organization membership, or required rights, and thereby bypasses Row Level Security and internal authorization mechanisms.

Why this happens

The core issue is a misuse of elevated-privilege database functions without embedded authorization controls, mapped to CWE-269: Improper Privilege Management.

A SECURITY DEFINER function executes with the privileges of its owner rather than the invoking user, which is appropriate only when the function enforces strict checks on who can perform which actions.

In this case, the function implements sensitive billing logic but omits validation of the caller's identity and permissions.

As a result, any role with EXECUTE access can indirectly inherit higher privileges and operate on billing data belonging to arbitrary organizations, unintentionally bypassing Row Level Security and other access controls.

Potential impact

  • An attacker can manipulate billing data for organizations they do not belong to.
  • Credits for victim organizations may be depleted without authorization.
  • Fraudulent overage events can be inserted, skewing billing metrics and audits.
  • Application-level billing integrity and trust in metering data can be undermined.
  • Indirect financial loss or service disruption may occur for affected organizations.

General mitigation guidance

Effective mitigation centers on tightening privilege boundaries and embedding authorization into privileged routines.

Common defensive patterns include:

  • Restricting EXECUTE privileges on SECURITY DEFINER functions to narrowly scoped, trusted roles instead of generic authenticated or anonymous roles.
  • Embedding explicit authorization checks in privileged functions, such as verifying auth.uid(), organization membership, and minimum rights before applying billing changes.
  • Preferring SECURITY INVOKER semantics for routines that do not require elevated privileges, so they naturally respect Row Level Security and per-user permissions.
  • Segregating billing logic into service layers that enforce business-level authorization before issuing database mutations.
  • Periodically reviewing default privileges and RPC exposures to ensure sensitive functions are not unintentionally callable by broad audiences.

How teams detect issues like this

Organizations can detect similar issues by combining schema inspection, policy review, and automated checks:

  • Regularly audit database functions for SECURITY DEFINER usage, especially in schemas exposed via APIs or RPC, and flag those lacking internal authorization checks.
  • Use static or schema analysis tools to identify functions granted EXECUTE to broad roles such as authenticated, anon, or public.
  • During code and migration review, require explicit documentation of why SECURITY DEFINER is necessary and which authorization checks are implemented.
  • Implement policy-as-code (e.g., in CI/CD) that fails builds when new privileged functions omit patterns like caller identity verification, organization membership checks, or minimum rights enforcement.
  • Correlate billing or metering anomalies with RPC logs to surface suspicious cross-organization operations.

Sources

SourceLink
github.comgithub.com/Cap-go/capgo/security/advisories/GHSA-qq85-vjrq-m75g
vulncheck.comvulncheck.com/advisories/capgo-privilege-escalation-via-security-definer-function-apply-usage-overage

Frequently asked

questions

Yes, if the function is exposed via Supabase RPC or other remote database access mechanisms and EXECUTE privileges are granted to remote-facing roles, an attacker can trigger it over the network.

The attacker needs an account mapped to a role (such as authenticated or anon) that has EXECUTE privileges on the public.apply_usage_overage function, either directly or via default grants; no direct database superuser access is required.

The safest pattern is to restrict EXECUTE access on privileged functions to tightly controlled roles and to embed clear authorization checks inside the function body, ensuring that operations verify the caller's identity, organization membership, and required rights before performing billing actions.

Future prevention involves adopting a consistent design where privileged routines are rare, well-reviewed, and always implement explicit authorization, combined with automated checks that flag new SECURITY DEFINER functions, broad EXECUTE grants, or RPC-exposed routines that manipulate sensitive data.

Find out what's already
exploitable in your codebase.