From b8190c44a89c56fac0ba25a1167ebd6eacba12ec Mon Sep 17 00:00:00 2001 From: Neuro Assassin <42872277+NeuroAssassin@users.noreply.github.com> Date: Mon, 22 Apr 2019 18:43:02 -0400 Subject: [PATCH] [Dev] Sanitize API tokens in debug and eval (#2585) * Sanitize API tokens in debug and eval * Not sure what happened there --- redbot/core/dev_commands.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/redbot/core/dev_commands.py b/redbot/core/dev_commands.py index a32fe2446..ee06bec08 100644 --- a/redbot/core/dev_commands.py +++ b/redbot/core/dev_commands.py @@ -61,13 +61,18 @@ class Dev(commands.Cog): return pagify(msg, delims=["\n", " "], priority=True, shorten_by=10) @staticmethod - def sanitize_output(ctx: commands.Context, input_: str) -> str: + def sanitize_output(ctx: commands.Context, keys: dict, input_: str) -> str: """Hides the bot's token from a string.""" token = ctx.bot.http.token r = "[EXPUNGED]" result = input_.replace(token, r) result = result.replace(token.lower(), r) result = result.replace(token.upper(), r) + for provider, data in keys.items(): + for name, key in data.items(): + result = result.replace(key, r) + result = result.replace(key.upper(), r) + result = result.replace(key.lower(), r) return result @commands.command() @@ -121,7 +126,8 @@ class Dev(commands.Cog): self._last_result = result - result = self.sanitize_output(ctx, str(result)) + api_keys = await ctx.bot.db.api_tokens() + result = self.sanitize_output(ctx, api_keys, str(result)) await ctx.send_interactive(self.get_pages(result), box_lang="py") @@ -185,7 +191,8 @@ class Dev(commands.Cog): msg = "{}{}".format(printed, result) else: msg = printed - msg = self.sanitize_output(ctx, msg) + api_keys = await ctx.bot.db.api_tokens() + msg = self.sanitize_output(ctx, api_keys, msg) await ctx.send_interactive(self.get_pages(msg), box_lang="py")