Skip to content

Commit 161d928

Browse files
Drop newlines and url unquote messages before passing through invite filter (#3184)
1 parent aebc88a commit 161d928

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

bot/exts/filtering/_filter_lists/invite.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ async def actions_for(
6262
"""Dispatch the given event to the list's filters, and return actions to take and messages to relay to mods."""
6363
text = clean_input(ctx.content)
6464

65-
# Avoid escape characters
66-
text = text.replace("\\", "")
67-
6865
matches = list(DISCORD_INVITE.finditer(text))
6966
invite_codes = {m.group("invite") for m in matches}
7067
if not invite_codes:

bot/exts/filtering/_utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import inspect
66
import pkgutil
77
import types
8+
import urllib.parse
89
import warnings
910
from abc import ABC, abstractmethod
1011
from collections import defaultdict
@@ -55,8 +56,16 @@ def clean_input(string: str) -> str:
5556
# For future consideration: remove characters in the Mc, Sk, and Lm categories too.
5657
# Can be normalised with form C to merge char + combining char into a single char to avoid
5758
# removing legit diacritics, but this would open up a way to bypass _filters.
58-
no_zalgo = ZALGO_RE.sub("", string)
59-
return INVISIBLE_RE.sub("", no_zalgo)
59+
content = ZALGO_RE.sub("", string)
60+
61+
# URL quoted strings can be used to hide links to servers
62+
content = urllib.parse.unquote(content)
63+
# Drop newlines that can be used to bypass filter
64+
content = content.replace("\n", "")
65+
# Avoid escape characters
66+
content = content.replace("\\", "")
67+
68+
return INVISIBLE_RE.sub("", content)
6069

6170

6271
def past_tense(word: str) -> str:

0 commit comments

Comments
 (0)