fix(db): bound app version upload policies#2347
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughThis PR adds security-definer API key resolution and permission-gating helpers to refactor ChangesAPI Key v2 App Versions Authorization
Possibly Related PRs
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@supabase/migrations/20260528002613_fix_apikey_v2_app_versions_rls_perf.sql`:
- Around line 304-377: Add a legacy org_users fallback for authenticated users
in public.app_versions_has_app_permission: if v_principal_type =
public.rbac_principal_user(), query public.org_users for a row with user_id =
v_principal_id and org_id = v_app_owner_org and check that org_users.user_right
>= p_min_right (or equivalent comparison used elsewhere); if such a row exists
return true immediately before the RBAC/existence recursive query (use the same
local variables v_principal_type, v_principal_id, v_app_owner_org, p_min_right
and public.rbac_principal_user() to locate the check).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 07c50112-9aac-4f93-a5f1-35c597eecbb5
📒 Files selected for processing (2)
supabase/migrations/20260528002613_fix_apikey_v2_app_versions_rls_perf.sqlsupabase/tests/56_test_apikey_v2_scope_and_rls.sql
b6c0a1d to
d9193be
Compare
d9193be to
e2b1366
Compare
|



Summary (AI generated)
org_usersaccess without letting broad API keys materialize every linked app.Motivation (AI generated)
The upload itself finishes, then the CLI fails while finalizing
app_versionsmetadata. The CLI path isupdateOrCreateVersion(...), which performs a targetedapp_versionsupsert after the TUS bundle and partial files upload. The old policy could still materialize every app linked to a broad API key during that targeted write, so a key linked to many apps/orgs could hitstatement_timeoutafter upload succeeded.Business Impact (AI generated)
This restores reliable bundle uploads for customers using broad API keys, without moving extra work into the CLI or adding per-upload primary-side background work. The final database write now stays bounded to the target app instead of scaling with all linked apps, so this should not add meaningful database cost.
Test Plan (AI generated)
bash scripts/check-supabase-migration-order.shbun lint:backendbun run supabase:db:resetbun scripts/supabase-worktree.ts test db supabase/tests/00-supabase_test_helpers.sql --localbun scripts/supabase-worktree.ts test db supabase/tests/56_test_apikey_v2_scope_and_rls.sql --localbun run supabase:with-env -- bunx vitest run tests/app-versions-rls-dos.test.tsapp_versionsupsert in 104 ms under a 500 msstatement_timeout.Screenshots (AI generated)
Not applicable. Database/RLS migration only.
Generated with AI