enhance(frontend): 外部サイトへのリンクは移動の前に警告を表示するように (MisskeyIO#558)

This commit is contained in:
まっちゃとーにゅ 2024-03-22 07:43:59 +09:00 committed by GitHub
parent 722f01c4e7
commit 01ec286f3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 141 additions and 7 deletions

View File

@ -1212,6 +1212,10 @@ useGroupedNotifications: "Display grouped notifications"
signupPendingError: "There was a problem verifying the email address. The link may have expired." signupPendingError: "There was a problem verifying the email address. The link may have expired."
cwNotationRequired: "If \"Hide content\" is enabled, a description must be provided." cwNotationRequired: "If \"Hide content\" is enabled, a description must be provided."
doReaction: "Add reaction" doReaction: "Add reaction"
wellKnownWebsites: "Well-known websites"
wellKnownWebsitesDescription: "Separate with spaces for AND, new lines for OR. Surround with slashes for regular expressions. Matching will allow redirection to external sites without a warning."
warningRedirectingExternalWebsiteTitle: "You are leaving our site!"
warningRedirectingExternalWebsiteDescription: "You are about to jump to another site.\nPlease make sure this link is reliable before proceeding.\n\n{url}"
code: "Code" code: "Code"
reloadRequiredToApplySettings: "Reloading is required to apply the settings." reloadRequiredToApplySettings: "Reloading is required to apply the settings."
remainingN: "Remaining: {n}" remainingN: "Remaining: {n}"

19
locales/index.d.ts vendored
View File

@ -4860,6 +4860,25 @@ export interface Locale extends ILocale {
* *
*/ */
"doReaction": string; "doReaction": string;
/**
*
*/
"wellKnownWebsites": string;
/**
* AND指定になりOR指定になります
*/
"wellKnownWebsitesDescription": string;
/**
*
*/
"warningRedirectingExternalWebsiteTitle": string;
/**
*
*
*
* {url}
*/
"warningRedirectingExternalWebsiteDescription": ParameterizedString<"url">;
/** /**
* URL * URL
*/ */

View File

@ -1211,6 +1211,10 @@ useGroupedNotifications: "通知をグルーピングして表示する"
signupPendingError: "メールアドレスの確認中に問題が発生しました。リンクの有効期限が切れている可能性があります。" signupPendingError: "メールアドレスの確認中に問題が発生しました。リンクの有効期限が切れている可能性があります。"
cwNotationRequired: "「内容を隠す」がオンの場合は注釈の記述が必要です。" cwNotationRequired: "「内容を隠す」がオンの場合は注釈の記述が必要です。"
doReaction: "リアクションする" doReaction: "リアクションする"
wellKnownWebsites: "よく知られたウェブサイト"
wellKnownWebsitesDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。一致した場合、外部サイトへのリダイレクトの警告を省略させることができます。"
warningRedirectingExternalWebsiteTitle: "外部サイトへ移動します"
warningRedirectingExternalWebsiteDescription: "別のサイトにジャンプしようとしています。\nリンク先の安全性を十分に確認した上で進んでください。\n\n{url}"
urlPreviewDenyList: "サムネイルの表示を制限するURL" urlPreviewDenyList: "サムネイルの表示を制限するURL"
urlPreviewDenyListDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。一致した場合、サムネイルがぼかされて表示されます。" urlPreviewDenyListDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。一致した場合、サムネイルがぼかされて表示されます。"
code: "コード" code: "コード"

View File

@ -1209,6 +1209,10 @@ useGroupedNotifications: "알림을 그룹화하고 표시"
signupPendingError: "메일 주소 확인중에 문제가 발생했습니다. 링크의 유효기간이 지났을 가능성이 있습니다." signupPendingError: "메일 주소 확인중에 문제가 발생했습니다. 링크의 유효기간이 지났을 가능성이 있습니다."
cwNotationRequired: "'내용을 숨기기'를 체크한 경우 주석을 써야 합니다." cwNotationRequired: "'내용을 숨기기'를 체크한 경우 주석을 써야 합니다."
doReaction: "리액션 추가" doReaction: "리액션 추가"
wellKnownWebsites: "잘 알려진 웹사이트"
wellKnownWebsitesDescription: "공백으로 구분하면 AND 지정이 되며, 개행으로 구분하면 OR 지정이 됩니다. 슬래시로 둘러싸면 정규 표현식이 됩니다. 일치하는 경우, 외부 사이트로의 리다이렉트 경고를 생략할 수 있습니다."
warningRedirectingExternalWebsiteTitle: "외부 사이트로 이동합니다"
warningRedirectingExternalWebsiteDescription: "다른 사이트로 이동하려고 합니다.\n링크가 안전한지 충분히 확인한 후 이동해주세요.\n\n{url}"
code: "문자열" code: "문자열"
reloadRequiredToApplySettings: "설정을 적용하려면 새로고침을 해야 합니다." reloadRequiredToApplySettings: "설정을 적용하려면 새로고침을 해야 합니다."
remainingN: "나머지: {n}" remainingN: "나머지: {n}"

View File

@ -0,0 +1,11 @@
export class ExternalWebsiteWarn1711008460816 {
name = 'ExternalWebsiteWarn1711008460816'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "wellKnownWebsites" character varying(3072) array NOT NULL DEFAULT '{}'`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "wellKnownWebsites"`);
}
}

View File

@ -99,6 +99,7 @@ export class MetaEntityService {
imageUrl: ad.imageUrl, imageUrl: ad.imageUrl,
dayOfWeek: ad.dayOfWeek, dayOfWeek: ad.dayOfWeek,
})), })),
wellKnownWebsites: instance.wellKnownWebsites,
notesPerOneAd: instance.notesPerOneAd, notesPerOneAd: instance.notesPerOneAd,
enableEmail: instance.enableEmail, enableEmail: instance.enableEmail,
enableServiceWorker: instance.enableServiceWorker, enableServiceWorker: instance.enableServiceWorker,

View File

@ -594,6 +594,11 @@ export class MiMeta {
}) })
public notesPerOneAd: number; public notesPerOneAd: number;
@Column('varchar', {
length: 3072, array: true, default: '{}',
})
public wellKnownWebsites: string[];
@Column('varchar', { @Column('varchar', {
length: 3072, array: true, default: '{}', length: 3072, array: true, default: '{}',
}) })

View File

@ -183,6 +183,14 @@ export const packedMetaLiteSchema = {
}, },
}, },
}, },
wellKnownWebsites: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
notesPerOneAd: { notesPerOneAd: {
type: 'number', type: 'number',
optional: false, nullable: false, optional: false, nullable: false,

View File

@ -381,9 +381,17 @@ export const meta = {
type: 'number', type: 'number',
optional: false, nullable: false, optional: false, nullable: false,
}, },
wellKnownWebsites: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
urlPreviewDenyList: { urlPreviewDenyList: {
type: 'array', type: 'array',
optional: true, nullable: false, optional: false, nullable: false,
items: { items: {
type: 'string', type: 'string',
optional: false, nullable: false, optional: false, nullable: false,
@ -602,6 +610,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
perRemoteUserUserTimelineCacheMax: instance.perRemoteUserUserTimelineCacheMax, perRemoteUserUserTimelineCacheMax: instance.perRemoteUserUserTimelineCacheMax,
perUserHomeTimelineCacheMax: instance.perUserHomeTimelineCacheMax, perUserHomeTimelineCacheMax: instance.perUserHomeTimelineCacheMax,
perUserListTimelineCacheMax: instance.perUserListTimelineCacheMax, perUserListTimelineCacheMax: instance.perUserListTimelineCacheMax,
wellKnownWebsites: instance.wellKnownWebsites,
notesPerOneAd: instance.notesPerOneAd, notesPerOneAd: instance.notesPerOneAd,
urlPreviewDenyList: instance.urlPreviewDenyList, urlPreviewDenyList: instance.urlPreviewDenyList,
featuredGameChannels: instance.featuredGameChannels, featuredGameChannels: instance.featuredGameChannels,

View File

@ -155,6 +155,11 @@ export const paramDef = {
type: 'string', type: 'string',
}, },
}, },
wellKnownWebsites: {
type: 'array', nullable: true, items: {
type: 'string',
},
},
urlPreviewDenyList: { urlPreviewDenyList: {
type: 'array', nullable: true, items: { type: 'array', nullable: true, items: {
type: 'string', type: 'string',
@ -220,6 +225,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}).map(x => x.toLowerCase()); }).map(x => x.toLowerCase());
} }
if (Array.isArray(ps.wellKnownWebsites)) {
set.wellKnownWebsites = ps.wellKnownWebsites.filter(Boolean);
}
if (Array.isArray(ps.urlPreviewDenyList)) { if (Array.isArray(ps.urlPreviewDenyList)) {
set.urlPreviewDenyList = ps.urlPreviewDenyList.filter(Boolean); set.urlPreviewDenyList = ps.urlPreviewDenyList.filter(Boolean);
} }

View File

@ -5,8 +5,15 @@ SPDX-License-Identifier: AGPL-3.0-only
<template> <template>
<component <component
:is="self ? 'MkA' : 'a'" ref="el" style="word-break: break-all;" class="_link" :[attr]="self ? url.substring(local.length) : url" :rel="rel ?? 'nofollow noopener'" :target="target" :is="self ? 'MkA' : 'a'"
ref="el"
style="word-break: break-all;"
class="_link"
:[attr]="self ? url.substring(local.length) : url"
:rel="rel ?? 'nofollow noopener'"
:target="target"
:title="url" :title="url"
@click="(ev: MouseEvent) => warningExternalWebsite(ev, url)"
> >
<slot></slot> <slot></slot>
<i v-if="target === '_blank'" class="ti ti-external-link" :class="$style.icon"></i> <i v-if="target === '_blank'" class="ti ti-external-link" :class="$style.icon"></i>
@ -17,6 +24,7 @@ SPDX-License-Identifier: AGPL-3.0-only
import { defineAsyncComponent, ref } from 'vue'; import { defineAsyncComponent, ref } from 'vue';
import { url as local } from '@/config.js'; import { url as local } from '@/config.js';
import { useTooltip } from '@/scripts/use-tooltip.js'; import { useTooltip } from '@/scripts/use-tooltip.js';
import { warningExternalWebsite } from '@/scripts/warning-external-website.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{

View File

@ -5,7 +5,14 @@ SPDX-License-Identifier: AGPL-3.0-only
<template> <template>
<component <component
:is="self ? 'MkA' : 'a'" ref="el" :class="$style.root" class="_link" :[attr]="self ? props.url.substring(local.length) : props.url" :rel="rel ?? 'nofollow noopener'" :target="target" :is="self ? 'MkA' : 'a'"
ref="el"
:class="$style.root"
class="_link"
:[attr]="self ? props.url.substring(local.length) : props.url"
:rel="rel ?? 'nofollow noopener'"
:target="target"
@click="(ev: MouseEvent) => warningExternalWebsite(ev, props.url)"
@contextmenu.stop="() => {}" @contextmenu.stop="() => {}"
> >
<template v-if="!self"> <template v-if="!self">
@ -30,6 +37,7 @@ import { url as local } from '@/config.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { useTooltip } from '@/scripts/use-tooltip.js'; import { useTooltip } from '@/scripts/use-tooltip.js';
import { safeURIDecode } from '@/scripts/safe-uri-decode.js'; import { safeURIDecode } from '@/scripts/safe-uri-decode.js';
import { warningExternalWebsite } from '@/scripts/warning-external-website.js';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
url: string; url: string;

View File

@ -45,6 +45,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #caption>{{ i18n.ts.prohibitedWordsDescription }}<br>{{ i18n.ts.prohibitedWordsDescription2 }}</template> <template #caption>{{ i18n.ts.prohibitedWordsDescription }}<br>{{ i18n.ts.prohibitedWordsDescription2 }}</template>
</MkTextarea> </MkTextarea>
<MkTextarea v-model="wellKnownWebsites">
<template #label>{{ i18n.ts.wellKnownWebsites }}</template>
<template #caption>{{ i18n.ts.wellKnownWebsitesDescription }}</template>
</MkTextarea>
<MkTextarea v-model="urlPreviewDenyList"> <MkTextarea v-model="urlPreviewDenyList">
<template #label>{{ i18n.ts.urlPreviewDenyList }}</template> <template #label>{{ i18n.ts.urlPreviewDenyList }}</template>
<template #caption>{{ i18n.ts.urlPreviewDenyListDescription }}</template> <template #caption>{{ i18n.ts.urlPreviewDenyListDescription }}</template>
@ -91,7 +96,8 @@ const hiddenTags = ref<string>('');
const preservedUsernames = ref<string>(''); const preservedUsernames = ref<string>('');
const tosUrl = ref<string | null>(null); const tosUrl = ref<string | null>(null);
const privacyPolicyUrl = ref<string | null>(null); const privacyPolicyUrl = ref<string | null>(null);
const urlPreviewDenyList = ref<string | undefined>(''); const wellKnownWebsites = ref<string>('');
const urlPreviewDenyList = ref<string>('');
async function init() { async function init() {
const meta = await misskeyApi('admin/meta'); const meta = await misskeyApi('admin/meta');
@ -103,7 +109,8 @@ async function init() {
preservedUsernames.value = meta.preservedUsernames.join('\n'); preservedUsernames.value = meta.preservedUsernames.join('\n');
tosUrl.value = meta.tosUrl; tosUrl.value = meta.tosUrl;
privacyPolicyUrl.value = meta.privacyPolicyUrl; privacyPolicyUrl.value = meta.privacyPolicyUrl;
urlPreviewDenyList.value = meta.urlPreviewDenyList?.join('\n'); wellKnownWebsites.value = meta.wellKnownWebsites.join('\n');
urlPreviewDenyList.value = meta.urlPreviewDenyList.join('\n');
} }
function save() { function save() {
@ -116,7 +123,8 @@ function save() {
prohibitedWords: prohibitedWords.value.split('\n'), prohibitedWords: prohibitedWords.value.split('\n'),
hiddenTags: hiddenTags.value.split('\n'), hiddenTags: hiddenTags.value.split('\n'),
preservedUsernames: preservedUsernames.value.split('\n'), preservedUsernames: preservedUsernames.value.split('\n'),
urlPreviewDenyList: urlPreviewDenyList.value?.split('\n'), wellKnownWebsites: wellKnownWebsites.value.split('\n'),
urlPreviewDenyList: urlPreviewDenyList.value.split('\n'),
}).then(() => { }).then(() => {
fetchInstance(true); fetchInstance(true);
}); });

View File

@ -0,0 +1,33 @@
import { url as local } from '@/config.js';
import { instance } from '@/instance.js';
import { i18n } from '@/i18n.js';
import * as os from '@/os.js';
const isRegExp = /^\/(.+)\/(.*)$/;
export async function warningExternalWebsite(ev: MouseEvent, url: string) {
const self = url.startsWith(local);
const isWellKnownWebsite = self || instance.wellKnownWebsites.some(expression => {
const r = isRegExp.exec(expression);
if (r) {
return new RegExp(r[1], r[2]).test(url);
} else return expression.split(' ').every(keyword => url.includes(keyword));
});
if (!self && !isWellKnownWebsite) {
ev.preventDefault();
ev.stopPropagation();
const confirm = await os.confirm({
type: 'warning',
title: i18n.ts.warningRedirectingExternalWebsiteTitle,
text: i18n.tsx.warningRedirectingExternalWebsiteDescription({ url }),
});
if (confirm.canceled) return false;
window.open(url, '_blank', 'noopener');
}
return true;
}

View File

@ -4991,6 +4991,7 @@ export type components = {
imageUrl: string; imageUrl: string;
dayOfWeek: number; dayOfWeek: number;
})[]; })[];
wellKnownWebsites: string[];
/** @default 0 */ /** @default 0 */
notesPerOneAd: number; notesPerOneAd: number;
enableEmail: boolean; enableEmail: boolean;
@ -5181,7 +5182,8 @@ export type operations = {
perUserHomeTimelineCacheMax: number; perUserHomeTimelineCacheMax: number;
perUserListTimelineCacheMax: number; perUserListTimelineCacheMax: number;
notesPerOneAd: number; notesPerOneAd: number;
urlPreviewDenyList?: string[]; wellKnownWebsites: string[];
urlPreviewDenyList: string[];
featuredGameChannels: string[]; featuredGameChannels: string[];
backgroundImageUrl: string | null; backgroundImageUrl: string | null;
deeplAuthKey: string | null; deeplAuthKey: string | null;
@ -9657,6 +9659,7 @@ export type operations = {
notesPerOneAd?: number; notesPerOneAd?: number;
silencedHosts?: string[] | null; silencedHosts?: string[] | null;
sensitiveMediaHosts?: string[] | null; sensitiveMediaHosts?: string[] | null;
wellKnownWebsites?: string[] | null;
urlPreviewDenyList?: string[] | null; urlPreviewDenyList?: string[] | null;
featuredGameChannels?: string[] | null; featuredGameChannels?: string[] | null;
}; };