Node.js based forum software built for the modern web
fix(activitypub): reject array-valued attributedTo in inbox origin check
Julian Lam7a071a31a768
diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.jsindex 81fb718da4..35868314ed 100644--- a/src/activitypub/inbox.js+++ b/src/activitypub/inbox.js@@ -44,15 +44,14 @@ inbox.create = async (req) => {// attributedTo must be same-originif (actor && object.attributedTo) {- // Normalize `attributedTo`+ // Normalize `attributedTo` — only handle single values (string or object with id)let { attributedTo } = object;- if (typeof attributedTo === 'object' && !Array.isArray(attributedTo)) {+ if (Array.isArray(attributedTo)) {+ activitypub.helpers.log('[activitypub/inbox.create] attributedTo is an array, rejecting.');+ return null;+ }+ if (typeof attributedTo === 'object' && attributedTo.id) {attributedTo = attributedTo.id;- } else if (Array.isArray(attributedTo)) {- attributedTo = attributedTo.find(a => typeof a === 'string' || (typeof a === 'object' && a.id)) || attributedTo.shift();- if (typeof attributedTo === 'object') {- attributedTo = attributedTo.id;- }}if (typeof attributedTo === 'string') {@@ -193,15 +192,14 @@ inbox.update = async (req) => {// attributedTo must be same-originif (actor && object.attributedTo) {- // Normalize `attributedTo`+ // Normalize `attributedTo` — only handle single values (string or object with id)let { attributedTo } = object;- if (typeof attributedTo === 'object' && !Array.isArray(attributedTo)) {+ if (Array.isArray(attributedTo)) {+ activitypub.helpers.log('[activitypub/inbox.update] attributedTo is an array, rejecting.');+ return null;+ }+ if (typeof attributedTo === 'object' && attributedTo.id) {attributedTo = attributedTo.id;- } else if (Array.isArray(attributedTo)) {- attributedTo = attributedTo.find(a => typeof a === 'string' || (typeof a === 'object' && a.id)) || attributedTo.shift();- if (typeof attributedTo === 'object') {- attributedTo = attributedTo.id;- }}if (typeof attributedTo === 'string') {diff --git a/test/activitypub/inbox.js b/test/activitypub/inbox.jsindex 53f69ee79d..8c9db6d4ae 100644--- a/test/activitypub/inbox.js+++ b/test/activitypub/inbox.js@@ -251,7 +251,7 @@ describe('Inbox', () => {assert.strictEqual(await messaging.messageExists(note.id), false);});- it('should not create a message when attributedTo is array of non-URI values', async () => {+ it('should not create a message when attributedTo is an array of non-URI values', async () => {const { note } = helpers.mocks.note({attributedTo: [1, 'not-a-uri'],to: [`${nconf.get('url')}/uid/${this.uid}`],