From 1f896fb6baee43a1533ec371b233eecf3a5f88ff Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 29 Jul 2024 15:03:51 -0400 Subject: [PATCH] fix: bugs in user searching causing remote lookups to fail --- src/activitypub/actors.js | 2 +- src/activitypub/helpers.js | 6 ++++-- src/user/search.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/activitypub/actors.js b/src/activitypub/actors.js index 3c31fac0e4..759296e73c 100644 --- a/src/activitypub/actors.js +++ b/src/activitypub/actors.js @@ -39,7 +39,7 @@ Actors.assert = async (ids, options = {}) => { ids = (await Promise.all(ids.map(async (id) => { const originalId = id; if (activitypub.helpers.isWebfinger(id)) { - const host = id.split('@')[1]; + const host = id.replace(/^(acct:|@)/, '').split('@')[1]; if (host === nconf.get('url_parsed').host) { // do not assert loopback ids return 'loopback'; } diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index 78a1a0d06e..f27a1a5d60 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -58,10 +58,12 @@ Helpers.query = async (id) => { // 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('@'); + let [username, hostname] = isUri ? [uri.pathname || uri.href, uri.host] : id.split('@'); if (!username || !hostname) { return false; } + username = username.trim(); + hostname = hostname.trim(); const cached = webfingerCache.get(id); if (cached !== undefined) { @@ -159,7 +161,7 @@ Helpers.resolveLocalId = async (input) => { return { type: null, id: null }; } else if (String(input).indexOf('@') !== -1) { // Webfinger input = decodeURIComponent(input); - const [slug] = input.replace(/^acct:/, '').split('@'); + const [slug] = input.replace(/^(acct:|@)/, '').split('@'); const uid = await user.getUidByUserslug(slug); return { type: 'user', id: uid }; } diff --git a/src/user/search.js b/src/user/search.js index 252273b941..17df4b68f1 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -45,7 +45,7 @@ module.exports = function (User) { const handle = activitypub.helpers.isWebfinger(data.query); if (handle || activitypub.helpers.isUri(data.query)) { const local = await activitypub.helpers.resolveLocalId(data.query); - if (local.type === 'user') { + if (local.type === 'user' && utils.isNumber(local.id)) { uids = [local.id]; } else { const assertion = await activitypub.actors.assert([handle || data.query]);