Skip to content

Node.js based forum software built for the modern web

fix(activitypub): validate response body is JSON object in activitypub.get

Julian Lam97e1c6b60f02
diff --git a/src/activitypub/index.js b/src/activitypub/index.js
index cc717c4101..a4a520fefa 100644
--- a/src/activitypub/index.js
+++ b/src/activitypub/index.js
@@ -441,6 +441,13 @@ ActivityPub.get = async (type, id, uri, options) => {
throw e;
}
+ if (!body || typeof body !== 'object' || Array.isArray(body)) {
+ ActivityPub.helpers.log(`[activitypub/get] Received non-object response from ${uri}`);
+ const e = new Error(`[[error:activitypub.get-failed]]`);
+ e.code = 'ap_get_invalid_response';
+ throw e;
+ }
+
requestCache.set(cacheKey, body);
return body;
} catch (err) {