Node.js based forum software built for the modern web
chore(activitypub): disable public key fetch rate limit by default
Julian Lam9f2141754cf9
diff --git a/install/data/defaults.json b/install/data/defaults.jsonindex e8001a61e5..194c752ee0 100644--- a/install/data/defaults.json+++ b/install/data/defaults.json@@ -207,7 +207,7 @@"activitypubEnabled": 1,"activitypubAllowLoopback": 0,"activitypubParentTraversalDepth": 50,- "activitypubPublicKeyFetchRateLimit": 180,+ "activitypubPublicKeyFetchRateLimit": 0,"activitypubProbe": 1,"activitypubProbeTimeout": 2000,"activitypubContentPruneDays": 30,diff --git a/public/language/en-GB/admin/settings/activitypub.json b/public/language/en-GB/admin/settings/activitypub.jsonindex 8348b75b93..4bc07e19a2 100644--- a/public/language/en-GB/admin/settings/activitypub.json+++ b/public/language/en-GB/admin/settings/activitypub.json@@ -10,7 +10,7 @@"enabled": "Enable Federation","enabled-help": "If enabled, will allow this NodeBB will be able to communicate with all Activitypub-enabled clients on the wider fediverse.","publicKeyFetchRateLimit": "Public Key Fetch Rate Limit",- "publicKeyFetchRateLimit-help": "Maximum number of public key fetch requests allowed per minute per IP. (Default: 180)",+ "publicKeyFetchRateLimit-help": "Maximum number of public key fetch requests allowed per minute per IP. Disabled by default; enable if you need to guard against outbound request flooding, but may impact federation. A value of 512 is a reasonable starting point for active instances.","allowLoopback": "Allow loopback processing","allowLoopback-help": "Useful for debugging purposes only. You should probably leave this disabled.","parentTraversalDepth": "Parent traversal depth",diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex 497e5f4663..d3a6595b98 100644--- a/src/activitypub/index.js+++ b/src/activitypub/index.js@@ -235,13 +235,17 @@ ActivityPub.fetchPublicKey = async (uri, ip) => {throw new Error('[[error:activitypub.invalid-id]]');}- // Check rate limit for this IP- const lockId = `pubkey:${ip}`;- const currentCount = publicKeyFetchRateLimit.get(lockId) || 0;- const lockStatus = await db.incrObjectField('locks', lockId);- if (lockStatus > 1 || currentCount >= meta.config.activitypubPublicKeyFetchRateLimit) {- winston.warn(`[activitypub/fetchPublicKey] Rate limit exceeded for IP ${ip}`);- throw new Error('[[error:activitypub.rate-limited]]');+ // Check rate limit for this IP (0 = disabled)+ let lockId;+ let currentCount;+ if (meta.config.activitypubPublicKeyFetchRateLimit > 0) {+ lockId = `pubkey:${ip}`;+ currentCount = publicKeyFetchRateLimit.get(lockId) || 0;+ const lockStatus = await db.incrObjectField('locks', lockId);+ if (lockStatus > 1 || currentCount >= meta.config.activitypubPublicKeyFetchRateLimit) {+ winston.warn(`[activitypub/fetchPublicKey] Rate limit exceeded for IP ${ip}`);+ throw new Error('[[error:activitypub.rate-limited]]');+ }}try {@@ -287,8 +291,10 @@ ActivityPub.fetchPublicKey = async (uri, ip) => {}throw err;} finally {- await db.deleteObjectField('locks', lockId);- publicKeyFetchRateLimit.set(lockId, currentCount + 1, 60 * 1000);+ if (lockId) {+ await db.deleteObjectField('locks', lockId);+ publicKeyFetchRateLimit.set(lockId, currentCount + 1, 60 * 1000);+ }}};