From 011436d56b7d130b50885f93b935cf94b5ed00d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Sun, 18 Feb 2024 03:47:17 +0900 Subject: [PATCH 1/4] =?UTF-8?q?spec(backend/NoteCreateService):=20?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=82=AB=E3=83=AB=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E3=81=8C=E3=81=BE=E3=81=A0=E8=AA=B0=E3=82=82=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AD=E3=83=BC=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=BC=E3=81=AB=E3=82=88=E3=82=8B=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E3=82=92=E5=BC=95=E3=81=8D=E8=B5=B7=E3=81=93=E3=81=99=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E6=80=A7=E3=81=AE=E3=81=82=E3=82=8B=E6=8A=95=E7=A8=BF?= =?UTF-8?q?=E3=82=92=E6=8B=92=E5=90=A6=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=20(MisskeyIO#462)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cherry-picked from 738b4d69701a9d4b232f6a44b340782d096b182b, 1b3adcc2bbc695a0f28f5865a6705e0e59830962, 33cb50761ec12fc0df0e6f99ba97e0d5d4e580fc, a27af00e23a5283e357de1e6bf2a47ebefaa77c2, 5c6236bb0f1fde9140e331c9e1390bb5fccd4f9a Co-authored-by: Ebise Lutica <7106976+EbiseLutica@users.noreply.github.com> Co-authored-by: anatawa12 --- .../backend/src/core/NoteCreateService.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 4c0ed92cdddd..ff3e10e43b20 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -59,6 +59,9 @@ import { UtilityService } from '@/core/UtilityService.js'; import { UserBlockingService } from '@/core/UserBlockingService.js'; import { isReply } from '@/misc/is-reply.js'; import { trackPromise } from '@/misc/promise-tracker.js'; +import { IdentifiableError } from '@/misc/identifiable-error.js'; +import { LoggerService } from '@/core/LoggerService.js'; +import type Logger from '@/logger.js'; type NotificationType = 'reply' | 'renote' | 'quote' | 'mention'; @@ -149,6 +152,7 @@ type Option = { @Injectable() export class NoteCreateService implements OnApplicationShutdown { + private logger: Logger; #shutdownController = new AbortController(); public static ContainsProhibitedWordsError = class extends Error {}; @@ -219,7 +223,10 @@ export class NoteCreateService implements OnApplicationShutdown { private instanceChart: InstanceChart, private utilityService: UtilityService, private userBlockingService: UserBlockingService, - ) { } + private loggerService: LoggerService, + ) { + this.logger = this.loggerService.getLogger('note:create'); + } @bindThis public async create(user: { @@ -359,6 +366,16 @@ export class NoteCreateService implements OnApplicationShutdown { mentionedUsers = data.apMentions ?? await this.extractMentionedUsers(user, combinedTokens); } + const willCauseNotification = mentionedUsers.filter(u => u.host === null).length > 0 || data.reply?.userHost === null || data.renote?.userHost === null; + + if (process.env.MISSKEY_BLOCK_MENTIONS_FROM_UNFAMILIAR_REMOTE_USERS === 'true' && user.host !== null && willCauseNotification) { + const userEntity = await this.usersRepository.findOneBy({ id: user.id }); + if ((userEntity?.followersCount ?? 0) === 0) { + this.logger.error('Request rejected because user has no local followers', { user: user.id, note: data }); + throw new IdentifiableError('e11b3a16-f543-4885-8eb1-66cad131dbfd', 'Notes including mentions, replies, or renotes from remote users are not allowed until user has at least one local follower.'); + } + } + tags = tags.filter(tag => Array.from(tag).length <= 128).splice(0, 32); if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) { From b48621220ab07cc9e74c75396eb82d4bbebbc09e Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 20 Feb 2024 03:10:01 +0900 Subject: [PATCH 2/4] =?UTF-8?q?docs(changelog):=20=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=82=AB=E3=83=AB=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=8C?= =?UTF-8?q?=E3=81=BE=E3=81=A0=E8=AA=B0=E3=82=82=E3=83=95=E3=82=A9=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E3=83=AA?= =?UTF-8?q?=E3=83=A2=E3=83=BC=E3=83=88=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=88=E3=82=8B=E9=80=9A=E7=9F=A5=E3=82=92=E5=BC=95?= =?UTF-8?q?=E3=81=8D=E8=B5=B7=E3=81=93=E3=81=99=E5=8F=AF=E8=83=BD=E6=80=A7?= =?UTF-8?q?=E3=81=AE=E3=81=82=E3=82=8B=E6=8A=95=E7=A8=BF=E3=82=92=E6=8B=92?= =?UTF-8?q?=E5=90=A6=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d36528943f49..c981f3938f26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,15 @@ --> +## 202x.x.x-kinel.x (unreleased) + +### General + +### Client + +### Server +- ローカルユーザーがまだ誰もフォローしていないリモートユーザーによる通知を引き起こす可能性のある投稿を拒否できるように + ## 2024.2.0-kinel.1 ### Client From f93be690b1ea8befe7c6339721525a20a73d29ec Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 20 Feb 2024 03:27:37 +0900 Subject: [PATCH 3/4] chore: use config instead of env variable to enable blockMentionsFromUnfamiliarRemoteUsers --- packages/backend/src/config.ts | 3 +++ packages/backend/src/core/NoteCreateService.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index f263c4d06b06..cb92bd877920 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -100,6 +100,7 @@ type Source = { maxWebImageSize?: number; withRepliesInHomeTL?: boolean; withRepliesInUserList?: boolean; + blockMentionsFromUnfamiliarRemoteUsers?: boolean; } }; @@ -185,6 +186,7 @@ export type Config = { maxWebImageSize?: number; withRepliesInHomeTL?: boolean, withRepliesInUserList: boolean, + blockMentionsFromUnfamiliarRemoteUsers: boolean; } }; @@ -230,6 +232,7 @@ export function loadConfig(): Config { // to avoid merge conflict in the future, this is at top nirila: Object.assign({ withRepliesInUserList: true, + blockMentionsFromUnfamiliarRemoteUsers: false, }, config.nirila ?? {}), version, publishTarballInsteadOfProvideRepositoryUrl: !!config.publishTarballInsteadOfProvideRepositoryUrl, diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index ff3e10e43b20..5297f1e2d3e6 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -368,7 +368,7 @@ export class NoteCreateService implements OnApplicationShutdown { const willCauseNotification = mentionedUsers.filter(u => u.host === null).length > 0 || data.reply?.userHost === null || data.renote?.userHost === null; - if (process.env.MISSKEY_BLOCK_MENTIONS_FROM_UNFAMILIAR_REMOTE_USERS === 'true' && user.host !== null && willCauseNotification) { + if (this.config.nirila.blockMentionsFromUnfamiliarRemoteUsers && user.host !== null && willCauseNotification) { const userEntity = await this.usersRepository.findOneBy({ id: user.id }); if ((userEntity?.followersCount ?? 0) === 0) { this.logger.error('Request rejected because user has no local followers', { user: user.id, note: data }); From b13d3d2b90bec61f12239d9559fc79b257da4280 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 20 Feb 2024 03:57:05 +0900 Subject: [PATCH 4/4] Update CHANGELOG.md Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c981f3938f26..0bf9cf714d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ ### Client ### Server -- ローカルユーザーがまだ誰もフォローしていないリモートユーザーによる通知を引き起こす可能性のある投稿を拒否できるように +- ローカルユーザーがまだ誰もフォローしていないリモートユーザーによる、通知を引き起こす可能性のある投稿を拒否できるように ## 2024.2.0-kinel.1