diff --git a/bin/lib/ail_core.py b/bin/lib/ail_core.py index c3277b96..344449eb 100755 --- a/bin/lib/ail_core.py +++ b/bin/lib/ail_core.py @@ -89,7 +89,7 @@ def get_object_all_subtypes(obj_type): # TODO Dynamic subtype if obj_type == 'pgp': return ['key', 'mail', 'name'] if obj_type == 'username': - return ['telegram', 'twitter', 'jabber'] + return ['telegram', 'discord', 'twitter', 'jabber'] if obj_type == 'user-account': return r_object.smembers(f'all_chat:subtypes') return [] diff --git a/bin/lib/objects/abstract_subtype_object.py b/bin/lib/objects/abstract_subtype_object.py index 9598feec..80d132e8 100755 --- a/bin/lib/objects/abstract_subtype_object.py +++ b/bin/lib/objects/abstract_subtype_object.py @@ -22,6 +22,7 @@ from lib.ConfigLoader import ConfigLoader from lib.item_basic import is_crawled, get_item_domain from lib.data_retention_engine import update_obj_date +from lib.telegram import USERNAME_CHARS from packages import Date @@ -254,6 +255,15 @@ def get_metas(self, subtype, obj_ids, options=set()): dict_obj[obj_id] = obj.get_meta(options=options) return dict_obj + def is_valid_search(self, subtypes, id_to_search): + if subtypes == 'telegram': + return set(id_to_search).issubset(USERNAME_CHARS) + elif subtypes == 'discord': + id_to_search = id_to_search.replace('.', '').replace('#', '') + return set(id_to_search).issubset(USERNAME_CHARS) + else: + return True + @abstractmethod def sanitize_id_to_search(self, subtypes, id_to_search): return id_to_search diff --git a/bin/lib/telegram.py b/bin/lib/telegram.py index 02984066..ba687cc8 100755 --- a/bin/lib/telegram.py +++ b/bin/lib/telegram.py @@ -19,6 +19,7 @@ REGEX_USERNAME = re.compile(r'[0-9a-zA-z_]+') REGEX_JOIN_HASH = re.compile(r'[0-9a-zA-z-]+') +USERNAME_CHARS = set("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_") ## ## diff --git a/var/www/blueprints/objects_subtypes.py b/var/www/blueprints/objects_subtypes.py index 01536d7d..ec22cb9e 100644 --- a/var/www/blueprints/objects_subtypes.py +++ b/var/www/blueprints/objects_subtypes.py @@ -151,6 +151,9 @@ def objects_username_search(): page = 1 usernames = Usernames.Usernames() + if not usernames.is_valid_search(subtype, to_search): + return create_json_response({'status': 'error', 'message': 'Invalid Username'}, 400) + search_result = usernames.search_by_id(to_search, [subtype], page, case_sensitive=case_sensitive) if search_result: