Impact
A logic flaw exists in the message command handler of CommandKit that affects how the commandName property is exposed to both middleware functions and command execution contexts when handling command aliases. When a message command is invoked using an alias, the ctx.commandName value reflects the alias rather than the canonical command name. This occurs in both middleware functions and within the command’s own run function.
Although not explicitly documented, CommandKit’s examples and guidance around middleware usage implicitly convey that ctx.commandName represents the canonical command identifier. Middleware examples in the documentation consistently use ctx.commandName to reference the command being executed, and the documentation describes middleware as suitable for “logging, authentication, permission checks, or any other cross-cutting concerns.” As a result, developers reasonably expect ctx.commandName to return the canonical command name and may rely on it for security-sensitive logic.
Developers who assume ctx.commandName is canonical may introduce unintended behavior when relying on it for logic such as permission checks, rate limiting, or audit logging. This could allow unauthorized command execution or inaccurate access control decisions. Slash commands and context menu commands are not affected.
Patches
Fixed in v1.2.0-rc.12.
ctx.commandName now consistently returns the actual canonical command name, regardless of the alias used to invoke it.
Workaround
If upgrading isn't immediately possible:
- Use
ctx.command.data.command.name for permission validations, or
- Include all command aliases in your permission logic.
References
Impact
A logic flaw exists in the message command handler of CommandKit that affects how the
commandNameproperty is exposed to both middleware functions and command execution contexts when handling command aliases. When a message command is invoked using an alias, thectx.commandNamevalue reflects the alias rather than the canonical command name. This occurs in both middleware functions and within the command’s own run function.Although not explicitly documented, CommandKit’s examples and guidance around middleware usage implicitly convey that
ctx.commandNamerepresents the canonical command identifier. Middleware examples in the documentation consistently usectx.commandNameto reference the command being executed, and the documentation describes middleware as suitable for “logging, authentication, permission checks, or any other cross-cutting concerns.” As a result, developers reasonably expectctx.commandNameto return the canonical command name and may rely on it for security-sensitive logic.Developers who assume
ctx.commandNameis canonical may introduce unintended behavior when relying on it for logic such as permission checks, rate limiting, or audit logging. This could allow unauthorized command execution or inaccurate access control decisions. Slash commands and context menu commands are not affected.Patches
Fixed in v1.2.0-rc.12.
ctx.commandNamenow consistently returns the actual canonical command name, regardless of the alias used to invoke it.Workaround
If upgrading isn't immediately possible:
ctx.command.data.command.namefor permission validations, orReferences