From 1ecbf02a58a506647c285f4c9dfeda601116a0c9 Mon Sep 17 00:00:00 2001 From: Opliko Date: Thu, 25 Apr 2024 17:16:30 +0200 Subject: [PATCH] fix: handle requests to URI IDs correctly --- src/activitypub/helpers.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index 4f85b777e9..24c61cade8 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -37,9 +37,12 @@ Helpers.isUri = (value) => { }; Helpers.query = async (id) => { - const [username, hostname] = id.split('@'); const isUri = Helpers.isUri(id); - if ((!username || !hostname) && !isUri) { + // username@host ids use acct: URI schema + const uri = isUri ? new URL(id) : new URL(`acct:${id}`); + // JS doesn't parse anything other than protocol and pathname from acct: URIs, so we need to just split id manually + const [username, hostname] = isUri ? [uri.pathname || uri.href, uri.host] : id.split('@'); + if (!username || !hostname) { return false; } @@ -47,8 +50,7 @@ Helpers.query = async (id) => { return webfingerCache.get(id); } - // only add acct: schema if id is not an URI already - const query = new URLSearchParams({ resource: `${isUri ? '' : 'acct:'}${id}` }); + const query = new URLSearchParams({ resource: uri }); // Make a webfinger query to retrieve routing information let response; @@ -73,7 +75,7 @@ Helpers.query = async (id) => { const { subject, publicKey } = body; const payload = { subject, username, hostname, actorUri, publicKey }; - const claimedId = subject.slice(5); + const claimedId = new URL(subject).pathname; webfingerCache.set(claimedId, payload); if (claimedId !== id) { webfingerCache.set(id, payload);