Skip to content

Commit

Permalink
fix: better logic for choosing webfinger lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
oplik0 committed Apr 25, 2024
1 parent dd71340 commit ed84eed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/activitypub/actors.js
Expand Up @@ -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 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];
if (host === nconf.get('url_parsed').host) { // do not assert loopback ids
return null;
Expand Down
7 changes: 1 addition & 6 deletions src/activitypub/helpers.js
Expand Up @@ -22,15 +22,10 @@ Helpers.isUri = (value) => {
value = String(value);
}

const protocols = ['https'];
if (process.env.CI === 'true') {
protocols.push('http');
}

return validator.isURL(value, {
require_protocol: true,
require_host: true,
protocols,
protocols: activitypub._constants.acceptedProtocols,
require_valid_protocol: true,
require_tld: false, // temporary — for localhost
});
Expand Down
1 change: 1 addition & 0 deletions src/activitypub/index.js
Expand Up @@ -24,6 +24,7 @@ ActivityPub._constants = Object.freeze({
acceptedPostTypes: [
'Note', 'Page', 'Article', 'Question',
],
acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])],
});
ActivityPub._cache = requestCache;

Expand Down

0 comments on commit ed84eed

Please sign in to comment.