Node.js based forum software built for the modern web
fix(activitypub): respect severity in isAllowed and update tests
Julian Lam877a929ed341
diff --git a/public/language/en-GB/admin/settings/activitypub.json b/public/language/en-GB/admin/settings/activitypub.jsonindex 8f541178ad..b03b481ad5 100644--- a/public/language/en-GB/admin/settings/activitypub.json+++ b/public/language/en-GB/admin/settings/activitypub.json@@ -60,7 +60,7 @@"server.filter-help": "Specify servers you would like to bar from federating with your NodeBB. Alternatively, you may opt to selectively <em>allow</em> federation with specific servers, instead. Both options are supported, although they are mutually exclusive.","server.filter-help-hostname": "Enter just the instance hostname below (e.g. <code>example.org</code>), separated by line breaks.","server.filter-allow-list": "Use this as an Allow List instead",- "server.filter-allow-list-help": "When enabled, only domains in the core list are allowed to federate. Severity settings are ignored in allow list mode."+ "server.filter-allow-list-help": "When enabled, only domains in the core list are allowed to federate. Severity settings are ignored in allow list mode.","core-domains.title": "Add/Modify Domain","core-domains.add": "Add",diff --git a/src/activitypub/instances.js b/src/activitypub/instances.jsindex f8194c8752..0f16d7db0b 100644--- a/src/activitypub/instances.js+++ b/src/activitypub/instances.js@@ -21,9 +21,12 @@ Instances.isAllowed = async (domain) => {const { activitypubFilter: type } = meta.config;if (!type) {- // type = 0: blocklist mode — deny if domain is on the core list+ // type = 0: blocklist mode — deny if domain is on the core list with severity <= silenceif (result.allowed) {- return { ...result, allowed: !core.domains.some(d => d.domain === domain) };+ const coreDomain = core.domains.find(d => d.domain === domain);+ const coreSeverity = coreDomain ? coreDomain.severity : null;+ const coreBlocked = coreSeverity && coreSeverity !== 'filter';+ return { ...result, allowed: !coreBlocked };}return result;diff --git a/test/activitypub/blocklists.js b/test/activitypub/blocklists.jsindex 52a8792966..c511e04fbc 100644--- a/test/activitypub/blocklists.js+++ b/test/activitypub/blocklists.js@@ -120,8 +120,8 @@ describe('ActivityPub blocklists', () => {const result = await activitypub.blocklists.get(u);assert.strictEqual(result.count, 2);- assert(result.domains.includes('blocked.example.com'));- assert(result.domains.includes('another.example.com'));+ assert(result.domains.some(d => d.domain === 'blocked.example.com'));+ assert(result.domains.some(d => d.domain === 'another.example.com'));});it('should return empty domains if refresh received no CSV data', async () => {@@ -161,8 +161,8 @@ describe('ActivityPub blocklists', () => {const result = await activitypub.blocklists.get(u);assert.strictEqual(result.count, 2);- assert(result.domains.includes('fresh.com'));- assert(result.domains.includes('fresh.org'));+ assert(result.domains.some(d => d.domain === 'fresh.com'));+ assert(result.domains.some(d => d.domain === 'fresh.org'));});});@@ -279,8 +279,8 @@ describe('ActivityPub blocklists', () => {const result = await activitypub.blocklists.get(u);assert.strictEqual(result.count, 1, `expected count 1, got ${result.count}`);- assert(result.domains.includes('new.com'));- assert(!result.domains.includes('old.com'));+ assert(result.domains.some(d => d.domain === 'new.com'));+ assert(!result.domains.some(d => d.domain === 'old.com'));const sevNew = await getSeverity('new.com');assert.strictEqual(sevNew, 3, `expected new.com severity to be 3, got ${sevNew}`);@@ -437,7 +437,7 @@ describe('ActivityPub blocklists', () => {// 5. Check filtered domainconst filtered = await activitypub.blocklists.check('filtered.com');- assert.strictEqual(filtered.allowed, false);+ assert.strictEqual(filtered.allowed, true);assert.strictEqual(filtered.severity, 3);// 6. Check clean domain