Skip to content

Commit

Permalink
fix: [username search] check if username is valid + add missing disco…
Browse files Browse the repository at this point in the history
…rd subtype
  • Loading branch information
Terrtia committed Feb 19, 2025
1 parent aaec6cf commit 129654e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/lib/ail_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
10 changes: 10 additions & 0 deletions bin/lib/objects/abstract_subtype_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions bin/lib/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_")

## ##

Expand Down
3 changes: 3 additions & 0 deletions var/www/blueprints/objects_subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 129654e

Please sign in to comment.