Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop newlines and url unquote messages before passing through invite … #3184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions bot/exts/filtering/_filter_lists/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ async def actions_for(
"""Dispatch the given event to the list's filters, and return actions to take and messages to relay to mods."""
text = clean_input(ctx.content)

# Avoid escape characters
text = text.replace("\\", "")

matches = list(DISCORD_INVITE.finditer(text))
invite_codes = {m.group("invite") for m in matches}
if not invite_codes:
Expand Down
13 changes: 11 additions & 2 deletions bot/exts/filtering/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import inspect
import pkgutil
import types
import urllib.parse
import warnings
from abc import ABC, abstractmethod
from collections import defaultdict
Expand Down Expand Up @@ -55,8 +56,16 @@ def clean_input(string: str) -> str:
# For future consideration: remove characters in the Mc, Sk, and Lm categories too.
# Can be normalised with form C to merge char + combining char into a single char to avoid
# removing legit diacritics, but this would open up a way to bypass _filters.
no_zalgo = ZALGO_RE.sub("", string)
return INVISIBLE_RE.sub("", no_zalgo)
content = ZALGO_RE.sub("", string)

# URL quoted strings can be used to hide links to servers
content = urllib.parse.unquote(content)
# Drop newlines that can be used to bypass filter
content = content.replace("\n", "")
# Avoid escape characters
content = content.replace("\\", "")

return INVISIBLE_RE.sub("", content)


def past_tense(word: str) -> str:
Expand Down