From 99a5786112c440c2091aa18bff860bab5a8c16ac Mon Sep 17 00:00:00 2001 From: "Nikita Tyukalov, ASUS, Linux" Date: Tue, 25 Nov 2025 05:03:43 +0300 Subject: [PATCH] Fixed improper whitelisting --- mod_chat_sanitizer.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/mod_chat_sanitizer.py b/mod_chat_sanitizer.py index fdf4e1b..31d5976 100644 --- a/mod_chat_sanitizer.py +++ b/mod_chat_sanitizer.py @@ -105,6 +105,8 @@ async def _violent_worker(data: dict) -> None: if is_text_forbidden(res[i].message.lower(), blacklist, whitelist): messages_to_delete.append(res[i].id) continue + if is_text_whitelisted(res[i].message.lower(), whitelist): + continue # names are not to be checked if not data['check_names']: continue @@ -115,6 +117,8 @@ async def _violent_worker(data: dict) -> None: if name: if sender.last_name is not None: name += ' ' + sender.last_name + if is_text_whitelisted(name.lower(), whitelist): + continue if is_text_forbidden(name.lower(), blacklist, whitelist): messages_to_delete.append(res[i].id) continue @@ -137,6 +141,8 @@ async def _violent_worker(data: dict) -> None: if name_to_check: if sender.last_name is not None: name_to_check += ' ' + sender.last_name + if name_to_check is not None and is_text_whitelisted(name.lower(), whitelist): + continue if name_to_check is not None and is_text_forbidden(name_to_check.lower(), blacklist, whitelist): messages_to_delete.append(res[i].id) continue @@ -213,18 +219,29 @@ def mod_get_config_for_session(session_name) -> dict: _mod_config[session_name] = c return c +def is_text_whitelisted(text, whitelist) -> bool: + ''' Returns True if text contains something from whitelist ''' + # check if has whitelisted content + for word in whitelist: + # whitelisted content exists + if word in text.lower(): + return True + # forbidden + return False + + def is_text_forbidden(text, blacklist, whitelist) -> bool: ''' Returns True or False ''' # check if has blacklisted content for word in blacklist: - if word in text: + if word in text.lower(): break else: return False # check if has whitelisted content for word in whitelist: # whitelisted content exists - if word in text: + if word in text.lower(): return False # forbidden return True