From 82cc3987c13db4ad0da1589386027c222ce85ff8 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] =?UTF-8?q?spec(backend/NoteCreateService):=20=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=82=AB=E3=83=AB=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E3=81=8C=E3=81=BE=E3=81=A0=E8=AA=B0=E3=82=82=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E3=81=AB=E3=82=88=E3=82=8B=E9=80=9A=E7=9F=A5=E3=82=92?= =?UTF-8?q?=E5=BC=95=E3=81=8D=E8=B5=B7=E3=81=93=E3=81=99=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E6=80=A7=E3=81=AE=E3=81=82=E3=82=8B=E6=8A=95=E7=A8=BF=E3=82=92?= =?UTF-8?q?=E6=8B=92=E5=90=A6=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=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> --- packages/backend/src/core/NoteCreateService.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 84660b05e6..58adce6c72 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -366,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)) {