fix(security): gate rank admin subcommands and guard ban/kick null members - #151
Merged
Merged
Conversation
…mbers - Require ManageGuild for /rank reset and /rank set (missed in #130 hardening) - Ban users not currently in guild via guild.members.ban instead of crashing - Reject /kick when target is not a guild member before accessing kickable - Add regression tests for both fixes Co-authored-by: Daan Vrieling <contact@zvapor.xyz>
zVapor-Dev
marked this pull request as ready for review
September 16, 2026 22:51
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
Critical bug inspection found two high-severity issues missed during the #130 security hardening pass.
Bug 1 — Unauthorized
/rank resetand/rank set(Critical)Impact: Any guild member could reset or arbitrarily set another user's XP/level.
Root cause: PR #130 added Discord permission gates to moderation commands but
/rank resetand/rank setwere never gated. The global validator only checksuserPermissionswhen defined on the command module.Fix: Require
ManageGuildvia existingdenyUnlessManageGuildhelper before database writes in reset/set subcommands./rank inforemains available to all members.Trigger:
/rank reset user:@targetor/rank set user:@target level:999as a regular member.Bug 2 —
/banand/kickcrash on null member (High)Impact: Moderation commands throw
TypeError: Cannot read properties of nullwhen the target user is not a current guild member, breaking moderation workflows.Root cause:
interaction.options.getMember("user")returnsnullfor users who left or were never cached, but code accessedmember.bannable/member.kickablewithout a guard (unlike/timeout).Fix:
guild.members.ban(user)when member is null (supports banning users not currently in the server).Trigger: Moderator runs
/banor/kickon a user ID who is not currently in the guild.Validation
npm test— 51/51 passingtests/rank-admin-gate.test.js,tests/moderation-null-member.test.js