Skip to content

Node.js based forum software built for the modern web

fix: actors.assert attempting to process things that aren't actors, #12809

Julian Lam6b4b4b1a0080
diff --git a/src/activitypub/actors.js b/src/activitypub/actors.js
index 41b6a16e99..9390a62069 100644
--- a/src/activitypub/actors.js
+++ b/src/activitypub/actors.js
@@ -20,6 +20,16 @@ const activitypub = module.parent.exports;
const Actors = module.exports;
Actors.assert = async (ids, options = {}) => {
+ /**
+ * Ensures that the passed in ids or webfinger handles are stored in database.
+ * Options:
+ * - update: boolean, forces re-fetch/process of the resolved id
+ * Return one of:
+ * - An array of newly processed ids
+ * - false: if input incorrect (or webfinger handle cannot resolve)
+ * - true: no new IDs processed; all passed-in IDs present.
+ */
+
// Handle single values
if (!Array.isArray(ids)) {
ids = [ids];
@@ -89,6 +99,12 @@ Actors.assert = async (ids, options = {}) => {
try {
// winston.verbose(`[activitypub/actors] Processing ${id}`);
const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? id : await activitypub.get('uid', 0, id, { cache: process.env.CI === 'true' });
+ if (
+ !activitypub._constants.acceptableActorTypes.has(actor.type) ||
+ !activitypub._constants.requiredActorProps.every(prop => actor.hasOwnProperty(prop))
+ ) {
+ return null;
+ }
// Follow counts
try {
diff --git a/src/activitypub/index.js b/src/activitypub/index.js
index 1d37f2f546..c378a2d9f9 100644
--- a/src/activitypub/index.js
+++ b/src/activitypub/index.js
@@ -33,6 +33,8 @@ ActivityPub._constants = Object.freeze({
acceptedPostTypes: [
'Note', 'Page', 'Article', 'Question',
],
+ acceptableActorTypes: new Set(['Application', 'Group', 'Organization', 'Person', 'Service']),
+ requiredActorProps: ['inbox', 'outbox'],
acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])],
});
ActivityPub._cache = requestCache;