Node.js based forum software built for the modern web
fix(activitypub): re-apply federation policy on redirect destinations
Julian Lam6c4692b7cd92
diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex a4e199cc18..e61bc8505b 100644--- a/src/activitypub/index.js+++ b/src/activitypub/index.js@@ -320,19 +320,23 @@ ActivityPub.verify = async (req) => {return isValid;};-ActivityPub.get = async (type, id, uri, options) => {- if (!meta.config.activitypubEnabled) {- throw new Error('[[error:activitypub.not-enabled]]');- }-- const { hostname } = new URL(uri);+async function _checkFederationPolicy(hostname, url) {const { allowed } = await ActivityPub.instances.isAllowed(hostname);if (!allowed) {- ActivityPub.helpers.log(`[activitypub/get] Not retrieving ${uri}, domain is blocked.`);+ ActivityPub.helpers.log(`[activitypub/get] Not retrieving ${url}, domain is blocked.`);const e = new Error(`[[error:activitypub.get-failed]]`);e.code = `ap_get_domain_blocked`;throw e;}+};++ActivityPub.get = async (type, id, uri, options) => {+ if (!meta.config.activitypubEnabled) {+ throw new Error('[[error:activitypub.not-enabled]]');+ }++ const { hostname } = new URL(uri);+ await _checkFederationPolicy(hostname, uri);options = {cache: true,@@ -348,7 +352,7 @@ ActivityPub.get = async (type, id, uri, options) => {const headers = id >= 0 ? await ActivityPub.sign(keyData, uri) : {};ActivityPub.helpers.log(`[activitypub/get] ${uri}`);try {- const { response, body } = await request.get(uri, {+ const { response, body, url: resolvedUrl } = await request.get(uri, {headers: {...headers,...options.headers,@@ -357,6 +361,9 @@ ActivityPub.get = async (type, id, uri, options) => {timeout: 5000,});+ const { hostname: resolvedHostname } = new URL(resolvedUrl);+ await _checkFederationPolicy(resolvedHostname, resolvedUrl);+if (!String(response.statusCode).startsWith('2')) {ActivityPub.helpers.log(`[activitypub/get] Received ${response.statusCode} when querying ${uri}`);if (body.hasOwnProperty('error')) {diff --git a/src/request.js b/src/request.jsindex 620518873f..0addd437e6 100644--- a/src/request.js+++ b/src/request.js@@ -161,6 +161,7 @@ async function call(url, method, { body, timeout, jar, sizeLimit = 10 * 1024 * 1statusText: response.statusText,headers: Object.fromEntries(response.headers.entries()),},+ url: currentUrl,};}