From 4138410d3344ec1e4c7b110fd04af086c987fa0e Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Wed, 20 Jan 2021 21:32:59 +0100 Subject: [PATCH] Ensure no role hierarchy bypassing in Mutes (#4741) * Ensure no role hierarchy bypassing on bad role configuration * Do the same for `[p]muteset role` --- redbot/cogs/mutes/mutes.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/redbot/cogs/mutes/mutes.py b/redbot/cogs/mutes/mutes.py index 9ef3de995..6243a2fed 100644 --- a/redbot/cogs/mutes/mutes.py +++ b/redbot/cogs/mutes/mutes.py @@ -28,6 +28,9 @@ MUTE_UNMUTE_ISSUES = { "hierarchy_problem": _( "I cannot let you do that. You are not higher than the user in the role hierarchy." ), + "assigned_role_hierarchy_problem": _( + "I cannot let you do that. You are not higher than the mute role in the role hierarchy." + ), "is_admin": _("That user cannot be muted, as they have the Administrator permission."), "permissions_issue_role": _( "Failed to mute or unmute user. I need the Manage Roles " @@ -684,6 +687,11 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass): # removed the mute role await ctx.send(_("Channel overwrites will be used for mutes instead.")) else: + if role >= ctx.author.top_role: + await ctx.send( + _("You can't set this role as it is not lower than you in the role hierarchy.") + ) + return await self.config.guild(ctx.guild).mute_role.set(role.id) self.mute_role_cache[ctx.guild.id] = role.id await ctx.send(_("Mute role set to {role}").format(role=role.name)) @@ -1331,6 +1339,9 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass): if not role: ret["reason"] = _(MUTE_UNMUTE_ISSUES["role_missing"]) return ret + if author != guild.owner and role >= author.top_role: + ret["reason"] = _(MUTE_UNMUTE_ISSUES["assigned_role_hierarchy_problem"]) + return ret if not guild.me.guild_permissions.manage_roles or role >= guild.me.top_role: ret["reason"] = _(MUTE_UNMUTE_ISSUES["permissions_issue_role"]) return ret