From bf9e74ca053e7c541f0457c0cd12bfe2acfc08bb Mon Sep 17 00:00:00 2001 From: xtex Date: Wed, 19 Jul 2023 12:01:14 +0800 Subject: [PATCH] fix: failed to resolve acct URI which points to local Person (#11024) * fix: resolving alias for local users (#9199) Signed-off-by: xtex * style: return type for RemoteUserResolveService#resolveSelf Signed-off-by: xtex * docs: update CHANGELOG Signed-off-by: xtex * style: fix typecheck Signed-off-by: xtex --------- Signed-off-by: xtex Co-authored-by: syuilo --- CHANGELOG.md | 1 + .../src/core/RemoteUserResolveService.ts | 22 +++++++++++++++++-- packages/backend/src/core/WebfingerService.ts | 4 ++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 350afcb30e..9f7df34888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ ### Server - Fix: キャッシュが溜まり続けないように +- Fix: ローカルの `Person` を指す `acct` URI を解析するときのバグを修正しました ## 13.13.1 diff --git a/packages/backend/src/core/RemoteUserResolveService.ts b/packages/backend/src/core/RemoteUserResolveService.ts index 952d244823..e19a245e18 100644 --- a/packages/backend/src/core/RemoteUserResolveService.ts +++ b/packages/backend/src/core/RemoteUserResolveService.ts @@ -8,8 +8,9 @@ import type { LocalUser, RemoteUser } from '@/models/entities/User.js'; import type { Config } from '@/config.js'; import type Logger from '@/logger.js'; import { UtilityService } from '@/core/UtilityService.js'; -import { WebfingerService } from '@/core/WebfingerService.js'; +import { ILink, WebfingerService } from '@/core/WebfingerService.js'; import { RemoteLoggerService } from '@/core/RemoteLoggerService.js'; +import { ApDbResolverService } from '@/core/activitypub/ApDbResolverService.js'; import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js'; import { bindThis } from '@/decorators.js'; @@ -27,6 +28,7 @@ export class RemoteUserResolveService { private utilityService: UtilityService, private webfingerService: WebfingerService, private remoteLoggerService: RemoteLoggerService, + private apDbResolverService: ApDbResolverService, private apPersonService: ApPersonService, ) { this.logger = this.remoteLoggerService.logger.createSubLogger('resolve-user'); @@ -67,6 +69,22 @@ export class RemoteUserResolveService { if (user == null) { const self = await this.resolveSelf(acctLower); + if (self.href.startsWith(this.config.url)) { + const local = this.apDbResolverService.parseUri(self.href); + if (local.local && local.type === 'users') { + // the LR points to local + return (await this.apDbResolverService + .getUserFromApId(self.href) + .then((u) => { + if (u == null) { + throw new Error('local user not found'); + } else { + return u; + } + })) as LocalUser; + } + } + this.logger.succ(`return new remote user: ${chalk.magenta(acctLower)}`); return await this.apPersonService.createPerson(self.href); } @@ -119,7 +137,7 @@ export class RemoteUserResolveService { } @bindThis - private async resolveSelf(acctLower: string) { + private async resolveSelf(acctLower: string): Promise { this.logger.info(`WebFinger for ${chalk.yellow(acctLower)}`); const finger = await this.webfingerService.webfinger(acctLower).catch(err => { this.logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${ err.statusCode ?? err.message }`); diff --git a/packages/backend/src/core/WebfingerService.ts b/packages/backend/src/core/WebfingerService.ts index f58a6a10fc..6b2428cdf0 100644 --- a/packages/backend/src/core/WebfingerService.ts +++ b/packages/backend/src/core/WebfingerService.ts @@ -6,12 +6,12 @@ import { query as urlQuery } from '@/misc/prelude/url.js'; import { HttpRequestService } from '@/core/HttpRequestService.js'; import { bindThis } from '@/decorators.js'; -type ILink = { +export type ILink = { href: string; rel?: string; }; -type IWebFinger = { +export type IWebFinger = { links: ILink[]; subject: string; };