Repository navigation
fix(security): lock users privileged columns + pgTAP policy tests in CI - #38
Merged
Merged
Conversation
Any student could run `update users set is_developer = true` on their own row and pass requireDeveloper() in edge functions, which read names and emails of any section with the service role key. The UPDATE policy pinned role and section_id only. - Revoke INSERT/UPDATE on users from anon and authenticated; grant UPDATE back on the five columns the client writes. Enrollment and CR changes use SECURITY DEFINER RPCs and are unaffected. - Add pgTAP tests in supabase/tests: privileged columns, cross-section isolation, general-poll anonymity. - CI: new db-tests job runs `supabase start` + `supabase test db`. - CD: deploy now needs db-tests; stop cancelling an in-progress db push. - Remove the SELECT 1 placeholder RLS test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
20260606000000 recreated the four announcement_comments policies that 20260601000000 already created, without dropping them first. Prod applied it fine, but `supabase start` on an empty DB fails with 42710 (policy already exists). Both definitions are identical, so dropping first leaves the final state unchanged; prod won't re-run this migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 20260909 policy selected from public.users inside a users policy, so every client UPDATE on users fails with 42P17 (infinite recursion), the same bug 20260524105400 fixed once before. pgTAP caught it on the first real run. The column grant now makes role/section_id unwritable, so the policy only pins the row to its owner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Any student could make themselves a developer from the browser console:
That passes
requireDeveloper()in edge functions.get-analytics-summarythen uses the service role key to return names and emails for anysectionId. The UPDATE policy only pinnedroleandsection_id.The fix replaces "block bad columns" with "allow good columns":
All 12 database functions that write
users(create/join hub, CR promote/transfer, etc.) are SECURITY DEFINER, so they're unaffected. The client writes only those five columns.Pipeline change:
Evidence
rls.test.sqlwasSELECT 1. No policy tests ran anywhere, and migrations went straight to prod.After: see the Database Policy Tests check on this PR. This is the first time all migrations are applied to an empty database. If
supabase startfails, a migration depends on something created by hand in the dashboard, and that needs fixing before merge.users_privileges.test.sqlcheck 1 (update users set is_developer = true→ expects42501) would fail against the current prod schema.Found by the first CI runs
2eca65e).20260606000000recreated fourannouncement_commentspolicies without dropping them first, so an empty DB couldn't be built. I addedDROP POLICY IF EXISTS. Both definitions are identical, so prod is unchanged.a9f81fe). The 20260909 policy selects fromusersinside auserspolicy. Every client UPDATE onusersfails with42P17 infinite recursion(the same bug20260524105400fixed once). This is probably live in prod since Sept 9: the notification toggle, profile preferences and the onboarding phone/batch step. The policy is now a plain own-row check, and the column grant handles which columns are writable.Merge Danger
Door: two-way
Rolling back means re-granting
INSERT, UPDATE ON public.users TO authenticated. No data changes.Blast Radius: profile-writes
If the client writes a
userscolumn that isn't in the allowlist, that write fails with "permission denied". I greppedsrc/and found only those five columns. Before merging, runselect id, email from users where is_developer;in prod to see whether the hole was already used.🤖 Generated with Claude Code