Skip to content

Node.js based forum software built for the modern web

feat(activitypub): make public key fetch rate limit configurable

Julian Lam471b827f0bbb
diff --git a/install/data/defaults.json b/install/data/defaults.json
index a1a6dfd28a..e8001a61e5 100644
--- a/install/data/defaults.json
+++ b/install/data/defaults.json
@@ -207,6 +207,7 @@
"activitypubEnabled": 1,
"activitypubAllowLoopback": 0,
"activitypubParentTraversalDepth": 50,
+ "activitypubPublicKeyFetchRateLimit": 180,
"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.json
index 0bf6a05e49..8348b75b93 100644
--- a/public/language/en-GB/admin/settings/activitypub.json
+++ b/public/language/en-GB/admin/settings/activitypub.json
@@ -9,6 +9,8 @@
"user-pruning-help": "Remote user accounts will only be pruned if they have no posts. Otherwise they will be re-retrieved. (0 for disabled)",
"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)",
"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.js
index d7dd892fd7..497e5f4663 100644
--- a/src/activitypub/index.js
+++ b/src/activitypub/index.js
@@ -239,7 +239,7 @@ ActivityPub.fetchPublicKey = async (uri, ip) => {
const lockId = `pubkey:${ip}`;
const currentCount = publicKeyFetchRateLimit.get(lockId) || 0;
const lockStatus = await db.incrObjectField('locks', lockId);
- if (lockStatus > 1 || currentCount >= 60) {
+ if (lockStatus > 1 || currentCount >= meta.config.activitypubPublicKeyFetchRateLimit) {
winston.warn(`[activitypub/fetchPublicKey] Rate limit exceeded for IP ${ip}`);
throw new Error('[[error:activitypub.rate-limited]]');
}
diff --git a/src/views/admin/federation/general.tpl b/src/views/admin/federation/general.tpl
index 3918c0c936..9fd139ee01 100644
--- a/src/views/admin/federation/general.tpl
+++ b/src/views/admin/federation/general.tpl
@@ -29,6 +29,13 @@
[[admin/settings/activitypub:parentTraversalDepth-help]]
</div>
</div>
+ <div class="mb-3">
+ <label class="form-label" for="activitypubPublicKeyFetchRateLimit">[[admin/settings/activitypub:publicKeyFetchRateLimit]]</label>
+ <input type="number" id="activitypubPublicKeyFetchRateLimit" name="activitypubPublicKeyFetchRateLimit" data-field="activitypubPublicKeyFetchRateLimit" title="[[admin/settings/activitypub:publicKeyFetchRateLimit]]" class="form-control" />
+ <div class="form-text">
+ [[admin/settings/activitypub:publicKeyFetchRateLimit-help]]
+ </div>
+ </div>
</form>
</div>