Conversation
The remove-person permission check admits the owner through the self-change arm, so a replayed DELETE /users/:id with the owner's own id left the account with no owner and no way to get one back: a join-code rejoin creates a fresh member. Refuse the request when the user is the account's only active owner, after the existing permission gate so admins are still forbidden outright, and keep self-removal for admins and members.
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. |
There was a problem hiding this comment.
🟡 Changes recommended
sole_owner? currently misclassifies inactive users as sole owners.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Prevents an account’s sole owner from deactivating themself through the users endpoint.
Changes:
- Adds sole-owner detection and controller enforcement.
- Covers HTML/JSON behavior and role scenarios.
- Documents new API error responses.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
File summaries
| File | Description |
|---|---|
app/models/user/role.rb |
Adds sole-owner detection. |
app/controllers/users_controller.rb |
Blocks sole-owner deactivation. |
test/models/user/role_test.rb |
Tests owner-role scenarios. |
test/controllers/users_controller_test.rb |
Tests deactivation outcomes. |
docs/api/sections/users.md |
Documents 403 and 422 responses. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
An account's owner could deactivate themself by replaying the remove-person request with their own user id. The UI never offers it (the remove button is disabled for yourself), but
UsersController#destroyis gated bycan_change?, whoseother == selfarm admits the owner. The result is an account with no owner and no way to get one back: nobody left can cancel the account or change settings, and rejoining via join code creates a fresh member. Surfaced by a bug bounty report; closed as self-exploitation, but it is a foot-gun worth removing.Change
User#sole_owner?: the user is an active owner and the account has no other active owner.UsersController#destroyrefuses when the target is the sole owner: HTML redirects to account settings with an alert, JSON responds422 Unprocessable Entity. The check runs after the existing permission gate, so an admin trying to remove the owner is still403 Forbidden.403and422responses forDELETE /:account_slug/users/:user_id.What stays the same
User#deactivateis untouched.Identity#before_destroydeactivates every user of the identity, owners included, and that path must keep working, so the rule sits at the request boundary rather than inside the model operation.Not done on purpose
Tests
sole_owner?across owner/admin/member, a second owner, and a deactivated second owner.