Skip to content

fix: restrict org plan status RPC access#1967

Merged
riderx merged 2 commits intomainfrom
codex/fix-ghsa-j5h5-v35x-mgjf
Apr 27, 2026
Merged

fix: restrict org plan status RPC access#1967
riderx merged 2 commits intomainfrom
codex/fix-ghsa-j5h5-v35x-mgjf

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented Apr 27, 2026

Summary (AI generated)

  • 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
  • Wait for GitHub CI to pass on the PR

Generated with AI

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

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).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

codex

Poem

🐰 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!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: restricting access to an org plan status RPC to fix a security vulnerability.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed PR description is well-structured with Summary, Motivation, Business Impact, and Test Plan sections covering the security fix comprehensively.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-ghsa-j5h5-v35x-mgjf

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented Apr 27, 2026

Merging this PR will not alter performance

✅ 28 untouched benchmarks


Comparing codex/fix-ghsa-j5h5-v35x-mgjf (8a98210) with main (847a8b9)

Open in CodSpeed

@sonarqubecloud
Copy link
Copy Markdown

@riderx riderx marked this pull request as ready for review April 27, 2026 13:00
@riderx riderx merged commit 1a65f50 into main Apr 27, 2026
16 checks passed
@riderx riderx deleted the codex/fix-ghsa-j5h5-v35x-mgjf branch April 27, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant