Skip to content

Restrict API-key oracle RPCs from anon#1704

Merged
riderx merged 74 commits intomainfrom
riderx/fix-apikey-oracles
Mar 3, 2026
Merged

Restrict API-key oracle RPCs from anon#1704
riderx merged 74 commits intomainfrom
riderx/fix-apikey-oracles

Conversation

@riderx
Copy link
Member

@riderx riderx commented Feb 26, 2026

Summary (AI generated)

  • Removed anonymous RPC grants for public.get_org_perm_for_apikey and public.get_user_id in the base migration.
  • Added a follow-up migration to revoke EXECUTE for anon on the same API-key introspection RPC signatures.

Motivation (AI generated)

  • The public anon access enabled key-existence and permission/app-enumeration oracles, which increased the impact of leaked API keys.

Business Impact (AI generated)

  • This hardens API key handling by eliminating unauthenticated enumeration paths while preserving authenticated and service-role behavior.

Test Plan (AI generated)

  • Ran bun lint after the migration updates.
  • Reviewed git diff and git diff origin/main... to verify only the intended grant and revoke changes.
  • Run targeted Supabase migration/test flow for the RPC permission checks when available.

Screenshots

Not applicable (backend SQL migrations only).

Summary by CodeRabbit

  • Security
    • Restricted unauthenticated access to sensitive API authentication and permission verification functions. Only authenticated users and service accounts can now execute these operations, improving overall system security by preventing unauthorized introspection of API keys and user permissions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 21 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 2b59eab and bf8ddb5.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (59)
  • .gitsecret/paths/mapping.cfg
  • internal/AuthKey_8P7Y3V99PJ.p8.secret
  • internal/CICD.mobileprovision.secret
  • internal/Certificates.p12.secret
  • internal/Certificates_p12.p12.secret
  • internal/capgo-394818-68ad1517d330.json.secret
  • internal/cloudflare/.env.local.secret
  • internal/cloudflare/.env.preprod.secret
  • internal/cloudflare/.env.prod.secret
  • internal/forgr-key.jks.base64.secret
  • internal/forgr-key.jks.secret
  • internal/how-to-deploy.md.secret
  • internal/supabase/.env.local.secret
  • messages/de.json
  • messages/en.json
  • messages/es.json
  • messages/fr.json
  • messages/hi.json
  • messages/id.json
  • messages/it.json
  • messages/ja.json
  • messages/ko.json
  • messages/pl.json
  • messages/pt-br.json
  • messages/ru.json
  • messages/tr.json
  • messages/vi.json
  • messages/zh-cn.json
  • package.json
  • read_replicate/update_readreplica_passwords.sh
  • src/components/dashboard/DemoOnboardingGate.vue
  • src/components/dashboard/DemoOnboardingModal.vue
  • src/modules/auth.ts
  • src/modules/i18n.ts
  • src/pages/delete_account.vue
  • src/pages/resend_email.vue
  • src/pages/settings/organization/Security.vue
  • src/services/versions.ts
  • supabase/functions/_backend/private/role_bindings.ts
  • supabase/functions/_backend/public/apikey/post.ts
  • supabase/functions/_backend/public/build/request.ts
  • supabase/functions/_backend/public/build/upload.ts
  • supabase/functions/_backend/public/organization/members/delete.ts
  • supabase/functions/_backend/utils/cloudflare.ts
  • supabase/functions/_backend/utils/version.ts
  • supabase/migrations/20260225120000_restrict_webhooks_select_for_admin_only.sql
  • supabase/migrations/20260226090000_require_verified_email_for_delete_user.sql
  • supabase/migrations/20260227000000_secure_record_build_time_rpc.sql
  • supabase/migrations/20260227150000_fix_invite_user_to_org_security.sql
  • supabase/migrations/20260228000000_role_bindings_rls_assignable.sql
  • supabase/migrations/20260228000100_delete_member_cascade_bindings.sql
  • supabase/migrations/20260228000200_prevent_last_super_admin_delete.sql
  • supabase/migrations/20260228000300_fix_apikey_hashed_lookup.sql
  • supabase/migrations/20260228172308_fix_prevent_last_super_admin_cascade.sql
  • supabase/migrations/20260228172309_fix_rbac_test_compatibility.sql
  • supabase/tests/34_test_rbac_rls.sql
  • supabase/tests/35_test_is_admin_rbac.sql
  • tests/builder-payload.unit.test.ts
  • tests/organization-api.test.ts
📝 Walkthrough

Walkthrough

This pull request revokes anonymous access to three API-key introspection functions across two database migration files, restricting execute privileges on public.get_org_perm_for_apikey() and two variants of public.get_user_id() from the anonymous role while maintaining access for authenticated and service_role users.

Changes

Cohort / File(s) Summary
Database Privilege Migrations
supabase/migrations/20250530233128_base.sql, supabase/migrations/20260226153000_restrict_apikey_oracle_rpcs.sql
Identical REVOKE statements removing EXECUTE privileges on the anon role for three function signatures: get_org_perm_for_apikey(apikey text, app_id text), get_user_id(apikey text), and get_user_id(apikey text, app_id text). Access remains available for authenticated and service_role users.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

💰 Rewarded

Poem

🐰 Anonymous door locked tight today,
API keys now hidden away,
Only the trusted may peek and see,
Permissions guarded with certainty! 🔐

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Restrict API-key oracle RPCs from anon' accurately and concisely describes the main change: removing anonymous access to API-key introspection functions.
Description check ✅ Passed The PR description covers summary, motivation, and business impact, though the test plan section has incomplete checkboxes and lacks detailed reproduction steps as specified in the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch riderx/fix-apikey-oracles

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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: 2b59eab3dd

ℹ️ 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".


GRANT ALL ON FUNCTION "public"."get_org_perm_for_apikey" ("apikey" "text", "app_id" "text") TO "anon";

GRANT ALL ON FUNCTION "public"."get_org_perm_for_apikey" ("apikey" "text", "app_id" "text") TO "authenticated";

Choose a reason for hiding this comment

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

P1 Badge Keep historical migration files immutable

This commit modifies 20250530233128_base.sql, but /workspace/capgo/AGENTS.md explicitly requires you to “never edit previously committed migrations.” Rewriting an already-applied migration makes schema history non-immutable and can create drift/confusion between environments that already ran the original file and fresh environments that replay the edited file; this hardening should live only in a new migration.

Useful? React with 👍 / 👎.

WcaleNieWolny and others added 27 commits February 26, 2026 12:01
Builder availability errors (not configured, call failed, error response,
missing upload URL) are transient server-side failures, not client errors.
Returning 503 allows the CLI retry logic to automatically retry these
requests instead of treating them as terminal 400 errors.
fix: return 503 for service_unavailable build errors
fix: correct vue/html-indent in DemoOnboardingModal
Extract buildBuilderPayload() from the inline fetch body so the
snake_case → camelCase mapping and exact key set can be tested.
6 vitest cases verify: camelCase output, no legacy credentials field,
correct metadata keys, and pass-through of contents.
Add unit tests for builder payload shape
Old CLI clients sending the flat `credentials` field would have it
silently dropped, causing confusing builder failures. Now the proxy
explicitly rejects non-empty `credentials` with a migration message
pointing to `build_credentials`.
riderx and others added 27 commits March 1, 2026 15:35
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
fix(security): RBAC security audit fixes
* fix(auth): block account deletion for unverified users

* fix(auth): refresh session fields for email verification gate

* fix(auth): make delete_user insert idempotent

* fix(auth): explain blocked delete/settings when email unverified

* fix(auth): block delete action when email is unverified

* fix(auth): localize resend email block and make delete_user idempotent
* fix(db): restrict invite_user_to_org public rpc

* fix(db): use caller identity in invite 2FA check
* fix(db): secure record_build_time rpc writes

* fix(db): preserve service-role record_build_time path
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2026

@riderx riderx merged commit 6103e84 into main Mar 3, 2026
15 checks passed
@riderx riderx deleted the riderx/fix-apikey-oracles branch March 3, 2026 12:56
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.

4 participants