Skip to content

test: guard metrics RPCs with org oracle checks#1761

Open
riderx wants to merge 4 commits intomainfrom
riderx/metrics-rpc-rbac-tests
Open

test: guard metrics RPCs with org oracle checks#1761
riderx wants to merge 4 commits intomainfrom
riderx/metrics-rpc-rbac-tests

Conversation

@riderx
Copy link
Member

@riderx riderx commented Mar 8, 2026

Summary (AI generated)\n\n- Added an SQL regression test to verify cross-tenant/org access control boundaries for org-scoped metrics RPCs.\n- The new test protects against unauthenticated or unauthorized callers reading data via get_app_metrics, get_global_metrics, and get_total_metrics.\n- Existing behavior is also validated for authorized owner and service-role-only explicit total-metrics access.\n\n## Motivation (AI generated)\n\n- Prior code paths could expose or cache metrics across tenants when org/context checks were bypassed.\n- This regression test locks in the expected oracle-based authorization behavior after the recent RPC hardening changes.\n\n## Business Impact (AI generated)\n\n- Prevents cross-tenant metric leakage and reinforces tenant isolation for billing/usage and dashboard reporting endpoints.\n- Reduces regression risk in a security-sensitive area with low test coverage previously.\n\n## Test Plan (AI generated)\n\n- [x] Added supabase/tests/45_test_metrics_oracle.sql with dedicated users, org/app fixtures, and authorization assertions.\n- [x] Ran bun lint:backend successfully.\n\nGenerated with AI

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 901134bb-78f8-46a1-8a13-4c33211b9ca0

📥 Commits

Reviewing files that changed from the base of the PR and between 2af3a08 and cdaa98e.

📒 Files selected for processing (3)
  • AGENTS.md
  • supabase/migrations/20260308121758_fix_get_app_global_metrics_rbac.sql
  • supabase/tests/45_test_metrics_oracle.sql
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch riderx/metrics-rpc-rbac-tests

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

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b72544d5fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +118 to +120
SELECT tests.authenticate_as_service_role();

RETURN NEXT throws_ok(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Assert permission denial before switching to service_role

This test switches to service_role and then expects get_total_metrics(org_id, start_date, end_date) to throw permission denied, but that overload is granted to service_role (see supabase/migrations/20260224093000_fix_get_total_metrics_auth.sql), so the assertion is inverted and will fail when the SQL test suite runs. The denial assertion should be executed while still authenticated as a non-service caller (e.g. the attacker) to verify the intended access control boundary.

Useful? React with 👍 / 👎.

@riderx riderx force-pushed the riderx/metrics-rpc-rbac-tests branch from b72544d to c57c573 Compare March 9, 2026 00:00
@riderx riderx force-pushed the riderx/metrics-rpc-rbac-tests branch from c57c573 to cdaa98e Compare March 9, 2026 00:07
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 9, 2026

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