Cog-Creators / Red-DiscordBot

A multi-function Discord bot
https://docs.discord.red
GNU General Public License v3.0
4.72k stars 2.3k forks source link

Fix edge case where perm names are not validated in custom Red decos #6291

Closed Flame442 closed 7 months ago

Flame442 commented 7 months ago

Description of the changes

_validate_perms_dict is supposed to be used to validate that the permissions names passed to decorators such as @commands.admin_or_permissions are actual permissions. The get_decorator helper used to build these decorators currently returns a decorator that fails to validate permission names if the decorated object is a coroutine. This causes the check to never properly happen in cases where the decorator executes before @commands.command (ie, if it is on the bottom). This potentially could cause unexpected behavior if a permission name is misspelled when passed to one of these decorators.

Found by @untir_l.

Reproduction example:

import discord
from redbot.core import commands

class Test(commands.Cog):
    @commands.command()
    @commands.admin_or_permissions(NONEXISTENT_PERM=True)
    async def test(self, ctx):
        await ctx.reply("Boop!")

Already properly handled (prevents load):

import discord
from redbot.core import commands

class Test(commands.Cog):
    @commands.admin_or_permissions(NONEXISTENT_PERM=True)
    @commands.command()
    async def test(self, ctx):
        await ctx.reply("Boop!")

Have the changes in this PR been tested?

Yes