More validation on movedTo

main
Bob Mottram 2025-12-13 16:30:58 +00:00
parent 0bc1db1631
commit bda422305f
8 changed files with 56 additions and 28 deletions

View File

@ -1752,7 +1752,8 @@ def _profile_post_moved(actor_json: {}, fields: {},
for fieldname in fieldnames: for fieldname in fieldnames:
moved_to = '' moved_to = ''
if actor_json.get(fieldname): if actor_json.get(fieldname):
moved_to = actor_json[fieldname] if isinstance(actor_json[fieldname], str):
moved_to = remove_html(actor_json[fieldname])
if fields.get(fieldname): if fields.get(fieldname):
if fields[fieldname] != moved_to and \ if fields[fieldname] != moved_to and \

View File

@ -671,13 +671,15 @@ def show_person_options(self, calling_domain: str, path: str,
self.server.person_cache) self.server.person_cache)
if actor_json: if actor_json:
if actor_json.get('movedTo'): if actor_json.get('movedTo'):
moved_to = actor_json['movedTo'] if isinstance(actor_json['movedTo'], str):
if '"' in moved_to: moved_to = remove_html(actor_json['movedTo'])
moved_to = moved_to.split('"')[1] if '"' in moved_to:
moved_to = moved_to.split('"')[1]
elif actor_json.get('copiedTo'): elif actor_json.get('copiedTo'):
moved_to = actor_json['copiedTo'] if isinstance(actor_json['copiedTo'], str):
if '"' in moved_to: moved_to = remove_html(actor_json['copiedTo'])
moved_to = moved_to.split('"')[1] if '"' in moved_to:
moved_to = moved_to.split('"')[1]
if actor_json.get('type'): if actor_json.get('type'):
if actor_json['type'] == 'Group': if actor_json['type'] == 'Group':
is_group = True is_group = True

View File

@ -1002,10 +1002,12 @@ def _desktop_show_actor(http_prefix: str,
_say_command(say_str, say_str, screenreader, system_language, espeak) _say_command(say_str, say_str, screenreader, system_language, espeak)
print(actor) print(actor)
if actor_json.get('movedTo'): if actor_json.get('movedTo'):
say_str = 'Moved to ' + html.unescape(actor_json['movedTo']) moved_url = html.unescape(actor_json['movedTo'])
say_str = 'Moved to ' + remove_html(moved_url)
_say_command(say_str, say_str, screenreader, system_language, espeak) _say_command(say_str, say_str, screenreader, system_language, espeak)
elif actor_json.get('copiedTo'): elif actor_json.get('copiedTo'):
say_str = 'Copied to ' + html.unescape(actor_json['copiedTo']) moved_url = html.unescape(actor_json['copiedTo'])
say_str = 'Copied to ' + remove_html(moved_url)
_say_command(say_str, say_str, screenreader, system_language, espeak) _say_command(say_str, say_str, screenreader, system_language, espeak)
if actor_json.get('alsoKnownAs'): if actor_json.get('alsoKnownAs'):
also_known_as_str = '' also_known_as_str = ''

View File

@ -250,9 +250,11 @@ def _person_receive_update(base_dir: str,
person_has_moved_url = None person_has_moved_url = None
if person_json.get('movedTo'): if person_json.get('movedTo'):
person_has_moved_url = person_json['movedTo'] if isinstance(person_json['movedTo'], str):
person_has_moved_url = remove_html(person_json['movedTo'])
elif person_json.get('copiedTo'): elif person_json.get('copiedTo'):
person_has_moved_url = person_json['copiedTo'] if isinstance(person_json['copiedTo'], str):
person_has_moved_url = remove_html(person_json['copiedTo'])
if person_has_moved_url: if person_has_moved_url:
prev_domain_full = None prev_domain_full = None

View File

@ -9,6 +9,7 @@ __module_group__ = "Core"
import os import os
from flags import has_group_type from flags import has_group_type
from utils import remove_html
from utils import data_dir from utils import data_dir
from utils import is_account_dir from utils import is_account_dir
from utils import get_nickname_from_actor from utils import get_nickname_from_actor
@ -114,10 +115,15 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
if not person_json.get('movedTo') and \ if not person_json.get('movedTo') and \
not person_json.get('copiedTo'): not person_json.get('copiedTo'):
return ctr return ctr
moved_to_url = ''
if person_json.get('movedTo'): if person_json.get('movedTo'):
moved_to_url = person_json['movedTo'] if isinstance(person_json['movedTo'], str):
moved_to_url = remove_html(person_json['movedTo'])
else: else:
moved_to_url = person_json['copiedTo'] if isinstance(person_json['copiedTo'], str):
moved_to_url = remove_html(person_json['copiedTo'])
if not moved_to_url:
return ctr
if '://' not in moved_to_url: if '://' not in moved_to_url:
return ctr return ctr
if '.' not in moved_to_url: if '.' not in moved_to_url:

View File

@ -359,10 +359,15 @@ def get_actor_move_json(actor_json: {}) -> {}:
if not actor_json.get('movedTo') and \ if not actor_json.get('movedTo') and \
not actor_json.get('copiedTo'): not actor_json.get('copiedTo'):
return None return None
moved_url = ''
if actor_json.get('movedTo'): if actor_json.get('movedTo'):
moved_url = actor_json['movedTo'] if isinstance(actor_json['movedTo'], str):
moved_url = remove_html(actor_json['movedTo'])
else: else:
moved_url = actor_json['copiedTo'] if isinstance(actor_json['copiedTo'], str):
moved_url = remove_html(actor_json['copiedTo'])
if not moved_url:
return None
if '://' not in moved_url or \ if '://' not in moved_url or \
'.' not in moved_url: '.' not in moved_url:
return None return None

View File

@ -9,6 +9,7 @@ __module_group__ = "Core"
import os import os
from flags import is_dormant from flags import is_dormant
from utils import remove_html
from utils import data_dir from utils import data_dir
from utils import get_user_paths from utils import get_user_paths
from utils import acct_dir from utils import acct_dir
@ -280,10 +281,15 @@ def update_moved_actors(base_dir: str, debug: bool) -> None:
if not actor_json.get('movedTo'): if not actor_json.get('movedTo'):
if not actor_json.get('copiedTo'): if not actor_json.get('copiedTo'):
continue continue
moved_url = ''
if actor_json.get('movedTo'): if actor_json.get('movedTo'):
moved_url = actor_json['movedTo'] if not isinstance(actor_json['movedTo'], str):
moved_url = remove_html(actor_json['movedTo'])
else: else:
moved_url = actor_json['copiedTo'] if not isinstance(actor_json['copiedTo'], str):
moved_url = remove_html(actor_json['copiedTo'])
if not moved_url:
continue
nickname = get_nickname_from_actor(moved_url) nickname = get_nickname_from_actor(moved_url)
if not nickname: if not nickname:
continue continue

View File

@ -352,16 +352,16 @@ def html_profile_after_search(authorized: bool,
moved_to = '' moved_to = ''
if profile_json.get('movedTo') or profile_json.get('copiedTo'): if profile_json.get('movedTo') or profile_json.get('copiedTo'):
if profile_json.get('movedTo'): if profile_json.get('movedTo'):
moved_to = profile_json['movedTo'] if not isinstance(profile_json['movedTo'], str):
moved_to = remove_html(profile_json['movedTo'])
else: else:
moved_to = profile_json['copiedTo'] if not isinstance(profile_json['copiedTo'], str):
if isinstance(moved_to, str): moved_to = remove_html(profile_json['copiedTo'])
if moved_to:
if '"' in moved_to: if '"' in moved_to:
moved_to = moved_to.split('"')[1] moved_to = moved_to.split('"')[1]
moved_to = remove_html(moved_to) moved_to = moved_to
display_name += '' display_name += ''
else:
moved_to = ''
you_follow = \ you_follow = \
is_following_actor(base_dir, is_following_actor(base_dir,
@ -1493,10 +1493,12 @@ def html_profile(signing_priv_key_pem: str,
moved_to = '' moved_to = ''
if profile_json.get('movedTo') or profile_json.get('copiedTo'): if profile_json.get('movedTo') or profile_json.get('copiedTo'):
if profile_json.get('movedTo'): if profile_json.get('movedTo'):
moved_to = profile_json['movedTo'] if isinstance(profile_json['movedTo'], str):
moved_to = remove_html(profile_json['movedTo'])
else: else:
moved_to = profile_json['copiedTo'] if isinstance(profile_json['copiedTo'], str):
if isinstance(moved_to, str): moved_to = remove_html(profile_json['copiedTo'])
if moved_to:
if '"' in moved_to: if '"' in moved_to:
moved_to = moved_to.split('"')[1] moved_to = moved_to.split('"')[1]
else: else:
@ -3481,9 +3483,11 @@ def html_edit_profile(server, translate: {},
actor_json = load_json(actor_filename) actor_json = load_json(actor_filename)
if actor_json: if actor_json:
if actor_json.get('movedTo'): if actor_json.get('movedTo'):
moved_to = actor_json['movedTo'] if isinstance(actor_json['movedTo'], str):
moved_to = remove_html(actor_json['movedTo'])
elif actor_json.get('copiedTo'): elif actor_json.get('copiedTo'):
moved_to = actor_json['copiedTo'] if isinstance(actor_json['copiedTo'], str):
moved_to = remove_html(actor_json['copiedTo'])
featured_hashtags = get_featured_hashtags(actor_json) featured_hashtags = get_featured_hashtags(actor_json)
donate_url = get_donation_url(actor_json) donate_url = get_donation_url(actor_json)
website_url = get_website(actor_json, translate) website_url = get_website(actor_json, translate)