You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Restrict public.is_paying_and_good_plan_org_action(orgid, actions[]) with the same caller-role and org-rights gate already used by the sibling org status RPCs
Revoke anonymous execute access and keep authenticated plus service_role execution
Extend the org status pgTAP coverage to assert admin, non-member, anonymous, and service-role behavior for the fixed RPC
Update older plan-logic SQL tests to run under service-role auth so they validate plan behavior instead of the removed public RPC access pattern
Motivation (AI generated)
GitHub security advisory GHSA-j5h5-v35x-mgjf reports that is_paying_and_good_plan_org_action remained as an unauthenticated SECURITY DEFINER org-state oracle after the earlier sibling RPC hardening. This closes that missed path with the same authorization pattern already used elsewhere in the schema.
Business Impact (AI generated)
This removes an anonymous cross-tenant billing and quota state disclosure path on Capgo's production API surface. It reduces security risk for customer organizations and avoids exposing plan, trial, credits, or over-quota status through a public RPC.
Test Plan (AI generated)
Lint the touched SQL files with sqlfluff
Verify the function body and grants directly in the local Postgres container
Verify anonymous REST access to the RPC now returns 401 / 42501
Introduces a new SECURITY DEFINER RPC function is_paying_and_good_plan_org_action that checks whether an organization has active credits or a valid Stripe subscription supporting requested action types, with access controlled via org membership checks and tests validating authorization across different user contexts.
Changes
Cohort / File(s)
Summary
New RPC Function supabase/migrations/20260427105817_restrict_is_paying_and_good_plan_org_action_access.sql
Defines a SECURITY DEFINER RPC that gates access via check_min_rights, checks usage credit balances, and evaluates Stripe trial/subscription eligibility against provided action types. Execution restricted to authenticated and service_role.
Test Authentication Setup supabase/tests/11_test_plan.sql, supabase/tests/25_test_secret_functions.sql
Adds service-role authentication initialization calls before test execution without modifying existing test logic or assertions.
New RPC Assertions supabase/tests/46_test_org_status_rpcs.sql
Expands test suite with four assertions for is_paying_and_good_plan_org_action covering admin access (returns true), non-member access (returns false), anonymous access (permission error), and service-role access (returns true).
🐰 A guardian function hops into place,
Checking credits and Stripe's good grace—
Locked tight with security seals,
Testing each user tier reveals,
Now orgs know their billing is real!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary (AI generated)
public.is_paying_and_good_plan_org_action(orgid, actions[])with the same caller-role and org-rights gate already used by the sibling org status RPCsauthenticatedplusservice_roleexecutionMotivation (AI generated)
GitHub security advisory GHSA-j5h5-v35x-mgjf reports that
is_paying_and_good_plan_org_actionremained as an unauthenticatedSECURITY DEFINERorg-state oracle after the earlier sibling RPC hardening. This closes that missed path with the same authorization pattern already used elsewhere in the schema.Business Impact (AI generated)
This removes an anonymous cross-tenant billing and quota state disclosure path on Capgo's production API surface. It reduces security risk for customer organizations and avoids exposing plan, trial, credits, or over-quota status through a public RPC.
Test Plan (AI generated)
sqlfluff401/42501Generated with AI