From 59e989c0bbf59adfe71e9317e4d69cab4999d0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hern=C3=A1ndez?= Date: Thu, 17 Aug 2023 04:41:27 +0000 Subject: [PATCH] Validate before delivering to keep federation working on valid inboxes --- .../src/remote/activitypub/deliver-manager.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/remote/activitypub/deliver-manager.ts b/packages/backend/src/remote/activitypub/deliver-manager.ts index 400e047774..c97d1c99ae 100644 --- a/packages/backend/src/remote/activitypub/deliver-manager.ts +++ b/packages/backend/src/remote/activitypub/deliver-manager.ts @@ -122,19 +122,31 @@ export default class DeliverManager { ) .forEach((recipe) => inboxes.add(recipe.to.inbox!)); + // Validate Inboxes first + const validInboxes = []; + for (const inbox of inboxes) { + try { + validInboxes.push({ + inbox, + host: new URL(inbox).host, + }); + } catch (error) { + console.error(error); + console.error(`Invalid Inbox ${inbox}`); + } + } + const instancesToSkip = await skippedInstances( // get (unique) list of hosts - Array.from( - new Set(Array.from(inboxes).map((inbox) => new URL(inbox).host)), - ), + Array.from(new Set(validInboxes.map((valid) => valid.host))), ); // deliver - for (const inbox of inboxes) { + for (const valid of validInboxes) { // skip instances as indicated - if (instancesToSkip.includes(new URL(inbox).host)) continue; + if (instancesToSkip.includes(valid.host)) continue; - deliver(this.actor, this.activity, inbox); + deliver(this.actor, this.activity, valid.inbox); } } }