From 9840f7bc53a040559cd4ac6a508a667c0c9cf769 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:29:55 +1200 Subject: [PATCH] avoid invalid image json in Actors --- app/activitypub/util.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 881f0ea5..14847612 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -561,11 +561,11 @@ def actor_json_to_model(activity_json, address, server): current_app.logger.error(f'KeyError for {address}@{server} while parsing ' + str(activity_json)) return None - if 'icon' in activity_json: + if 'icon' in activity_json and activity_json['icon'] is not None and 'url' in activity_json['icon']: avatar = File(source_url=activity_json['icon']['url']) user.avatar = avatar db.session.add(avatar) - if 'image' in activity_json: + if 'image' in activity_json and activity_json['image'] is not None and 'url' in activity_json['image']: cover = File(source_url=activity_json['image']['url']) user.cover = cover db.session.add(cover) @@ -625,11 +625,11 @@ def actor_json_to_model(activity_json, address, server): elif 'content' in activity_json: community.description_html = allowlist_html(activity_json['content']) community.description = '' - if 'icon' in activity_json: + if 'icon' in activity_json and activity_json['icon'] is not None and 'url' in activity_json['icon']: icon = File(source_url=activity_json['icon']['url']) community.icon = icon db.session.add(icon) - if 'image' in activity_json: + if 'image' in activity_json and activity_json['image'] is not None and 'url' in activity_json['image']: image = File(source_url=activity_json['image']['url']) community.image = image db.session.add(image)