fix(maintainer): scope flagged-accounts query at database level (closes #755)#810
Open
arcgod-design wants to merge 1 commit into
Open
Conversation
Contributor
|
@arcgod-design is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel. A member of the Team first needs to authorize it. |
pavsoss
suggested changes
Jul 25, 2026
pavsoss
left a comment
Collaborator
There was a problem hiding this comment.
Please resolve the merge conflicts
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
Closes #755 — replaces the unbounded global load + client-side filter pattern in
getFlaggedAccountswith query-level scoping.Before
src/app/actions/maintainer/flagged-accounts.tsfetched up to 100 rows fromflagged_accountsacross all organizations and then filtered the result in JavaScript:This leaked global row counts via timing side-channels and wasted database resources on every maintainer action call.
After
The user_ids that have activity in the maintainer's repos are resolved first from
pull_requestsandrecommendationsin parallel viaPromise.all. Only those user_ids are then passed to theflagged_accountsquery as an.in('user_id', userIdsFilter)filter — so the database scope is now equivalent to the maintainer's authorized surface, matchingclosePullRequest,requestChanges,getContributorsList, etc. that already scope at query level.If
activeUserIdsis empty, the function short-circuits before ever touchingflagged_accounts, eliminating the entire data-leak surface for maintainers with no in-scope user activity.The JavaScript
evidence.items[].repofilter is retained as defense-in-depth (JSONB containment checks are not portable across Supabase client versions and the column has no GIN index guaranteed).Tests
src/app/actions/maintainer.test.ts— added 5 new regression tests forgetFlaggedAccounts scoping:.in('user_id', ...)call was made with only users that have activity in the maintainer's repos and thatuser-inactiveis not present.flagged_accountstable is never queried at all (flaggedAccountsCallCount === 0).query_failed.query_failed.The 3 existing scoping tests continue to pass unchanged. Total: 117 tests pass in
src/app/actions/maintainer.test.ts.Validation
vitest run src/app/actions/maintainer.test.ts— 117 passedeslint src/app/actions/maintainer/flagged-accounts.ts src/app/actions/maintainer.test.ts— cleanprettier --check— All matched files use Prettier code styletsc --noEmit -p tsconfig.json— no errorsRisk
This change adds one extra round trip to resolve
activeUserIdsbefore theflagged_accountsquery. Trade-off is favourable: it removes the unbounded global load on every maintainer flagged-accounts page load, removes the timing side-channel surface, and alignsgetFlaggedAccountswith every other maintainer action (which already scope at query level). The downstreamprofilesquery andlogMaintainerActionaudit hook are unchanged.