From 4da0d4be7171f11e3a30ade275b764b8335e40e0 Mon Sep 17 00:00:00 2001 From: Hazel K Date: Sat, 5 Oct 2024 22:01:55 -0400 Subject: [PATCH 1/3] add option to reject reports from an instance --- locales/en-US.yml | 3 +++ locales/index.d.ts | 16 ++++++++++++++++ locales/ja-JP.yml | 3 +++ .../1728177700920-add-reject-reports.js | 16 ++++++++++++++++ .../src/core/activitypub/ApInboxService.ts | 9 +++++++++ packages/backend/src/models/Instance.ts | 7 ++++++- .../admin/federation/update-instance.ts | 10 ++++++++++ packages/backend/src/types.ts | 10 ++++++++++ .../frontend/src/pages/admin/modlog.ModLog.vue | 4 ++++ packages/frontend/src/pages/instance-info.vue | 11 +++++++++++ 10 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 packages/backend/migration/1728177700920-add-reject-reports.js diff --git a/locales/en-US.yml b/locales/en-US.yml index 221ade4028..b4d08b73ee 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -223,6 +223,7 @@ stopActivityDelivery: "Stop sending activities" blockThisInstance: "Block this instance" silenceThisInstance: "Silence this instance" mediaSilenceThisInstance: "Silence media from this instance" +rejectReports: "Reject reports from this instance" operations: "Operations" software: "Software" version: "Version" @@ -2572,6 +2573,8 @@ _moderationLogTypes: resetPassword: "Password reset" suspendRemoteInstance: "Remote instance suspended" unsuspendRemoteInstance: "Remote instance unsuspended" + rejectRemoteInstanceReports: "Rejected reports from remote instance" + acceptRemoteInstanceReports: "Accepted reports from remote instance" updateRemoteInstanceNote: "Moderation note updated for remote instance." markSensitiveDriveFile: "File marked as sensitive" unmarkSensitiveDriveFile: "File unmarked as sensitive" diff --git a/locales/index.d.ts b/locales/index.d.ts index f93ef14325..c796174ac8 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -908,6 +908,10 @@ export interface Locale extends ILocale { * サーバーをメディアサイレンス */ "mediaSilenceThisInstance": string; + /** + * Reject reports from this instance + */ + "rejectReports": string; /** * 操作 */ @@ -3128,6 +3132,10 @@ export interface Locale extends ILocale { * 返信にサーバー情報を表示する */ "showTickerOnReplies": string; + /** + * 猫の話し方を無効にする + */ + "disableCatSpeak": string; /** * 検索MFMの検索エンジン */ @@ -9972,6 +9980,14 @@ export interface Locale extends ILocale { * リモートサーバーを再開 */ "unsuspendRemoteInstance": string; + /** + * Rejected reports from remote instance + */ + "rejectRemoteInstanceReports": string; + /** + * Accepted reports from remote instance + */ + "acceptRemoteInstanceReports": string; /** * リモートサーバーのモデレーションノート更新 */ diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 70acc3adf4..36e74e8167 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -223,6 +223,7 @@ stopActivityDelivery: "アクティビティの配送を停止" blockThisInstance: "このサーバーをブロック" silenceThisInstance: "サーバーをサイレンス" mediaSilenceThisInstance: "サーバーをメディアサイレンス" +rejectReports: "Reject reports from this instance" operations: "操作" software: "ソフトウェア" version: "バージョン" @@ -2640,6 +2641,8 @@ _moderationLogTypes: resetPassword: "パスワードをリセット" suspendRemoteInstance: "リモートサーバーを停止" unsuspendRemoteInstance: "リモートサーバーを再開" + rejectRemoteInstanceReports: "Rejected reports from remote instance" + acceptRemoteInstanceReports: "Accepted reports from remote instance" updateRemoteInstanceNote: "リモートサーバーのモデレーションノート更新" markSensitiveDriveFile: "ファイルをセンシティブ付与" unmarkSensitiveDriveFile: "ファイルをセンシティブ解除" diff --git a/packages/backend/migration/1728177700920-add-reject-reports.js b/packages/backend/migration/1728177700920-add-reject-reports.js new file mode 100644 index 0000000000..ed5f6bc559 --- /dev/null +++ b/packages/backend/migration/1728177700920-add-reject-reports.js @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +export class AddRejectReports1728177700920 { + name = 'AddRejectReports1728177700920' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "instance" ADD "rejectReports" boolean NOT NULL DEFAULT false`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "instance" DROP COLUMN "rejectReports"`); + } +} diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index 6a28cbad15..66947714b9 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -39,6 +39,8 @@ import { ApPersonService } from './models/ApPersonService.js'; import { ApQuestionService } from './models/ApQuestionService.js'; import type { Resolver } from './ApResolverService.js'; import type { IAccept, IAdd, IAnnounce, IBlock, ICreate, IDelete, IFlag, IFollow, ILike, IObject, IReject, IRemove, IUndo, IUpdate, IMove, IPost } from './type.js'; +import * as Bull from 'bullmq'; +import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; @Injectable() export class ApInboxService { @@ -83,6 +85,7 @@ export class ApInboxService { private apQuestionService: ApQuestionService, private queueService: QueueService, private globalEventService: GlobalEventService, + private federatedInstanceService: FederatedInstanceService, ) { this.logger = this.apLoggerService.logger; } @@ -530,6 +533,12 @@ export class ApInboxService { @bindThis private async flag(actor: MiRemoteUser, activity: IFlag): Promise { + // Make sure the source instance is allowed to send reports. + const instance = await this.federatedInstanceService.fetch(actor.host); + if (instance.rejectReports) { + throw new Bull.UnrecoverableError(`Rejecting report from instance: ${actor.host}`); + } + // objectは `(User|Note) | (User|Note)[]` だけど、全パターンDBスキーマと対応させられないので // 対象ユーザーは一番最初のユーザー として あとはコメントとして格納する const uris = getApIds(activity.object); diff --git a/packages/backend/src/models/Instance.ts b/packages/backend/src/models/Instance.ts index dd625f95d3..ba93190c57 100644 --- a/packages/backend/src/models/Instance.ts +++ b/packages/backend/src/models/Instance.ts @@ -158,7 +158,12 @@ export class MiInstance { default: false, }) public isNSFW: boolean; - + + @Column('boolean', { + default: false, + }) + public rejectReports: boolean; + @Column('varchar', { length: 16384, default: '', }) diff --git a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts index 8b142910a6..0d62417299 100644 --- a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts +++ b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts @@ -25,6 +25,7 @@ export const paramDef = { host: { type: 'string' }, isSuspended: { type: 'boolean' }, isNSFW: { type: 'boolean' }, + rejectReports: { type: 'boolean' }, moderationNote: { type: 'string' }, }, required: ['host'], @@ -57,6 +58,7 @@ export default class extends Endpoint { // eslint- await this.federatedInstanceService.update(instance.id, { suspensionState, isNSFW: ps.isNSFW, + rejectReports: ps.rejectReports, moderationNote: ps.moderationNote, }); @@ -74,6 +76,14 @@ export default class extends Endpoint { // eslint- } } + if (ps.rejectReports != null && instance.rejectReports !== ps.rejectReports) { + const message = ps.rejectReports ? 'rejectRemoteInstanceReports' : 'acceptRemoteInstanceReports'; + this.moderationLogService.log(me, message, { + id: instance.id, + host: instance.host, + }); + } + if (ps.moderationNote != null && instance.moderationNote !== ps.moderationNote) { this.moderationLogService.log(me, 'updateRemoteInstanceNote', { id: instance.id, diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index d83d414096..b3c3275b24 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -79,6 +79,8 @@ export const moderationLogTypes = [ 'resetPassword', 'suspendRemoteInstance', 'unsuspendRemoteInstance', + 'rejectRemoteInstanceReports', + 'acceptRemoteInstanceReports', 'updateRemoteInstanceNote', 'markSensitiveDriveFile', 'unmarkSensitiveDriveFile', @@ -235,6 +237,14 @@ export type ModerationLogPayloads = { id: string; host: string; }; + rejectRemoteInstanceReports: { + id: string; + host: string; + }; + acceptRemoteInstanceReports: { + id: string; + host: string; + }; updateRemoteInstanceNote: { id: string; host: string; diff --git a/packages/frontend/src/pages/admin/modlog.ModLog.vue b/packages/frontend/src/pages/admin/modlog.ModLog.vue index f6f276de53..63e04e5bdd 100644 --- a/packages/frontend/src/pages/admin/modlog.ModLog.vue +++ b/packages/frontend/src/pages/admin/modlog.ModLog.vue @@ -23,6 +23,8 @@ SPDX-License-Identifier: AGPL-3.0-only 'markSensitiveDriveFile', 'resetPassword', 'suspendRemoteInstance', + 'rejectRemoteInstanceReports', + 'acceptRemoteInstanceReports', ].includes(log.type), [$style.logRed]: [ 'suspend', @@ -61,6 +63,8 @@ SPDX-License-Identifier: AGPL-3.0-only : @{{ log.info.fileUserUsername }}{{ log.info.fileUserHost ? '@' + log.info.fileUserHost : '' }} : {{ log.info.host }} : {{ log.info.host }} + : {{ log.info.host }} + : {{ log.info.host }} : {{ log.info.announcement.title }} : {{ log.info.before.title }} : {{ log.info.announcement.title }} diff --git a/packages/frontend/src/pages/instance-info.vue b/packages/frontend/src/pages/instance-info.vue index 4ff26197d8..f5cc37a490 100644 --- a/packages/frontend/src/pages/instance-info.vue +++ b/packages/frontend/src/pages/instance-info.vue @@ -48,6 +48,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{ i18n.ts.blockThisInstance }} {{ i18n.ts.silenceThisInstance }} Mark as NSFW + {{ i18n.ts.rejectReports }} {{ i18n.ts.mediaSilenceThisInstance }} Refresh metadata @@ -170,6 +171,7 @@ const suspensionState = ref<'none' | 'manuallySuspended' | 'goneSuspended' | 'au const isBlocked = ref(false); const isSilenced = ref(false); const isNSFW = ref(false); +const rejectReports = ref(false); const isMediaSilenced = ref(false); const faviconUrl = ref(null); const moderationNote = ref(''); @@ -200,6 +202,7 @@ async function fetch(): Promise { isBlocked.value = instance.value?.isBlocked ?? false; isSilenced.value = instance.value?.isSilenced ?? false; isNSFW.value = instance.value?.isNSFW ?? false; + rejectReports.value = instance.value?.rejectReports ?? false; isMediaSilenced.value = instance.value?.isMediaSilenced ?? false; faviconUrl.value = getProxiedImageUrlNullable(instance.value?.faviconUrl, 'preview') ?? getProxiedImageUrlNullable(instance.value?.iconUrl, 'preview'); moderationNote.value = instance.value?.moderationNote ?? ''; @@ -260,6 +263,14 @@ async function toggleNSFW(): Promise { }); } +async function toggleRejectReports(): Promise { + if (!instance.value) throw new Error('No instance?'); + await misskeyApi('admin/federation/update-instance', { + host: instance.value.host, + rejectReports: rejectReports.value, + }); +} + function refreshMetadata(): void { if (!instance.value) throw new Error('No instance?'); misskeyApi('admin/federation/refresh-remote-instance-metadata', { From 61124699da77991af70720838d4b8dec95c09e94 Mon Sep 17 00:00:00 2001 From: Hazel K Date: Sat, 5 Oct 2024 22:21:00 -0400 Subject: [PATCH 2/3] fix lint errors --- packages/backend/src/core/activitypub/ApInboxService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index 66947714b9..bce67a458f 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -5,6 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { In } from 'typeorm'; +import * as Bull from 'bullmq'; import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { UserFollowingService } from '@/core/UserFollowingService.js'; @@ -29,6 +30,7 @@ import { bindThis } from '@/decorators.js'; import type { MiRemoteUser } from '@/models/User.js'; import { GlobalEventService } from '@/core/GlobalEventService.js'; import { AbuseReportService } from '@/core/AbuseReportService.js'; +import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; import { getApHrefNullable, getApId, getApIds, getApType, isAccept, isActor, isAdd, isAnnounce, isBlock, isCollection, isCollectionOrOrderedCollection, isCreate, isDelete, isFlag, isFollow, isLike, isMove, isPost, isReject, isRemove, isTombstone, isUndo, isUpdate, validActor, validPost } from './type.js'; import { ApNoteService } from './models/ApNoteService.js'; import { ApLoggerService } from './ApLoggerService.js'; @@ -39,8 +41,6 @@ import { ApPersonService } from './models/ApPersonService.js'; import { ApQuestionService } from './models/ApQuestionService.js'; import type { Resolver } from './ApResolverService.js'; import type { IAccept, IAdd, IAnnounce, IBlock, ICreate, IDelete, IFlag, IFollow, ILike, IObject, IReject, IRemove, IUndo, IUpdate, IMove, IPost } from './type.js'; -import * as Bull from 'bullmq'; -import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; @Injectable() export class ApInboxService { From 7dd296017b835771f9c8e9a39da1e8348938f7f2 Mon Sep 17 00:00:00 2001 From: Hazel K Date: Sat, 5 Oct 2024 22:43:34 -0400 Subject: [PATCH 3/3] fix modlog and translations for "Mark as NSFW" --- locales/en-US.yml | 3 +++ locales/index.d.ts | 12 ++++++++++++ locales/ja-JP.yml | 3 +++ .../endpoints/admin/federation/update-instance.ts | 8 ++++++++ packages/backend/src/types.ts | 10 ++++++++++ packages/frontend/src/pages/admin/modlog.ModLog.vue | 4 ++++ packages/frontend/src/pages/instance-info.vue | 2 +- 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index b4d08b73ee..dfd236b9c5 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -149,6 +149,7 @@ renoteUnmute: "Unmute Boosts" block: "Block" unblock: "Unblock" markAsNSFW: "Mark all media from user as NSFW" +markInstanceAsNSFW: "Mark as NSFW" suspend: "Suspend" unsuspend: "Unsuspend" blockConfirm: "Are you sure that you want to block this account?" @@ -2573,6 +2574,8 @@ _moderationLogTypes: resetPassword: "Password reset" suspendRemoteInstance: "Remote instance suspended" unsuspendRemoteInstance: "Remote instance unsuspended" + setRemoteInstanceNSFW: "Set remote instance as NSFW" + unsetRemoteInstanceNSFW: "Set remote instance as NSFW" rejectRemoteInstanceReports: "Rejected reports from remote instance" acceptRemoteInstanceReports: "Accepted reports from remote instance" updateRemoteInstanceNote: "Moderation note updated for remote instance." diff --git a/locales/index.d.ts b/locales/index.d.ts index c796174ac8..fb8d9339fc 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -612,6 +612,10 @@ export interface Locale extends ILocale { * ユーザーのすべてのメディアをNSFWとしてマークする */ "markAsNSFW": string; + /** + * Mark as NSFW + */ + "markInstanceAsNSFW": string; /** * 凍結 */ @@ -9980,6 +9984,14 @@ export interface Locale extends ILocale { * リモートサーバーを再開 */ "unsuspendRemoteInstance": string; + /** + * Set remote instance as NSFW + */ + "setRemoteInstanceNSFW": string; + /** + * Set remote instance as NSFW + */ + "unsetRemoteInstanceNSFW": string; /** * Rejected reports from remote instance */ diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 36e74e8167..d86b7a73d1 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -149,6 +149,7 @@ renoteUnmute: "ブーストのミュートを解除" block: "ブロック" unblock: "ブロック解除" markAsNSFW: "ユーザーのすべてのメディアをNSFWとしてマークする" +markInstanceAsNSFW: "Mark as NSFW" suspend: "凍結" unsuspend: "解凍" blockConfirm: "ブロックしますか?" @@ -2641,6 +2642,8 @@ _moderationLogTypes: resetPassword: "パスワードをリセット" suspendRemoteInstance: "リモートサーバーを停止" unsuspendRemoteInstance: "リモートサーバーを再開" + setRemoteInstanceNSFW: "Set remote instance as NSFW" + unsetRemoteInstanceNSFW: "Set remote instance as NSFW" rejectRemoteInstanceReports: "Rejected reports from remote instance" acceptRemoteInstanceReports: "Accepted reports from remote instance" updateRemoteInstanceNote: "リモートサーバーのモデレーションノート更新" diff --git a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts index 0d62417299..daf19c4435 100644 --- a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts +++ b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts @@ -76,6 +76,14 @@ export default class extends Endpoint { // eslint- } } + if (ps.isNSFW != null && instance.isNSFW !== ps.isNSFW) { + const message = ps.rejectReports ? 'setRemoteInstanceNSFW' : 'unsetRemoteInstanceNSFW'; + this.moderationLogService.log(me, message, { + id: instance.id, + host: instance.host, + }); + } + if (ps.rejectReports != null && instance.rejectReports !== ps.rejectReports) { const message = ps.rejectReports ? 'rejectRemoteInstanceReports' : 'acceptRemoteInstanceReports'; this.moderationLogService.log(me, message, { diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index b3c3275b24..d64d72c07f 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -77,6 +77,8 @@ export const moderationLogTypes = [ 'deleteGlobalAnnouncement', 'deleteUserAnnouncement', 'resetPassword', + 'setRemoteInstanceNSFW', + 'unsetRemoteInstanceNSFW', 'suspendRemoteInstance', 'unsuspendRemoteInstance', 'rejectRemoteInstanceReports', @@ -229,6 +231,14 @@ export type ModerationLogPayloads = { userUsername: string; userHost: string | null; }; + setRemoteInstanceNSFW: { + id: string; + host: string; + }; + unsetRemoteInstanceNSFW: { + id: string; + host: string; + }; suspendRemoteInstance: { id: string; host: string; diff --git a/packages/frontend/src/pages/admin/modlog.ModLog.vue b/packages/frontend/src/pages/admin/modlog.ModLog.vue index 63e04e5bdd..9fe804b2bd 100644 --- a/packages/frontend/src/pages/admin/modlog.ModLog.vue +++ b/packages/frontend/src/pages/admin/modlog.ModLog.vue @@ -23,6 +23,8 @@ SPDX-License-Identifier: AGPL-3.0-only 'markSensitiveDriveFile', 'resetPassword', 'suspendRemoteInstance', + 'setRemoteInstanceNSFW', + 'unsetRemoteInstanceNSFW', 'rejectRemoteInstanceReports', 'acceptRemoteInstanceReports', ].includes(log.type), @@ -63,6 +65,8 @@ SPDX-License-Identifier: AGPL-3.0-only : @{{ log.info.fileUserUsername }}{{ log.info.fileUserHost ? '@' + log.info.fileUserHost : '' }} : {{ log.info.host }} : {{ log.info.host }} + : {{ log.info.host }} + : {{ log.info.host }} : {{ log.info.host }} : {{ log.info.host }} : {{ log.info.announcement.title }} diff --git a/packages/frontend/src/pages/instance-info.vue b/packages/frontend/src/pages/instance-info.vue index f5cc37a490..b5803ab3f1 100644 --- a/packages/frontend/src/pages/instance-info.vue +++ b/packages/frontend/src/pages/instance-info.vue @@ -47,7 +47,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{ i18n.ts._delivery.resume }} {{ i18n.ts.blockThisInstance }} {{ i18n.ts.silenceThisInstance }} - Mark as NSFW + {{ i18n.ts.markInstanceAsNSFW }} {{ i18n.ts.rejectReports }} {{ i18n.ts.mediaSilenceThisInstance }} Refresh metadata