From 37c119e1f5b776b3eb3d9a165e5f68319b0612a6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 May 2023 17:45:13 +0900 Subject: [PATCH 1/9] refactor --- packages/frontend/src/components/MkWidgets.vue | 2 ++ packages/frontend/src/pages/explore.users.vue | 18 +++--------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/frontend/src/components/MkWidgets.vue b/packages/frontend/src/components/MkWidgets.vue index 33e594acd..ad1c02a48 100644 --- a/packages/frontend/src/components/MkWidgets.vue +++ b/packages/frontend/src/components/MkWidgets.vue @@ -32,6 +32,7 @@ + + - - From 02059fdee41bb5a345eb8f93583cde62d79e1489 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 May 2023 17:45:54 +0900 Subject: [PATCH 2/9] bump --- CHANGELOG.md | 5 +---- package.json | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 767f98e8e..d2cdde81d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ --> -## 13.x.x (unreleased) +## 13.12.2 ### General - 投稿したコンテンツのAIによる学習を軽減するオプションを追加 @@ -20,9 +20,6 @@ ### Client - Fix: ブラーエフェクトを有効にしている状態で高負荷になる問題を修正 -### Server -- - ## 13.12.1 ### Client diff --git a/package.json b/package.json index 28e1cdcf1..5379dcffa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "misskey", - "version": "13.12.1", + "version": "13.12.2", "codename": "nasubi", "repository": { "type": "git", From f9f115b66debc704292778b57b377e85c5371c20 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 May 2023 17:49:30 +0900 Subject: [PATCH 3/9] refactor(frontend): use css module --- packages/frontend/src/components/MkRadio.vue | 95 +++++++++----------- 1 file changed, 43 insertions(+), 52 deletions(-) diff --git a/packages/frontend/src/components/MkRadio.vue b/packages/frontend/src/components/MkRadio.vue index 5db2f5ee6..eea94d469 100644 --- a/packages/frontend/src/components/MkRadio.vue +++ b/packages/frontend/src/components/MkRadio.vue @@ -1,8 +1,7 @@ @@ -39,8 +39,8 @@ function toggle(): void { } - From ed634b4b3d784244639ca0829064148239b66a40 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 May 2023 17:53:01 +0900 Subject: [PATCH 4/9] refactor(frontend): use css module --- packages/frontend/src/components/MkSwitch.vue | 149 +++++++++--------- 1 file changed, 72 insertions(+), 77 deletions(-) diff --git a/packages/frontend/src/components/MkSwitch.vue b/packages/frontend/src/components/MkSwitch.vue index d9f6716f9..63738b6a4 100644 --- a/packages/frontend/src/components/MkSwitch.vue +++ b/packages/frontend/src/components/MkSwitch.vue @@ -1,21 +1,19 @@ @@ -45,52 +43,12 @@ const toggle = () => { }; - From ea9a95cd98bc4c4f337b99fe7e1b28b3781d14b3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 May 2023 17:53:49 +0900 Subject: [PATCH 5/9] delete unused component --- .../frontend/src/components/MkCheckbox.vue | 144 ------------------ 1 file changed, 144 deletions(-) delete mode 100644 packages/frontend/src/components/MkCheckbox.vue diff --git a/packages/frontend/src/components/MkCheckbox.vue b/packages/frontend/src/components/MkCheckbox.vue deleted file mode 100644 index a8e24dd83..000000000 --- a/packages/frontend/src/components/MkCheckbox.vue +++ /dev/null @@ -1,144 +0,0 @@ - - - - - From c15b75e4774a10a2aad72ffb63dd74e1123ea57d Mon Sep 17 00:00:00 2001 From: nenohi Date: Wed, 10 May 2023 18:02:41 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=E3=82=BB=E3=83=B3=E3=82=B7=E3=83=86?= =?UTF-8?q?=E3=82=A3=E3=83=96=E3=83=AF=E3=83=BC=E3=83=89=E3=82=92=E6=AD=A3?= =?UTF-8?q?=E8=A6=8F=E8=A1=A8=E7=8F=BE=E3=80=81CW=E3=81=AB=E3=82=82?= =?UTF-8?q?=E9=81=A9=E7=94=A8=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20(#10688)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * cwにセンシティブが効いてない * CWが無いときにTextを見るように * 比較演算子間違えた * とりあえずチェック * 正規表現対応 * /test/giにも対応 * matchでしなくてもいいのでは感 * レビュー修正 * Update packages/backend/src/core/NoteCreateService.ts Co-authored-by: Acid Chicken (硫酸鶏) * Update packages/backend/src/core/NoteCreateService.ts Co-authored-by: Acid Chicken (硫酸鶏) * 修正 * wipかも * wordsでスペース区切りのものできたかも * なんか動いたかも * test作成 * 文言の修正 * 修正 * note参照 --------- Co-authored-by: Acid Chicken (硫酸鶏) --- CHANGELOG.md | 1 + locales/ja-JP.yml | 1 + .../backend/src/core/NoteCreateService.ts | 29 +++++++++- packages/backend/test/e2e/note.ts | 55 +++++++++++++++++++ .../frontend/src/pages/admin/moderation.vue | 2 +- 5 files changed, 86 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2cdde81d..961e5fcca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ - カスタム絵文字のライセンスを複数でセットできるようになりました。 - 管理者が予約ユーザー名を設定できるようになりました。 - Fix: フォローリクエストの通知が残る問題を修正 +- センシティブワードの登録にAnd、正規表現が使用できるようになりました。 ### Client - アカウント作成時に初期設定ウィザードを表示するように diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index cfad31348..4f458dc4e 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -990,6 +990,7 @@ rolesAssignedToMe: "自分に割り当てられたロール" resetPasswordConfirm: "パスワードリセットしますか?" sensitiveWords: "センシティブワード" sensitiveWordsDescription: "設定したワードが含まれるノートの公開範囲をホームにします。改行で区切って複数設定できます。" +sensitiveWordsDescription2: "スペースで区切るとAND指定になり、キーワードをスラッシュで囲むと正規表現になります。" notesSearchNotAvailable: "ノート検索は利用できません。" license: "ライセンス" unfavoriteConfirm: "お気に入り解除しますか?" diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 364976e4a..977c9052c 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -3,6 +3,7 @@ import * as mfm from 'mfm-js'; import { In, DataSource } from 'typeorm'; import * as Redis from 'ioredis'; import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common'; +import RE2 from 're2'; import { extractMentions } from '@/misc/extract-mentions.js'; import { extractCustomEmojisFromMfm } from '@/misc/extract-custom-emojis-from-mfm.js'; import { extractHashtags } from '@/misc/extract-hashtags.js'; @@ -238,7 +239,8 @@ export class NoteCreateService implements OnApplicationShutdown { if (data.channel != null) data.localOnly = true; if (data.visibility === 'public' && data.channel == null) { - if ((data.text != null) && (await this.metaService.fetch()).sensitiveWords.some(w => data.text!.includes(w))) { + const sensitiveWords = (await this.metaService.fetch()).sensitiveWords; + if (this.isSensitive(data, sensitiveWords)) { data.visibility = 'home'; } else if ((await this.roleService.getUserPolicies(user.id)).canPublicNote === false) { data.visibility = 'home'; @@ -670,6 +672,31 @@ export class NoteCreateService implements OnApplicationShutdown { // Register to search database this.index(note); } + + @bindThis + private isSensitive(note: Option, sensitiveWord: string[]): boolean { + if (sensitiveWord.length > 0) { + const text = note.cw ?? note.text ?? ''; + if (text === '') return false; + const matched = sensitiveWord.some(filter => { + // represents RegExp + const regexp = filter.match(/^\/(.+)\/(.*)$/); + // This should never happen due to input sanitisation. + if (!regexp) { + const words = filter.split(' '); + return words.every(keyword => text.includes(keyword)); + } + try { + return new RE2(regexp[1], regexp[2]).test(text); + } catch (err) { + // This should never happen due to input sanitisation. + return false; + } + }); + if (matched) return true; + } + return false; + } @bindThis private incRenoteCount(renote: Note) { diff --git a/packages/backend/test/e2e/note.ts b/packages/backend/test/e2e/note.ts index 9c851a5dd..d2eb8f01d 100644 --- a/packages/backend/test/e2e/note.ts +++ b/packages/backend/test/e2e/note.ts @@ -541,6 +541,61 @@ describe('Note', () => { assert.strictEqual(res.status, 400); }); + + test('センシティブな投稿はhomeになる (単語指定)', async () => { + const sensitive = await api('admin/update-meta', { + sensitiveWords: [ + "test", + ] + }, alice); + + assert.strictEqual(sensitive.status, 204); + + await new Promise(x => setTimeout(x, 2)); + + const note1 = await api('/notes/create', { + text: 'hogetesthuge', + }, alice); + + assert.strictEqual(note1.status, 200); + assert.strictEqual(note1.body.createdNote.visibility, 'home'); + + }); + + test('センシティブな投稿はhomeになる (正規表現)', async () => { + const sensitive = await api('admin/update-meta', { + sensitiveWords: [ + "/Test/i", + ] + }, alice); + + assert.strictEqual(sensitive.status, 204); + + const note2 = await api('/notes/create', { + text: 'hogetesthuge', + }, alice); + + assert.strictEqual(note2.status, 200); + assert.strictEqual(note2.body.createdNote.visibility, 'home'); + }); + + test('センシティブな投稿はhomeになる (スペースアンド)', async () => { + const sensitive = await api('admin/update-meta', { + sensitiveWords: [ + "Test hoge" + ] + }, alice); + + assert.strictEqual(sensitive.status, 204); + + const note2 = await api('/notes/create', { + text: 'hogeTesthuge', + }, alice); + + assert.strictEqual(note2.status, 200); + assert.strictEqual(note2.body.createdNote.visibility, 'home'); + + }); }); describe('notes/delete', () => { diff --git a/packages/frontend/src/pages/admin/moderation.vue b/packages/frontend/src/pages/admin/moderation.vue index ffd3b6e23..bf788e360 100644 --- a/packages/frontend/src/pages/admin/moderation.vue +++ b/packages/frontend/src/pages/admin/moderation.vue @@ -27,7 +27,7 @@ - + From 11ea1a28110fb735462dbe1dbceb1ca58e206f32 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 May 2023 18:03:16 +0900 Subject: [PATCH 7/9] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 961e5fcca..d680a6984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ ### Client - Fix: ブラーエフェクトを有効にしている状態で高負荷になる問題を修正 +### Server +- センシティブワードの登録にAnd、正規表現が使用できるようになりました。 + ## 13.12.1 ### Client @@ -57,7 +60,6 @@ - カスタム絵文字のライセンスを複数でセットできるようになりました。 - 管理者が予約ユーザー名を設定できるようになりました。 - Fix: フォローリクエストの通知が残る問題を修正 -- センシティブワードの登録にAnd、正規表現が使用できるようになりました。 ### Client - アカウント作成時に初期設定ウィザードを表示するように From 6d4d9f417b75fb8021827db1bf66bf6c40af31d2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 May 2023 18:26:02 +0900 Subject: [PATCH 8/9] New Crowdin updates (#10823) * New translations ja-JP.yml (English) * New translations ja-JP.yml (German) --- locales/de-DE.yml | 2 ++ locales/en-US.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/locales/de-DE.yml b/locales/de-DE.yml index a082130ac..466872c0a 100644 --- a/locales/de-DE.yml +++ b/locales/de-DE.yml @@ -1038,6 +1038,8 @@ thisChannelArchived: "Dieser Kanal wurde archiviert." displayOfNote: "Anzeige von Notizen" initialAccountSetting: "Kontoeinrichtung" youFollowing: "Gefolgt" +preventAiLarning: "Verwendung in machinellem Lernen (AI/KI) ablehnen" +preventAiLarningDescription: "Fordert Crawler auf, gepostetes Text- oder Bildmaterial usw. nicht in Datensätzen für maschinelles Lernen (AI/KI) zu verwenden. Dies wird durch das Hinzufügen eines \"noai\"-HTML-Tags an den jeweiligen Inhalt erreicht. Da dieser Tag jedoch ignoriert werden kann, ist eine vollständige Verhinderung hierdurch nicht möglich." _initialAccountSetting: accountCreated: "Dein Konto wurde erfolgreich erstellt!" letsStartAccountSetup: "Lass uns nun dein Konto einrichten." diff --git a/locales/en-US.yml b/locales/en-US.yml index 6d994cb29..1c472a36c 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1038,6 +1038,8 @@ thisChannelArchived: "This channel has been archived." displayOfNote: "Note display" initialAccountSetting: "Profile setup" youFollowing: "Followed" +preventAiLarning: "Reject usage in Machine Learning (AI)" +preventAiLarningDescription: "Requests crawlers to not use posted text or image material etc. in machine learning (AI) data sets. This is achieved by adding a \"noai\" HTML-Tag to the respective content. A complete prevention can however not be achieved through this tag, as it may simply be ignored." _initialAccountSetting: accountCreated: "Your account was successfully created!" letsStartAccountSetup: "For starters, let's set up your profile." From 69afd0480e176b105ad1482c7fc72480ecd1b51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Wed, 10 May 2023 10:33:49 +0000 Subject: [PATCH 9/9] ci: fix typo --- .github/workflows/storybook.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/storybook.yml b/.github/workflows/storybook.yml index eb6ace27d..05efbb12e 100644 --- a/.github/workflows/storybook.yml +++ b/.github/workflows/storybook.yml @@ -20,7 +20,7 @@ jobs: fetch-depth: 0 submodules: true - name: Checkout HEAD - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request_target' run: git checkout ${{ github.head_ref }} - name: Install pnpm uses: pnpm/action-setup@v2 @@ -41,12 +41,12 @@ jobs: - name: Build storybook run: pnpm --filter frontend build-storybook - name: Publish to Chromatic - if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' + if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/master' run: pnpm --filter frontend chromatic --exit-once-uploaded -d storybook-static env: CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} - name: Publish to Chromatic - if: github.event_name != 'pull_request' && github.ref != 'refs/heads/master' + if: github.event_name != 'pull_request_target' && github.ref != 'refs/heads/master' id: chromatic_push run: | DIFF="${{ github.event.before }} HEAD" @@ -61,7 +61,7 @@ jobs: env: CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} - name: Publish to Chromatic - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request_target' id: chromatic_pull_request run: | DIFF="${{ github.base_ref }} HEAD" @@ -77,7 +77,7 @@ jobs: CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} - name: Notify that Chromatic will skip testing uses: actions/github-script@v6.4.0 - if: github.event_name == 'pull_request' && steps.chromatic_pull_request.outputs.skip == 'true' + if: github.event_name == 'pull_request_target' && steps.chromatic_pull_request.outputs.skip == 'true' with: github-token: ${{ secrets.GITHUB_TOKEN }} script: |