Skip to content

Commit 4ec3c35

Browse files
fix(autoban): log message and attachment urls (#513)
1 parent 74738ba commit 4ec3c35

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/discord_bot/cogs/autoban.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ async def on_message(self, message: discord.Message):
5252
reason="Automatic ban: posted in restricted channel.",
5353
delete_message_seconds=604800, # Delete messages from the past 7 days
5454
)
55+
# repr() sanitizes the content, escaping newlines and other special characters
56+
# to prevent log injection attacks.
57+
safe_content = repr(message.content)
58+
attachment_urls = [a.url for a in message.attachments]
5559
logger.warning(
56-
"Auto-banned user %s (%s) for posting in channel %s (%s).",
60+
"Auto-banned user %s (%s) for posting in channel %s (%s). "
61+
"Message content: %s. "
62+
"Attachments: %s.",
5763
message.author,
5864
message.author.id,
5965
message.channel.name,
6066
message.channel.id,
67+
safe_content,
68+
attachment_urls,
6169
)
6270
except discord.Forbidden:
6371
logger.error(

0 commit comments

Comments
 (0)