Skip to content

Commit 4a31c26

Browse files
committed
Prevent banned setnames
1 parent 891a346 commit 4a31c26

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

adapters/discord/commands/comp/name_commands.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
from application.services.config_service import ConfigService
2929

3030
MAX_LEN = 50
31-
INVALID_PAT = re.compile(r"[@]")
31+
INVALID_PAT = re.compile(
32+
r"@|(?:https?://|www\.)\S+|\*{2,}|\|{2,}|`+|_{2,}|~{2,}", re.IGNORECASE)
3233

3334

3435
class NameCommands(commands.Cog):
@@ -55,7 +56,7 @@ def __init__(
5556
5657
Parameters:
5758
`member`: The member whose name to change.
58-
`name`: The name. Length must be at most 50 characters, and the name may not contain `@`.
59+
`name`: The name. Length must be at most 50 characters, and the name may not contain `@`, links or discord markdown.
5960
"""),
6061
)
6162

@@ -77,7 +78,7 @@ async def set_name(
7778
"""
7879
# 1) Validate input
7980
if len(new_name) > MAX_LEN or INVALID_PAT.search(new_name):
80-
return await ctx.send("Invalid name (max 50 chars, no '@').")
81+
return await ctx.send("Invalid name (max 50 chars, no '@', no links, no discord markdown).")
8182

8283
# 2) Update in domain
8384
try:
@@ -102,7 +103,7 @@ async def set_name(
102103
Changes your team name in a collab task.
103104
104105
Parameters:
105-
`name`: The team name. Length must be at most 50 characters, and the name may not contain `@`.
106+
`name`: The team name. Length must be at most 50 characters, and the name may not contain `@`, links or discord markdown.
106107
"""),
107108
)
108109
async def set_team_name(
@@ -119,17 +120,17 @@ async def set_team_name(
119120
"""
120121
# 1) Validate input
121122
if len(new_team_name) > MAX_LEN or INVALID_PAT.search(new_team_name):
122-
return await ctx.send("Invalid team name (max 50 chars, no '@').")
123+
return await ctx.send("Invalid team name (max 50 chars, no '@', no links or discord markdown).")
123124

124125
# 2) Must have an active team-based competition
125126
task = await self.task_mgr.get_active_task()
126127
if not task:
127-
return await ctx.send("There is no active task")
128+
return await ctx.send("There is no active task.")
128129
if task.team_size <= 1:
129130
return await ctx.send("This task is not a collab task.")
130131

131132
# 3) Resolve the guild (single-guild instance)
132-
# If run from a server, use that guild; otherwise, take the first connected guild.
133+
# If run from a server, use that guild; otherwise, take the first connected guild.
133134
if ctx.guild is not None:
134135
guild = ctx.guild
135136
else:

adapters/discord/utils/submission_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ async def refresh_submission_list(
109109
except discord.HTTPException:
110110
pass
111111

112-
await channel.send(content)
112+
await channel.send(content, allowed_mentions=discord.AllowedMentions.none(), suppress_embeds=True)

0 commit comments

Comments
 (0)