Skip to content

Commit 75d4044

Browse files
committed
fix: vulnerability in error messages being able to ping or mention roles
1 parent d7a92a1 commit 75d4044

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

bot/exts/fun/adventure.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from discord import Embed, HTTPException, Message, Reaction, User
99
from discord.ext import commands
10-
from discord.ext.commands import Cog as DiscordCog, Context
10+
from discord.ext.commands import Cog as DiscordCog, Context, clean_content
1111
from pydis_core.utils.logging import get_logger
1212

1313
from bot import constants
@@ -379,7 +379,14 @@ class Adventure(DiscordCog):
379379
async def new_adventure(self, ctx: Context, game_code_or_index: str | None = None) -> None:
380380
"""Wanted to slay a dragon? Embark on an exciting journey through text-based RPG adventure."""
381381
try:
382-
await GameSession.start(ctx, game_code_or_index)
382+
# prevent malicious pings and mentions
383+
santiser = clean_content(fix_channel_mentions=True)
384+
sanitised_game_code_or_index = await santiser.convert(ctx, game_code_or_index)
385+
386+
# quality of life: if the user accidentally wraps the game code in backticks, process it anyway
387+
sanitised_game_code_or_index = sanitised_game_code_or_index.strip("`")
388+
389+
await GameSession.start(ctx, sanitised_game_code_or_index)
383390
except GameCodeNotFoundError as error:
384391
await ctx.send(str(error))
385392

0 commit comments

Comments
 (0)