From 64004fdea244f039c34e9f59a103be9b9e164f77 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 11 Jun 2024 15:32:55 +0900 Subject: [PATCH] =?UTF-8?q?publicKey=E3=81=AB=E9=85=8D=E5=88=97=E3=81=8C?= =?UTF-8?q?=E5=85=A5=E3=81=A3=E3=81=A6=E3=82=82=E3=81=84=E3=81=84=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B=20https://github.com/missk?= =?UTF-8?q?ey-dev/misskey/pull/13950?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/models/ApPersonService.ts | 21 +++++++++++++------ packages/backend/src/core/activitypub/type.ts | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index f315e49a54..a712ca95ca 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -184,15 +184,24 @@ export class ApPersonService implements OnModuleInit { throw new Error('invalid Actor: id has different host'); } - if (x.publicKey) { - if (typeof x.publicKey.id !== 'string') { - throw new Error('invalid Actor: publicKey.id is not a string'); - } - + if (x.publicKey && typeof x.publicKey.id !== 'string') { const publicKeyIdHost = this.punyHost(x.publicKey.id); if (publicKeyIdHost !== expectHost) { throw new Error('invalid Actor: publicKey.id has different host'); } + } else if (x.publicKey && Array.isArray(x.publicKey)) { + for (const publicKey of x.publicKey) { + if (typeof publicKey.id !== 'string') { + throw new Error('invalid Actor: publicKey.id is not a string'); + } + + const publicKeyIdHost = this.punyHost(publicKey.id); + if (publicKeyIdHost !== expectHost) { + throw new Error('invalid Actor: publicKey.id has different host'); + } + } + } else if (x.publicKey) { + throw new Error('invalid Actor: publicKey is not an object or an array'); } if (x.additionalPublicKeys) { @@ -408,7 +417,7 @@ export class ApPersonService implements OnModuleInit { if (person.publicKey) { const publicKeys = new Map([ ...(person.additionalPublicKeys ? person.additionalPublicKeys.map(key => [key.id, key] as const) : []), - [person.publicKey.id, person.publicKey], + ...(Array.isArray(person.publicKey) ? person.publicKey.map(key => [key.id, key] as const) : [[person.publicKey.id, person.publicKey]] as const), ]); await transactionalEntityManager.save(Array.from(publicKeys.values(), key => new MiUserPublickey({ diff --git a/packages/backend/src/core/activitypub/type.ts b/packages/backend/src/core/activitypub/type.ts index 0cd941ae19..368650a83d 100644 --- a/packages/backend/src/core/activitypub/type.ts +++ b/packages/backend/src/core/activitypub/type.ts @@ -169,7 +169,7 @@ export interface IActor extends IObject { discoverable?: boolean; inbox: string; sharedInbox?: string; // 後方互換性のため - publicKey?: IKey; + publicKey?: IKey | IKey[]; additionalPublicKeys?: IKey[]; followers?: string | ICollection | IOrderedCollection; following?: string | ICollection | IOrderedCollection;