From 4550872bcc8f9ef46183463c7b7b74a90cb6d17c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 21 May 2019 09:31:53 +0200 Subject: Relax activity validation --- .../custom-validators/activitypub/activity.ts | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index e0d170d9d..f68c76cdc 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts @@ -12,18 +12,19 @@ import { isFlagActivityValid } from './flag' import { isPlaylistObjectValid } from './playlist' function isRootActivityValid (activity: any) { - return Array.isArray(activity['@context']) && ( - ( - (activity.type === 'Collection' || activity.type === 'OrderedCollection') && - validator.isInt(activity.totalItems, { min: 0 }) && - Array.isArray(activity.items) - ) || - ( - isActivityPubUrlValid(activity.id) && - exists(activity.actor) && - (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id)) - ) - ) + return isCollection(activity) || isActivity(activity) +} + +function isCollection (activity: any) { + return (activity.type === 'Collection' || activity.type === 'OrderedCollection') && + validator.isInt(activity.totalItems, { min: 0 }) && + Array.isArray(activity.items) +} + +function isActivity (activity: any) { + return isActivityPubUrlValid(activity.id) && + exists(activity.actor) && + (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id)) } const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean } = { -- cgit v1.2.3