From 83b22560ebbfef66c636a9231f8e05d3fb9413b8 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 27 Jan 2023 09:07:58 +0200 Subject: [PATCH] dont use abort in chat --- files/helpers/regex.py | 2 +- files/helpers/sanitize.py | 12 +++++++++--- files/routes/chat.py | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 77836ed8e..2f0fb5f98 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -192,4 +192,4 @@ def command_regex_matcher(match, upper=False): reason_regex = re.compile('(/(post|comment)/[0-9]+)', flags=re.A) -discord_username_regex = re.compile("(\s|^).{2,32}#[0-9]{4}(?=\s|$)", flags=re.A) +discord_username_regex = re.compile("(\s|^|>).{2,32}#[0-9]{4}(?=[^0-9]|$)", flags=re.A) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 430d778bd..5ea345ffc 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -265,7 +265,7 @@ def handle_youtube_links(url): return html @with_sigalrm_timeout(10) -def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys=False, torture=False, sidebar=False, snappy=False): +def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys=False, torture=False, sidebar=False, snappy=False, chat=False): sanitized = sanitized.strip() sanitized = utm_regex.sub('', sanitized) @@ -422,14 +422,20 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys d = tldextract.extract(href).registered_domain + url.path domain_list.add(d.lower()) + def error(error): + if chat: + return error, 403 + else: + abort(403, error) + banned_domains = g.db.query(BannedDomain).all() for x in banned_domains: for y in domain_list: if y.startswith(x.domain): - abort(403, f'Remove the banned link "{x.domain}" and try again!\nReason for link ban: "{x.reason}"') + return error(f'Remove the banned link "{x.domain}" and try again!\nReason for link ban: "{x.reason}"') if discord_username_regex.match(sanitized): - abort(403, "Stop grooming!") + return error("Stop grooming!") if '
' not in sanitized and not sidebar:
 		sanitized = sanitized.replace('\n','')
diff --git a/files/routes/chat.py b/files/routes/chat.py
index 7833ca2ca..02aac2ec6 100644
--- a/files/routes/chat.py
+++ b/files/routes/chat.py
@@ -68,7 +68,10 @@ def speak(data, v):
 	if image: text += f'\n\n![]({image})'
 	if not text: return '', 400
 
-	text_html = sanitize(text, count_marseys=True)
+	text_html = sanitize(text, count_marseys=True, chat=True)
+	if isinstance(text_html , tuple):
+		return text_html
+
 	quotes = data['quotes']
 	id = str(uuid.uuid4())