From 14221e78b7b98ffa93e15c211769a0e88be088e5 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sat, 3 Dec 2022 16:59:28 +0000 Subject: [PATCH] Fix forkbomb 2 also in extractApMentions and parseAudience Co-authored-by: mei23 --- .../core/remote/activitypub/models/ApMentionService.ts | 8 +++----- .../src/core/remote/activitypub/models/ApNoteService.ts | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/remote/activitypub/models/ApMentionService.ts b/packages/backend/src/core/remote/activitypub/models/ApMentionService.ts index 710e1acfaf..1275e24c62 100644 --- a/packages/backend/src/core/remote/activitypub/models/ApMentionService.ts +++ b/packages/backend/src/core/remote/activitypub/models/ApMentionService.ts @@ -6,7 +6,7 @@ import type { Config } from '@/config.js'; import { toArray, unique } from '@/misc/prelude/array.js'; import type { CacheableUser } from '@/models/entities/User.js'; import { isMention } from '../type.js'; -import { ApResolverService } from '../ApResolverService.js'; +import { ApResolverService, Resolver } from '../ApResolverService.js'; import { ApPersonService } from './ApPersonService.js'; import type { IObject, IApMention } from '../type.js'; @@ -21,11 +21,9 @@ export class ApMentionService { ) { } - public async extractApMentions(tags: IObject | IObject[] | null | undefined) { + public async extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver) { const hrefs = unique(this.extractApMentionObjects(tags).map(x => x.href as string)); - - const resolver = this.apResolverService.createResolver(); - + const limit = promiseLimit(2); const mentionedUsers = (await Promise.all( hrefs.map(x => limit(() => this.apPersonService.resolvePerson(x, resolver).catch(() => null))), diff --git a/packages/backend/src/core/remote/activitypub/models/ApNoteService.ts b/packages/backend/src/core/remote/activitypub/models/ApNoteService.ts index a34a1d1eb8..7cf6725a38 100644 --- a/packages/backend/src/core/remote/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/remote/activitypub/models/ApNoteService.ts @@ -140,7 +140,7 @@ export class ApNoteService { throw new Error('actor has been suspended'); } - const noteAudience = await this.apAudienceService.parseAudience(actor, note.to, note.cc); + const noteAudience = await this.apAudienceService.parseAudience(actor, note.to, note.cc, resolver); let visibility = noteAudience.visibility; const visibleUsers = noteAudience.visibleUsers; @@ -154,7 +154,7 @@ export class ApNoteService { let isMessaging = note._misskey_talk && visibility === 'specified'; - const apMentions = await this.apMentionService.extractApMentions(note.tag); + const apMentions = await this.apMentionService.extractApMentions(note.tag, resolver); const apHashtags = await extractApHashtags(note.tag); // 添付ファイル