From e8f7551e061a611267249d5569d25219cf4fff19 Mon Sep 17 00:00:00 2001 From: freamon Date: Sun, 24 Mar 2024 00:15:10 +0000 Subject: [PATCH] Avoiding crashes from adding remotes: If remote community is missing If remote community doesn't have a 'featured' url (e.g. KBIN) If remote community returns empty/broken outbox (e.g. KBIN returns {}) with 200 OK --- app/activitypub/util.py | 2 +- app/community/routes.py | 8 ++++---- app/community/util.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 239dedcf..ad087afd 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -564,7 +564,7 @@ def actor_json_to_model(activity_json, address, server): ap_followers_url=activity_json['followers'], ap_inbox_url=activity_json['endpoints']['sharedInbox'], ap_outbox_url=activity_json['outbox'], - ap_featured_url=activity_json['featured'], + ap_featured_url=activity_json['featured'] if 'featured' in activity_json else '', ap_moderators_url=mods_url, ap_fetched_at=utcnow(), ap_domain=server, diff --git a/app/community/routes.py b/app/community/routes.py index 21f5a69a..d6af868b 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -102,9 +102,9 @@ def add_remote(): flash(_('Community not found.'), 'warning') else: flash(_('Community not found. If you are searching for a nsfw community it is blocked by this instance.'), 'warning') - - if new_community.banned: - flash(_('That community is banned from %(site)s.', site=g.site.name), 'warning') + else: + if new_community.banned: + flash(_('That community is banned from %(site)s.', site=g.site.name), 'warning') return render_template('community/add_remote.html', title=_('Add remote community'), form=form, new_community=new_community, @@ -960,4 +960,4 @@ def community_moderate_banned(actor): else: abort(401) else: - abort(404) \ No newline at end of file + abort(404) diff --git a/app/community/util.py b/app/community/util.py index 44642fb0..ebfbd775 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -96,7 +96,7 @@ def retrieve_mods_and_backfill(community_id: int): if outbox_request.status_code == 200: outbox_data = outbox_request.json() outbox_request.close() - if outbox_data['type'] == 'OrderedCollection' and 'orderedItems' in outbox_data: + if 'type' in outbox_data and outbox_data['type'] == 'OrderedCollection' and 'orderedItems' in outbox_data: activities_processed = 0 for activity in outbox_data['orderedItems']: user = find_actor_or_create(activity['object']['actor'])