Skip to content

fix(platform): gate member bulk-select and guard self-removal (#2043) - #2247

Merged
yannickmonney merged 1 commit into
mainfrom
tale/xs71kfkar3ahm1amyxdzzp0zsh89azq4
Jun 29, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
tale/xs71kfkar3ahm1amyxdzzp0zsh89azq4

Conversation

@larryro

@larryro larryro commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the ungated member bulk-select and the missing backend self-removal guard reported in #2043.

Previously, in the Org settings Members table, the bulk-select checkbox was rendered for every row — including the current user's own row and the owner row — even though the single-row action menu hides Delete for self and owner. And removeMember had no authUser.userId === member.userId check, so an admin could delete their own membership, causing a self-lockout plus an irreversible cascadeOnMemberRemoved wipe of their own userMemories/userPreferences/org-scoped TTS.

Changes

  • Frontend (member-table.tsx): replaced the bare enableRowSelection boolean with a per-row predicate that mirrors the single-row Delete gating — the current-user row and the owner row are no longer selectable for bulk-delete. Uses the same enableRowSelection={(row) => ...} shape already used by agents-table.tsx and typed on DataTable.
  • Backend (members/mutations.ts): added a self-removal guard in removeMember — throws You cannot remove your own membership when member.userId === authUser.userId, as defense in depth regardless of how the request is issued.
  • Test (members/mutations.test.ts): added a regression test asserting an admin cannot remove their own membership and that no deletion is attempted.

Verification

  • bunx vitest --run --project server convex/members/mutations.test.ts → 22 passed
  • bunx tsc --noEmit → 0 errors
  • bunx oxlint --type-aware on changed files → 0 warnings, 0 errors

Closes #2043

@larryro

larryro commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Desk Review — PR #2247 (fixes #2043)

Verdict: READY TO MERGE.

Two-round review (5 breadth subagents across correctness/robustness/elegance/tests/boundaries, then independent confirmation of every blocking candidate). The change cleanly satisfies both halves of the issue.

CI

All 47 required checks pass (Type check, Lint, Unit, UI, Build platform/convex, Playwright platform 1–16, Smoke test, etc.); the remaining jobs (Trivy, fork-PR/container variants) are skipping as expected. No red, no pending.

Tests

Ran bunx vitest --run --project server convex/members/mutations.test.ts → 22 passed. The new case removeMember handler > throws when an admin tries to remove their own membership was confirmed to exercise the new guard (AUTH_USER._id='user_caller' → identity.subject → authUser.userId matches member.userId='user_caller'; owner/admin guards don't fire first) and asserts ctx.runMutation is never called.

What was verified

  • Backend guard (members/mutations.ts:181-183) — if (member.userId === authUser.userId) throw 'You cannot remove your own membership'. Correctly positioned AFTER the owner check and BEFORE deleteOne/deleteMemberMirrorByMemberId/cascadeOnMemberRemoved, so no destructive cascade or audit entry runs on a self-removal. authUser.userId is the JWT identity.subject via getAuthUserIdentity — the right field. Enforced for every caller path.
  • Owner-removes-self is correctly caught by the pre-existing owner guard (line 172) first — consistent, not a gap.
  • No bypass: the org-member removeMember has a single guarded caller path (settings table + delete dialog). team_members.removeMember is a separate mutation (out of scope) and SCIM removeMembers is unrelated group-patch terminology.
  • Frontend predicate (member-table.tsx:174-177) mirrors the single-row Delete gating in member-row-actions.tsx:46,48 exactly (self by _id, owner by role.toLowerCase()==='owner'), matches the issue's prescribed expression, and follows the established agents-table.tsx prior art.
  • Select-all does NOT bypass the gate (a ROUND-1 candidate, refuted): in @tanstack/react-table 8.21.3, toggleAllPageRowsSelected → mutateRowIsSelected only selects rows where row.getCanSelect() is true, and getCanSelect invokes the enableRowSelection predicate. Header select-all skips the self/owner rows.

Non-blocking observations (not required for merge)

  1. member-table.tsx:174-177 — if memberContext is null/undefined the predicate fails open (all rows selectable). Mitigated three ways: the page is access-controlled to org members, the single-row gating shares the same memberContext?.member?._id dependency, and the backend guard catches self-removal regardless — strictly better than the prior bare enableRowSelection boolean. A defensive !!memberContext?.member && … would tighten it but isn't necessary.
  2. No frontend unit test for the selection predicate. There is no repo convention for testing enableRowSelection on any table, and the security-critical backend path is tested — acceptable as-is.

READY TO MERGE.

@yannickmonney
yannickmonney merged commit 2355c89 into main Jun 29, 2026
51 checks passed
@yannickmonney
yannickmonney deleted the tale/xs71kfkar3ahm1amyxdzzp0zsh89azq4 branch June 29, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Member bulk-select is ungated (self + owner rows selectable) and removeMember has no self-removal backend guard

2 participants