From c7ee771e74a768d8acdd165d52605e00a2893fa5 Mon Sep 17 00:00:00 2001 From: Noelle Wang <73260931+No767@users.noreply.github.com> Date: Sat, 2 Nov 2024 22:54:25 -0700 Subject: [PATCH] Ignore all `aiohttp.ContentTypeError` occurrences (#228) --- bot/libs/utils/tree.py | 14 ++++++++++---- changelog.md | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bot/libs/utils/tree.py b/bot/libs/utils/tree.py index f4107f3..14ceeb3 100644 --- a/bot/libs/utils/tree.py +++ b/bot/libs/utils/tree.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING +import aiohttp import discord from discord import app_commands @@ -71,11 +72,16 @@ async def on_error( interaction.command.qualified_name, # type: ignore exc_info=original, ) - if interaction.response.is_done(): - await interaction.followup.send( - embed=FullErrorEmbed(error), ephemeral=True - ) + + # Basically just ignore all content type errors for responses + # Since we already have them printed to stderr, it makes no sense to send a response back to the user when a response is already sent. + # In this case, it actually does more harm by giving the attackers more information than less. + if ( + isinstance(original, aiohttp.ContentTypeError) + and original.status == 0 + ): return + await interaction.response.send_message( embed=FullErrorEmbed(error), ephemeral=True ) diff --git a/changelog.md b/changelog.md index db105b1..b92004f 100644 --- a/changelog.md +++ b/changelog.md @@ -18,7 +18,7 @@ - Use proper type checking imports (https://github.com/No767/Catherine-Chan/pull/216) - Fix exception violations with pronouns tester (https://github.com/No767/Catherine-Chan/pull/212) - Migrate from Bandit, Black, Autoflake and Isort to Ruff (https://github.com/No767/Catherine-Chan/pull/218, https://github.com/No767/Catherine-Chan/pull/223) -- Prevent unsanitized queries from creating Cloudflare errors (https://github.com/No767/Catherine-Chan/pull/226, https://github.com/No767/Catherine-Chan/pull/227) +- Prevent unsanitized queries from creating Cloudflare errors (https://github.com/No767/Catherine-Chan/pull/226, https://github.com/No767/Catherine-Chan/pull/227, https://github.com/No767/Catherine-Chan/pull/228) ## ✨ Additions