Bound versioned retrieval RPC match_count to prevent unbounded results#756
Bound versioned retrieval RPC match_count to prevent unbounded results#756BigSimmo wants to merge 4 commits into
match_count to prevent unbounded results#756Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds two versioned retrieval RPC wrappers that clamp ChangesRetrieval RPC hardening
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
CI triageCI failed on this PR. Automated classification of the 2 failed job(s):
Compared with main CI run #2957 (success). Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger. |
…and fix format Migration 20260717170000_bound_versioned_retrieval_match_count.sql collided with main's 20260717170000_registry_projection_cleanup.sql. Renamed to 20260717174000 (next available slot after main's 20260717173000 tip). Also update the migration filename reference in tests/retrieval-access-scope.test.ts and apply prettier format fix to pass the format:check gate.
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 `@tests/retrieval-access-scope.test.ts`:
- Around line 126-129: Update the ACL assertions in the
boundedRetrievalMigration test to verify each complete REVOKE clause, including
the authenticated role, rather than using prefix-only checks. Also assert both
full GRANT statements targeting service_role, preserving the exact function
signatures and privileges defined by the migration.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: bd1e8520-ba70-4334-9cf0-795fa9565c61
📒 Files selected for processing (3)
docs/branch-review-ledger.mdsupabase/migrations/20260717174000_bound_versioned_retrieval_match_count.sqltests/retrieval-access-scope.test.ts
| expect(boundedRetrievalMigration).toContain( | ||
| "revoke all on function public.match_document_chunks_text_v2(text, integer, uuid[], uuid, boolean)", | ||
| ); | ||
| expect(boundedRetrievalMigration).toContain("revoke all on function public.match_document_index_units_hybrid_v2("); |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Assert the complete ACL contract.
These prefix checks still pass if authenticated is omitted from REVOKE, or if the service_role grants are removed. Assert each full revoke clause and both GRANT ... TO service_role statements.
🤖 Prompt for 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.
In `@tests/retrieval-access-scope.test.ts` around lines 126 - 129, Update the ACL
assertions in the boundedRetrievalMigration test to verify each complete REVOKE
clause, including the authenticated role, rather than using prefix-only checks.
Also assert both full GRANT statements targeting service_role, preserving the
exact function signatures and privileges defined by the migration.
…nstraint The supabase-schema.test.ts guard requires the final alphabetical migration to be 20260717173000_reassert_supabase_admin_default_privileges.sql. Moving the bound-match-count migration from 20260717174000 to 20260717162000 (a free slot between the 161000 assert and the 170000 main cluster) satisfies this ordering constraint while avoiding all existing timestamp collisions. Update tests/retrieval-access-scope.test.ts to reference the new filename.
Motivation
match_countRPC arguments areNULLor negative, which can turnLIMITinto an unbounded scan and multiply JSON hydration and response work on hot retrieval paths.Description
supabase/migrations/20260717170000_bound_versioned_retrieval_match_count.sqlthat replaces the two versioned wrappers with deterministic clamping of the exposedmatch_counttoleast(greatest(coalesce(...), 1), 96)while preserving existing signatures and defaults for callers.match_document_chunks_text_v2(text RPC) andmatch_document_index_units_hybrid_v2(index-unit RPC) and keep inner scoped helpers unchanged so candidate-window work remains capped.service_rolefor the new wrappers to preserve the service-role-only execution posture.tests/retrieval-access-scope.test.tsthat checks for the clamp expressions and the revoke/grant lines, and record the database review indocs/branch-review-ledger.md.Testing
npm run check:function-grants, which succeeded and confirmed SECUIRTY DEFINER functions are not re-opened to public/anon/authenticated.service_role(passed).git diff --checkand static diff checks (passed).npm run test:focused -- --files tests/retrieval-access-scope.test.tsrefused because changed test paths require the full suite, andnpm run testfailed due to missingvitestinnode_modules(MODULE_NOT_FOUND), so unit-suite verification could not complete in this environment.npm run verify:cheap/npm run check:runtimecould not complete becausetsx/CLI is unavailable and this environment is running Node20.xwhile the repo requires Node24.x(precondition failure), so the aggregate gates were not executed.npm run check:drift,npm run check:production-readiness, Docker-backednpm run drift:manifest, or any live Supabase actions were intentionally not executed per policy.Files changed
supabase/migrations/20260717170000_bound_versioned_retrieval_match_count.sql(new migration wrapping/clamping the RPCs).tests/retrieval-access-scope.test.tsto assert the migration/regression contract.docs/branch-review-ledger.mddocumenting the database/retrieval review.Notes and residual risk
supabase/drift-manifest.jsonandsupabase/schema.sqlparity checks) must be run in a Node 24 + Docker-enabled environment before merging and applying to hosted Supabase.Codex Task
Summary by CodeRabbit
Bug Fixes
Tests
Documentation