Skip to content

Commit 134ecbe

Browse files
u1-liquidEbiseLutica
authored andcommitted
spec(backend/NoteCreateService): ローカルユーザーがまだ誰もフォローしていないリモートユーザーによる通知を引き起こす可能性のある投稿を拒否できるように (MisskeyIO#462)
Cherry-picked from 738b4d6, 1b3adcc, 33cb507, a27af00, 5c6236b Co-authored-by: Ebise Lutica <7106976+EbiseLutica@users.noreply.github.com>
1 parent 8815630 commit 134ecbe

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/backend/src/core/NoteCreateService.ts

+10
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,16 @@ export class NoteCreateService implements OnApplicationShutdown {
359359
mentionedUsers = data.apMentions ?? await this.extractMentionedUsers(user, combinedTokens);
360360
}
361361

362+
const willCauseNotification = mentionedUsers.filter(u => u.host === null).length > 0 || data.reply?.userHost === null || data.renote?.userHost === null;
363+
364+
if (process.env.MISSKEY_BLOCK_MENTIONS_FROM_UNFAMILIAR_REMOTE_USERS === 'true' && user.host !== null && willCauseNotification) {
365+
const userEntity = await this.usersRepository.findOneBy({ id: user.id });
366+
if ((userEntity?.followersCount ?? 0) === 0) {
367+
this.logger.error('Request rejected because user has no local followers', { user: user.id, note: data });
368+
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.');
369+
}
370+
}
371+
362372
tags = tags.filter(tag => Array.from(tag).length <= 128).splice(0, 32);
363373

364374
if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) {

0 commit comments

Comments
 (0)