From 4c4871065f022c84da04b2ba582dd690d252b0d8 Mon Sep 17 00:00:00 2001 From: Daiki Mizukami Date: Fri, 28 Jun 2024 21:45:16 +0900 Subject: [PATCH 1/2] fix(backend): Handle array values for `Actor.publicKey` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `publicKey`は複数の値を取りうるとされているので、そのケースへの対応。 cf. https://swicg.github.io/activitypub-http-signature/#how-to-obtain-a-signature-s-public-key 引用元の仕様では複数の値から適するものを選ぶように定められているが、まず は簡単のためMastodonと同様に先頭の値のみを取る形で対応した。 --- .../backend/src/core/activitypub/models/ApPersonService.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 398c8695d2eb..89acfd609b6a 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -20,7 +20,7 @@ import type Logger from '@/logger.js'; import type { MiNote } from '@/models/Note.js'; import type { IdService } from '@/core/IdService.js'; import type { MfmService } from '@/core/MfmService.js'; -import { toArray } from '@/misc/prelude/array.js'; +import { toArray, toSingle } from '@/misc/prelude/array.js'; import type { GlobalEventService } from '@/core/GlobalEventService.js'; import type { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; import type { FetchInstanceMetadataService } from '@/core/FetchInstanceMetadataService.js'; @@ -182,6 +182,8 @@ export class ApPersonService implements OnModuleInit { } if (x.publicKey) { + x.publicKey = toSingle(x.publicKey); + if (typeof x.publicKey.id !== 'string') { throw new Error('invalid Actor: publicKey.id is not a string'); } From 450988e21bd6e273b374d5714e210328f6ca742f Mon Sep 17 00:00:00 2001 From: Daiki Mizukami Date: Thu, 11 Jul 2024 22:34:05 +0900 Subject: [PATCH 2/2] fix(backend): fix typecheck --- .../backend/src/core/activitypub/models/ApPersonService.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 89acfd609b6a..0ec07eb141e4 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -181,9 +181,8 @@ export class ApPersonService implements OnModuleInit { throw new Error('invalid Actor: id has different host'); } + x.publicKey = toSingle(x.publicKey); if (x.publicKey) { - x.publicKey = toSingle(x.publicKey); - if (typeof x.publicKey.id !== 'string') { throw new Error('invalid Actor: publicKey.id is not a string'); }