From dddd760efd3e3da5be68493d065c7adf11bdba63 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 26 Jul 2018 17:13:55 +0900 Subject: [PATCH] Fix bug --- src/remote/activitypub/models/person.ts | 62 ++++++++++++++----------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 4ff8d23be..c292d0241 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -14,6 +14,34 @@ import htmlToMFM from '../../../mfm/html-to-mfm'; const log = debug('misskey:activitypub'); +function validatePerson(x: any) { + if (x == null) { + return new Error('invalid person: object is null'); + } + + if (x.type != 'Person' && x.type != 'Service') { + return new Error(`invalid person: object is not a person or service '${x.type}'`); + } + + if (typeof x.preferredUsername !== 'string') { + return new Error('invalid person: preferredUsername is not a string'); + } + + if (typeof x.inbox !== 'string') { + return new Error('invalid person: inbox is not a string'); + } + + if (!validateUsername(x.preferredUsername)) { + return new Error('invalid person: invalid username'); + } + + if (!isValidName(x.name == '' ? null : x.name)) { + return new Error('invalid person: invalid name'); + } + + return null; +} + /** * Personをフェッチします。 * @@ -47,28 +75,10 @@ export async function createPerson(value: any, resolver?: Resolver): Promise