Node.js based forum software built for the modern web
feat(activitypub): add allowList to ssrf.js for hostname whitelisting
Julian Lam711f22752fad
diff --git a/src/request.js b/src/request.jsindex 055329e39b..620518873f 100644--- a/src/request.js+++ b/src/request.js@@ -8,9 +8,8 @@ const { Agent } = require('undici');const { Dispatcher1Wrapper } = require('undici');const plugins = require('./plugins');-const { checkHostname, lookup } = require('./ssrf');+const { checkHostname, lookup, allowList } = require('./ssrf');-let allowList = new Set();let initialized = false;exports.jar = function () {@@ -27,8 +26,12 @@ async function init() {allowList.add(nconf.get('url_parsed').hostname);const { allowed } = await plugins.hooks.fire('filter:request.init', { allowed: allowList });if (allowed instanceof Set) {- allowList = allowed;+ // Replace the set reference — ssrf.js uses this same Set+ allowList.clear();+ allowed.forEach(h => allowList.add(h));}+ // Always ensure the configured URL's hostname is in the allow list+ allowList.add(nconf.get('url_parsed').hostname);initialized = true;}diff --git a/src/ssrf.js b/src/ssrf.jsindex ac1dfba3ae..1d53ebebc8 100644--- a/src/ssrf.js+++ b/src/ssrf.js@@ -4,6 +4,7 @@ const dns = require('dns').promises;const ipaddr = require('ipaddr.js');const checkCache = new Map();+const allowList = new Set();const CHECK_TTL = 1000 * 60 * 60; // 1 hourconst CHECK_CLEANUP_INTERVAL = 1000 * 60 * 5; // 5 minutes@@ -19,6 +20,12 @@ cleanupInterval.unref();async function checkHostname(rawHostname) {const hostname = rawHostname.replace(/^\[|\]$/g, '');++ // Check allow-list first — hostnames here bypass SSRF restrictions+ if (allowList.has(hostname)) {+ return { ok: true, _ts: Date.now() };+ }+const cached = checkCache.get(hostname);if (cached && (Date.now() - (cached._ts || 0)) < CHECK_TTL) {return cached;@@ -82,6 +89,7 @@ async function lookup(hostname, options, callback) {}module.exports = {+ allowList,checkHostname,check,lookup,