mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
fix: handle URI actor IDs
This commit is contained in:
@@ -31,8 +31,9 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
// Translate webfinger handles to uris
|
// Translate webfinger handles to uris
|
||||||
ids = (await Promise.all(ids.map(async (id) => {
|
ids = (await Promise.all(ids.map(async (id) => {
|
||||||
const originalId = id;
|
const originalId = id;
|
||||||
if (id.includes('@')) {
|
const isUri = activitypub.helpers.isUri(id);
|
||||||
const host = id.split('@')[1];
|
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
|
if (host === nconf.get('url_parsed').host) { // do not assert loopback ids
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ Helpers.isUri = (value) => {
|
|||||||
|
|
||||||
Helpers.query = async (id) => {
|
Helpers.query = async (id) => {
|
||||||
const [username, hostname] = id.split('@');
|
const [username, hostname] = id.split('@');
|
||||||
if (!username || !hostname) {
|
const isUri = Helpers.isUri(id);
|
||||||
|
if ((!username || !hostname) && !isUri) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,11 +47,13 @@ Helpers.query = async (id) => {
|
|||||||
return webfingerCache.get(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
|
// Make a webfinger query to retrieve routing information
|
||||||
let response;
|
let response;
|
||||||
let body;
|
let body;
|
||||||
try {
|
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) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user