Repository navigation
Two-user privacy test for the database, and run the SQL behaviour tests in CI - #3556
Conversation
Adds tests/sql/two-user-privacy.sql, which signs in as two synthetic doctors and proves browser roles hold no access to any public table, the callable function allowlist, administrator functions refusing a doctor, and every browser-facing owner policy isolating the two doctors. Adds npm run test:sql (bare-image replay) and runs tests/sql in the Migration replay CI job. Repairs enrichment-repair.sql fixtures for the newer lease-tuple checks. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Warning Review limit reachedYour organization has reached its usage spending cap. Adjust your spending cap in the billing tab. Next included review available in 17 minutes. View limit details
✨ Finishing Touches: 💡 1
Comment |
🏁 CodeAnt Quality Gate ResultsCommit: ✅ Overall Status: PASSEDQuality Gate Details
|
…he coverage guard Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
There was a problem hiding this comment.
BigSimmo has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
PR Summary by QodoTest two-user database privacy and run SQL behaviour tests in CI
AI Description
Diagram
High-Level Assessment
Files changed (7)
|
|
Claude encountered an error after 2s —— View job I'll analyze this and get back to you. |
Code Review by Qodo
No findings for this group No findings for this group No findings for this group Resolved findings 1.
|
- Prevent administrator refusal helper from swallowing privacy leaks - Probe cross-owner inserts explicitly - Use valid storage columns for update probes
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46ef4ea98b
ℹ️ 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".
…e owner_rule rows Qodo's insert probe only touched documents and storage objects, which have no insert policy, so it could not catch a permissive one. Clone one of the actor's own rows, point it at the other doctor and require a row-level security refusal on every covered table. Also gives every owner_rule row the new update_col value, which Qodo's commit left mismatched (VALUES lists must all be the same length). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
|
Code review by qodo was updated up to the latest commit 590a31a |
A new overload reusing an allowed name is now caught. Proven by planting is_visible_document_page(integer) granted to authenticated: the test fails. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
…st6n' into claude/two-user-privacy-tests-ahst6n
|
Code review by qodo was updated up to the latest commit 3811823 |
The insert probe now also keeps the owner column as yours and moves only the parent document. Three owner policies (document_labels, document_sections, document_memory_cards) check owner_id but not the parent document's owner. Browser roles have no grant on these tables and the server routes check document ownership first, so this is unreachable today. The test records the three tables as a known gap and fails if the list stops matching in either direction. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
A permissive insert policy scoped to one bucket is now caught; proven by planting one on clinical-images only. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
|
Code review by qodo was updated up to the latest commit a295ac3 |
|
Generated by Claude Code |
… row per table A direct psql -f run without -1 now rolls the roster fixtures back too. distinct on uses a typed constant, so non-storage tables probe one row. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
Code Review ✅ Approved 3 closed / 3 findings🟡 Medium risk · Adding privacy probes to migration-replay CI could block database PRs if emulator behavior differs from the test assumptions. Adds a two-user database privacy test that signs in as two synthetic doctors and checks privacy rules by querying, and runs all SQL behaviour tests in the Migration replay CI job. Insert probing on the other doctor's document is resolved. One open minor finding: ✅ 3 closed✅ Edge Case: Insert probe never tries own owner_id on the other doctor's document
Closed: Edge Case: Coverage guard misses policies with no TO clause (PUBLIC)
Closed: Edge Case: DISTINCT ON (1) means column 1, so non-storage tables probe every row
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Approved For more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Important Your trial ends in 6 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more. Was this helpful? React with 👍 / 👎 | Gitar |
|
Code review by qodo was updated up to the latest commit 09bbbad |
User description
Requested by Josh · project thread
Summary
Before: nothing signed in as two different users and checked the database's privacy rules by actually querying. The four SQL behaviour tests in
tests/sql/were never run by CI, and one of them (enrichment-repair.sql) had gone stale and failed.After:
tests/sql/two-user-privacy.sqlsigns in as two synthetic doctors and proves, by querying, that:anon,authenticated) hold no privilege on anypublictable, view or sequence, and every read, insert and delete each role attempts on every table is refused. Work mode data (roster, on call, CPD, teaching, admin) is reachable only through server routes.anon, and the four administrator ones refuse an ordinary doctor.All five
tests/sqlfiles now run in the Migration replay CI job against the full migration chain, and locally withnpm run test:sql(bare-image replay ofschema.sql, Docker only, no provider).tests/sql/**now selects the database CI scope.No migration and no live database change. No policy or grant changed; no gap was found that needed one.
Areas touched: Data platform and access (test, runner), Delivery (CI step, scope pattern, npm script), Source intake (fixture repair only).
Verification
npm run test:sql:All 5 SQL behaviour tests passed.includingTWO_USER_PRIVACY_SQL_PASS.supabase migration up --local(309 migrations): all five files printed their pass line.authenticated, granting a function toanonorauthenticated, opening the documents, chunks or storage read policy, and adding an uncovered policy were each caught with aPRIVACY LEAKor coverage error.npm run test:Test Files 1882 passed (1882),Tests 29901 passed | 5 skipped.typecheck,check:migration-role,check:gate-manifest,check:function-grants,check:owner-scope,check:diff-integrity,check:verification-planpassed; eslint and prettier clean on changed files.Risk and rollout
Notes
check:owner-scopeand the nightly staging cross-tenant harness, not by this test.src/lib/supabase/admin.tsstill lacks aserver-onlyguard. Not added here because the ingestion worker and scripts import it in plain Node, whereserver-onlythrows; it needs its own small change.🤖 Generated with Claude Code
https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n
Generated by Claude Code
Summary by cubic
Adds a two-user database privacy test that signs in as two synthetic doctors and proves the privacy rules by querying, and starts running the SQL behaviour tests in CI.
Previously the four SQL behaviour tests in
tests/sql/never ran in CI, andenrichment-repair.sqlhad gone stale and failed. Now all five run in the Migration replay CI job and locally vianpm run test:sql(a disposable Docker replay ofschema.sql, never the live database), andtests/sql/**selects the database CI scope. The test proves browser roles hold no privilege on any public relation, that only five reviewed functions are callable by a signed-in user (four administrator ones refuse an ordinary doctor), and that every owner policy, including PUBLIC (no TO clause) ones, isolates the two doctors when a grant is simulated. A new browser-facing policy without coverage fails the test.Hardening
enrichment-repair.sqlfixtures for the newer lease-tuple checks, and makesroster-behaviour.sqlroll back its fixtures even on a directpsql -frun.owner_id, not parent document ownership, so the probe skips those; the test fails if the gap list drifts in either direction.No migration or live database change; no policy or grant changed.
Written for commit 09bbbad. Summary will update on new commits.
CodeAnt-AI Description
Run two-user database privacy checks in CI and locally
What Changed
Impact
✅ Cross-user privacy regressions caught in CI✅ SQL behavior failures block migration replay checks✅ Local database checks avoid live data💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit