From 700016649d25ee5bc6c3fa17e03003677d7f5b5d Mon Sep 17 00:00:00 2001 From: Opliko Date: Thu, 25 Apr 2024 12:59:05 +0200 Subject: [PATCH] fix: handle URI actor IDs --- src/activitypub/actors.js | 5 +++-- src/activitypub/helpers.js | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/activitypub/actors.js b/src/activitypub/actors.js index 991f8223f8..6f6b20fae2 100644 --- a/src/activitypub/actors.js +++ b/src/activitypub/actors.js @@ -31,8 +31,9 @@ Actors.assert = async (ids, options = {}) => { // Translate webfinger handles to uris ids = (await Promise.all(ids.map(async (id) => { const originalId = id; - if (id.includes('@')) { - const host = id.split('@')[1]; + const isUri = activitypub.helpers.isUri(id); + if (id.includes('@') || isUri) { + const host = isUri ? new URL(id).host : id.split('@')[1]; if (host === nconf.get('url_parsed').host) { // do not assert loopback ids return null; } diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index 6da2c89396..071143fc32 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -38,7 +38,8 @@ Helpers.isUri = (value) => { Helpers.query = async (id) => { const [username, hostname] = id.split('@'); - if (!username || !hostname) { + const isUri = Helpers.isUri(id); + if ((!username || !hostname) && !isUri) { return false; } @@ -46,11 +47,13 @@ Helpers.query = async (id) => { return webfingerCache.get(id); } + const protocol = isUri ? '' : 'acct:'; // if ID is an URI the protocol is already included + // Make a webfinger query to retrieve routing information let response; let body; try { - ({ response, body } = await request.get(`https://${hostname}/.well-known/webfinger?resource=acct%3a${encodeURIComponent(id)}`)); + ({ response, body } = await request.get(`https://${hostname}/.well-known/webfinger?resource=${encodeURIComponent(protocol)}${encodeURIComponent(id)}`)); } catch (e) { return false; }