From 2c6b773748a63f1478086317e1f520a582086db8 Mon Sep 17 00:00:00 2001 From: mei23 Date: Wed, 10 Apr 2019 20:34:21 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20AP=20actor=20Service=20=E3=81=AE?= =?UTF-8?q?=E3=82=B5=E3=83=9D=E3=83=BC=E3=83=88=E3=81=8C=E4=B8=8D=E5=AE=8C?= =?UTF-8?q?=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/queue/processors/inbox.ts | 3 ++- src/remote/activitypub/models/person.ts | 4 ++-- src/remote/activitypub/type.ts | 2 ++ src/server/api/endpoints/ap/show.ts | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/queue/processors/inbox.ts b/src/queue/processors/inbox.ts index 76d303f469d3..fe12aeb898dc 100644 --- a/src/queue/processors/inbox.ts +++ b/src/queue/processors/inbox.ts @@ -11,6 +11,7 @@ import Logger from '../../services/logger'; import { registerOrFetchInstanceDoc } from '../../services/register-or-fetch-instance-doc'; import Instance from '../../models/instance'; import instanceChart from '../../services/chart/instance'; +import { validActor } from '../../remote/activitypub/type'; const logger = new Logger('inbox'); @@ -79,7 +80,7 @@ export default async (job: Bull.Job): Promise => { // Update Person activityの場合は、ここで署名検証/更新処理まで実施して終了 if (activity.type === 'Update') { - if (activity.object && activity.object.type === 'Person') { + if (activity.object && validActor.includes(activity.object.type)) { if (user == null) { logger.warn('Update activity received, but user not registed.'); } else if (!httpSignature.verifySignature(signature, user.publicKey.publicKeyPem)) { diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index a1838dddc3c5..209b372591d3 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -6,7 +6,7 @@ import config from '../../../config'; import User, { validateUsername, isValidName, IUser, IRemoteUser, isRemoteUser } from '../../../models/user'; import Resolver from '../resolver'; import { resolveImage } from './image'; -import { isCollectionOrOrderedCollection, isCollection, IPerson, isOrderedCollection } from '../type'; +import { isCollectionOrOrderedCollection, isCollection, IPerson, isOrderedCollection, validActor } from '../type'; import { IDriveFile } from '../../../models/drive-file'; import Meta from '../../../models/meta'; import { fromHtml } from '../../../mfm/fromHtml'; @@ -38,7 +38,7 @@ function validatePerson(x: any, uri: string) { return new Error('invalid person: object is null'); } - if (x.type != 'Person' && x.type != 'Service') { + if (!validActor.includes(x.type)) { return new Error(`invalid person: object is not a person or service '${x.type}'`); } diff --git a/src/remote/activitypub/type.ts b/src/remote/activitypub/type.ts index 78514246d3ed..39f57e223be0 100644 --- a/src/remote/activitypub/type.ts +++ b/src/remote/activitypub/type.ts @@ -95,6 +95,8 @@ interface IQuestionChoice { _misskey_votes?: number; } +export const validActor = ['Person', 'Service']; + export interface IPerson extends IObject { type: 'Person'; name: string; diff --git a/src/server/api/endpoints/ap/show.ts b/src/server/api/endpoints/ap/show.ts index 7f4afa1f6e4f..a7c9e55d4f89 100644 --- a/src/server/api/endpoints/ap/show.ts +++ b/src/server/api/endpoints/ap/show.ts @@ -10,6 +10,7 @@ import Resolver from '../../../../remote/activitypub/resolver'; import { ApiError } from '../../error'; import Instance from '../../../../models/instance'; import { extractDbHost } from '../../../../misc/convert-host'; +import { validActor } from '../../../../remote/activitypub/type'; export const meta = { tags: ['federation'], @@ -95,7 +96,7 @@ async function fetchAny(uri: string) { } // それでもみつからなければ新規であるため登録 - if (object.type === 'Person') { + if (validActor.includes(object.type)) { const user = await createPerson(object.id); return { type: 'User',