From a66c2e3252d6cca8958959966f42494ded564023 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 7 May 2021 08:59:59 +0200 Subject: Fix remote actor creation date --- .../helpers/custom-validators/activitypub/actor.ts | 39 ++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'server/helpers/custom-validators/activitypub') diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts index 877345157..675a7b663 100644 --- a/server/helpers/custom-validators/activitypub/actor.ts +++ b/server/helpers/custom-validators/activitypub/actor.ts @@ -1,6 +1,6 @@ import validator from 'validator' import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' -import { exists, isArray } from '../misc' +import { exists, isArray, isDateValid } from '../misc' import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' import { isHostValid } from '../servers' import { peertubeTruncate } from '@server/helpers/core-utils' @@ -47,7 +47,21 @@ function isActorPrivateKeyValid (privateKey: string) { validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY) } -function isActorObjectValid (actor: any) { +function isActorFollowingCountValid (value: string) { + return exists(value) && validator.isInt('' + value, { min: 0 }) +} + +function isActorFollowersCountValid (value: string) { + return exists(value) && validator.isInt('' + value, { min: 0 }) +} + +function isActorDeleteActivityValid (activity: any) { + return isBaseActivityValid(activity, 'Delete') +} + +function sanitizeAndCheckActorObject (actor: any) { + normalizeActor(actor) + return exists(actor) && isActivityPubUrlValid(actor.id) && isActorTypeValid(actor.type) && @@ -68,24 +82,6 @@ function isActorObjectValid (actor: any) { (actor.type !== 'Group' || actor.attributedTo.length !== 0) } -function isActorFollowingCountValid (value: string) { - return exists(value) && validator.isInt('' + value, { min: 0 }) -} - -function isActorFollowersCountValid (value: string) { - return exists(value) && validator.isInt('' + value, { min: 0 }) -} - -function isActorDeleteActivityValid (activity: any) { - return isBaseActivityValid(activity, 'Delete') -} - -function sanitizeAndCheckActorObject (object: any) { - normalizeActor(object) - - return isActorObjectValid(object) -} - function normalizeActor (actor: any) { if (!actor) return @@ -95,6 +91,8 @@ function normalizeActor (actor: any) { actor.url = actor.url.href || actor.url.url } + if (!isDateValid(actor.published)) actor.published = undefined + if (actor.summary && typeof actor.summary === 'string') { actor.summary = peertubeTruncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max }) @@ -135,7 +133,6 @@ export { isActorPublicKeyValid, isActorPreferredUsernameValid, isActorPrivateKeyValid, - isActorObjectValid, isActorFollowingCountValid, isActorFollowersCountValid, isActorDeleteActivityValid, -- cgit v1.2.3