fix: better logic for choosing webfinger lookups

This commit is contained in:
Opliko
2024-04-25 20:05:53 +02:00
parent dd71340af9
commit ed84eed8a9
3 changed files with 5 additions and 8 deletions

View File

@@ -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 isUri = activitypub.helpers.isUri(id); // only look up webfinger if the id is not a supported URI
if (id.includes('@') && !(isUri && activitypub._constants.acceptedProtocols.includes(new URL(id).protocol.slice(0, -1)))) {
const host = isUri ? new URL(id).host : id.split('@')[1]; 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;

View File

@@ -22,15 +22,10 @@ Helpers.isUri = (value) => {
value = String(value); value = String(value);
} }
const protocols = ['https'];
if (process.env.CI === 'true') {
protocols.push('http');
}
return validator.isURL(value, { return validator.isURL(value, {
require_protocol: true, require_protocol: true,
require_host: true, require_host: true,
protocols, protocols: activitypub._constants.acceptedProtocols,
require_valid_protocol: true, require_valid_protocol: true,
require_tld: false, // temporary — for localhost require_tld: false, // temporary — for localhost
}); });

View File

@@ -24,6 +24,7 @@ ActivityPub._constants = Object.freeze({
acceptedPostTypes: [ acceptedPostTypes: [
'Note', 'Page', 'Article', 'Question', 'Note', 'Page', 'Article', 'Question',
], ],
acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])],
}); });
ActivityPub._cache = requestCache; ActivityPub._cache = requestCache;