Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 外部サイトへのリンクは移動の前に警告を表示するように #13557

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
58a98da
ノートに含まれたURLが外部サイトの場合、警告ダイアログを表示するか設定できるように
camilla-ett Mar 11, 2024
0341328
ダイアログの挙動を修正
camilla-ett Mar 11, 2024
bf37e95
enhance(frontend): 外部サイトへのリンクは移動の前に警告を表示するように (MisskeyIO#558)
u1-liquid Mar 21, 2024
e6e119c
add dedicated dialog
kakkokari-gtyih Mar 22, 2024
afd7099
Merge branch 'develop' into alert_other_host
kakkokari-gtyih Mar 22, 2024
4306ad8
Merge branch 'feat-13614' into alert_other_host
kakkokari-gtyih Mar 22, 2024
4590046
spdx
kakkokari-gtyih Mar 22, 2024
05138da
Use dedicated dialog
kakkokari-gtyih Mar 22, 2024
4ca7214
fix(MkUrlPreview): 外部サイトへのリンクは移動の前に警告を表示するように
u1-liquid Mar 21, 2024
7089341
fix
kakkokari-gtyih Mar 22, 2024
c8b340d
Update Changelog
kakkokari-gtyih Mar 22, 2024
e626e25
trustedDomainsの保存場所をローカルに変更
kakkokari-gtyih Mar 22, 2024
0aa1b0e
Merge branch 'develop' into alert_other_host
kakkokari-gtyih Mar 22, 2024
eb7d9c7
Add comment
kakkokari-gtyih Mar 22, 2024
a4cc888
comment
kakkokari-gtyih Mar 22, 2024
e010342
enhance(frontend): 外部サイトへのリンクは移動の警告の条件の調整 (MisskeyIO#564)
u1-liquid Mar 22, 2024
abf6a74
use url
kakkokari-gtyih Mar 22, 2024
d520644
fix types
kakkokari-gtyih Mar 22, 2024
ff3b25e
Merge branch 'develop' into alert_other_host
kakkokari-gtyih Mar 23, 2024
523fad6
Revert "use url"
kakkokari-gtyih Mar 24, 2024
ce04e88
Merge branch 'develop' into alert_other_host
kakkokari-gtyih Mar 24, 2024
9114c55
`wellKnownWebsites` -> `trustedLinkUrlPatterns`
kakkokari-gtyih Mar 24, 2024
483bdc6
`_urlWarning` -> `_externalNavigationWarning`
kakkokari-gtyih Mar 24, 2024
d34b6d2
Merge branch 'develop' into alert_other_host
kakkokari-gtyih Mar 25, 2024
fb02dfa
Update index.d.ts
syuilo Mar 25, 2024
374cfe9
wip
syuilo Mar 25, 2024
991f973
Merge branch 'develop' into pr/13557
syuilo Mar 27, 2024
c9b4801
wip
syuilo Mar 27, 2024
ca54992
clean up
syuilo Mar 29, 2024
274bc4e
Merge branch 'develop' into alert_other_host
kakkokari-gtyih Mar 31, 2024
c2fae88
Merge branch 'develop' into alert_other_host
kakkokari-gtyih Mar 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- コントロールパネル内にあるサマリープロキシの設定個所がセキュリティから全般へ変更となります。

### General
- Feat: 外部サイトへのリンクは移動の前に警告を表示するように
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/558 and https://github.com/MisskeyIO/misskey/commit/f7ec503b9ceb34d61a0dbd658858915eb7399c5d)
- Enhance: URLプレビューの有効化・無効化を設定できるように #13569
- Enhance: アンテナでBotによるノートを除外できるように
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/545)
Expand Down
23 changes: 23 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4812,6 +4812,14 @@ export interface Locale extends ILocale {
* リアクションする
*/
"doReaction": string;
/**
* よく知られたウェブサイト
*/
"wellKnownWebsites": string;
/**
* スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。一致した場合、外部サイトへのリダイレクトの警告を省略させることができます。
*/
"wellKnownWebsitesDescription": string;
/**
* コード
*/
Expand Down Expand Up @@ -9834,6 +9842,21 @@ export interface Locale extends ILocale {
*/
"summaryProxyDescription2": string;
};
"_urlWarning": {
/**
* 外部サイトに移動します
*/
"title": string;
/**
* 別のサイトに移動しようとしています。
* リンク先の安全性を十分に確認した上で進んでください。
*/
"description": string;
/**
* 今後{domain}のリンクを信頼する
*/
"trustThisDomain": ParameterizedString<"domain">;
};
}
declare const locales: {
[lang: string]: Locale;
Expand Down
7 changes: 7 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,8 @@ useGroupedNotifications: "通知をグルーピングして表示する"
signupPendingError: "メールアドレスの確認中に問題が発生しました。リンクの有効期限が切れている可能性があります。"
cwNotationRequired: "「内容を隠す」がオンの場合は注釈の記述が必要です。"
doReaction: "リアクションする"
wellKnownWebsites: "よく知られたウェブサイト"
wellKnownWebsitesDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。一致した場合、外部サイトへのリダイレクトの警告を省略させることができます。"
code: "コード"
reloadRequiredToApplySettings: "設定の反映にはリロードが必要です。"
remainingN: "残り: {n}"
Expand Down Expand Up @@ -2619,3 +2621,8 @@ _urlPreviewSetting:
summaryProxy: "プレビューを生成するプロキシのエンドポイント"
summaryProxyDescription: "Misskey本体ではなく、サマリープロキシを使用してプレビューを生成します。"
summaryProxyDescription2: "プロキシには下記パラメータがクエリ文字列として連携されます。プロキシ側がこれらをサポートしない場合、設定値は無視されます。"

_urlWarning:
kakkokari-gtyih marked this conversation as resolved.
Show resolved Hide resolved
title: "外部サイトに移動します"
description: "別のサイトに移動しようとしています。\nリンク先の安全性を十分に確認した上で進んでください。"
trustThisDomain: "今後{domain}のリンクを信頼する"
16 changes: 16 additions & 0 deletions packages/backend/migration/1711008460816-external-website-warn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

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"`);
}
}
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/MetaEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class MetaEntityService {
imageUrl: ad.imageUrl,
dayOfWeek: ad.dayOfWeek,
})),
wellKnownWebsites: instance.wellKnownWebsites,
notesPerOneAd: instance.notesPerOneAd,
enableEmail: instance.enableEmail,
enableServiceWorker: instance.enableServiceWorker,
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@ export class MiMeta {
})
public urlPreviewRequireContentLength: boolean;

@Column('varchar', {
length: 3072, array: true, default: '{}',
})
public wellKnownWebsites: string[];
kakkokari-gtyih marked this conversation as resolved.
Show resolved Hide resolved

@Column('varchar', {
length: 1024,
nullable: true,
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/models/json-schema/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ export const packedMetaLiteSchema = {
},
},
},
wellKnownWebsites: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
notesPerOneAd: {
type: 'number',
optional: false, nullable: false,
Expand Down
9 changes: 9 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ export const meta = {
type: 'number',
optional: false, nullable: false,
},
wellKnownWebsites: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
backgroundImageUrl: {
type: 'string',
optional: false, nullable: true,
Expand Down Expand Up @@ -601,6 +609,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
perRemoteUserUserTimelineCacheMax: instance.perRemoteUserUserTimelineCacheMax,
perUserHomeTimelineCacheMax: instance.perUserHomeTimelineCacheMax,
perUserListTimelineCacheMax: instance.perUserListTimelineCacheMax,
wellKnownWebsites: instance.wellKnownWebsites,
notesPerOneAd: instance.notesPerOneAd,
summalyProxy: instance.urlPreviewSummaryProxyUrl,
urlPreviewEnabled: instance.urlPreviewEnabled,
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/update-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export const paramDef = {
type: 'string', nullable: true,
description: '[Deprecated] Use "urlPreviewSummaryProxyUrl" instead.',
},
wellKnownWebsites: {
type: 'array', nullable: true, items: {
type: 'string',
},
},
urlPreviewEnabled: { type: 'boolean' },
urlPreviewTimeout: { type: 'integer' },
urlPreviewMaximumContentLength: { type: 'integer' },
Expand Down Expand Up @@ -202,6 +207,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return h !== '' && h !== lv && !set.blockedHosts?.includes(h);
});
}

if (Array.isArray(ps.wellKnownWebsites)) {
set.wellKnownWebsites = ps.wellKnownWebsites.filter(Boolean);
}

if (ps.themeColor !== undefined) {
set.themeColor = ps.themeColor;
}
Expand Down
9 changes: 6 additions & 3 deletions packages/frontend/src/components/MkLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<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"
:title="url"
:is="self ? 'MkA' : 'a'" ref="el" style="word-break: break-all;" class="_link" :[attr]="self ? url.substring(local.length) : url" :rel="rel" :target="target"
:title="url" @click="(ev: MouseEvent) => warningExternalWebsite(ev, props.url)"
>
<slot></slot>
<i v-if="target === '_blank'" class="ti ti-external-link" :class="$style.icon"></i>
Expand All @@ -19,16 +19,19 @@ import { url as local } from '@/config.js';
import { useTooltip } from '@/scripts/use-tooltip.js';
import * as os from '@/os.js';
import { isEnabledUrlPreview } from '@/instance.js';
import { warningExternalWebsite } from '@/scripts/warning-external-website.js';

const props = withDefaults(defineProps<{
url: string;
rel?: null | string;
}>(), {
rel: 'nofollow noopener',
});

// eslint-disable-next-line vue/no-setup-props-destructure
const self = props.url.startsWith(local);
const attr = self ? 'to' : 'href';
const target = self ? null : '_blank';
const target = self ? undefined : '_blank';

const el = ref<HTMLElement | { $el: HTMLElement }>();

Expand Down
13 changes: 11 additions & 2 deletions packages/frontend/src/components/MkUrlPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
</template>
<div v-else>
<component :is="self ? 'MkA' : 'a'" :class="[$style.link, { [$style.compact]: compact }]" :[attr]="self ? url.substring(local.length) : url" rel="nofollow noopener" :target="target" :title="url">
<div v-if="thumbnail && !sensitive" :class="$style.thumbnail" :style="defaultStore.state.dataSaver.urlPreview ? '' : `background-image: url('${thumbnail}')`">
<component
:is="self ? 'MkA' : 'a'"
:class="[$style.link, { [$style.compact]: compact }]"
:[attr]="self ? url.substring(local.length) : url"
rel="nofollow noopener"
:target="target"
:title="url"
@click="(ev: MouseEvent) => warningExternalWebsite(ev, url)"
>
<div v-if="thumbnail" :class="[$style.thumbnail, { [$style.thumbnailBlur]: sensitive }]" :style="defaultStore.state.dataSaver.urlPreview ? '' : `background-image: url('${thumbnail}')`">
</div>
<article :class="$style.body">
<header :class="$style.header">
Expand Down Expand Up @@ -92,6 +100,7 @@ import { deviceKind } from '@/scripts/device-kind.js';
import MkButton from '@/components/MkButton.vue';
import { versatileLang } from '@/scripts/intl-const.js';
import { defaultStore } from '@/store.js';
import { warningExternalWebsite } from '@/scripts/warning-external-website.js';

type SummalyResult = Awaited<ReturnType<typeof summaly>>;

Expand Down
133 changes: 133 additions & 0 deletions packages/frontend/src/components/MkUrlWarningDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<MkModal ref="modal" :preferType="'dialog'" :zPriority="'high'" @click="done(true)" @closed="emit('closed')">
<div :class="$style.root" class="_gaps">
<div class="_gaps_s">
<div :class="$style.icon">
<i :class="$style.iconInner" class="ti ti-alert-triangle"></i>
</div>
<header :class="$style.title">{{ i18n.ts._urlWarning.title }}</header>
<div><Mfm :text="i18n.ts._urlWarning.description"/></div>
<div class="_monospace" :class="$style.urlAddress">{{ url }}</div>
<div>
<MkSwitch v-model="trustThisDomain">{{ i18n.tsx._urlWarning.trustThisDomain({ domain }) }}</MkSwitch>
</div>
</div>
<div :class="$style.buttons">
<MkButton data-cy-modal-dialog-ok inline primary rounded @click="ok">{{ i18n.ts.ok }}</MkButton>
<MkButton data-cy-modal-dialog-cancel inline rounded @click="cancel">{{ i18n.ts.cancel }}</MkButton>
</div>
</div>
</MkModal>
</template>

<script lang="ts" setup>
import { onBeforeUnmount, onMounted, ref, shallowRef, computed } from 'vue';
import MkModal from '@/components/MkModal.vue';
import MkButton from '@/components/MkButton.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import { i18n } from '@/i18n.js';
import { defaultStore } from '@/store.js';

type Result = string | number | true | null;

const props = defineProps<{
url: string;
}>();

const emit = defineEmits<{
(ev: 'done', v: { canceled: true } | { canceled: false, result: Result }): void;
(ev: 'closed'): void;
}>();

const modal = shallowRef<InstanceType<typeof MkModal>>();
const trustThisDomain = ref(false);

const domain = computed(() => new URL(props.url).hostname);

// overload function を使いたいので lint エラーを無視する
function done(canceled: true): void;
function done(canceled: false, result: Result): void; // eslint-disable-line no-redeclare
function done(canceled: boolean, result?: Result): void { // eslint-disable-line no-redeclare
emit('done', { canceled, result } as { canceled: true } | { canceled: false, result: Result });
modal.value?.close();
}

async function ok() {
const result = true;
if (!defaultStore.state.trustedDomains.includes(domain.value) && trustThisDomain.value) {
await defaultStore.set('trustedDomains', defaultStore.state.trustedDomains.concat(domain.value));
}
done(false, result);
}

function cancel() {
done(true);
}

/*
function onBgClick() {
if (props.cancelableByBgClick) cancel();
}
*/
function onKeydown(evt: KeyboardEvent) {
if (evt.key === 'Escape') cancel();
}

onMounted(() => {
document.addEventListener('keydown', onKeydown);
});

onBeforeUnmount(() => {
document.removeEventListener('keydown', onKeydown);
});
</script>

<style lang="scss" module>
.root {
position: relative;
margin: auto;
padding: 32px;
width: 100%;
min-width: 320px;
max-width: 480px;
box-sizing: border-box;
text-align: center;
background: var(--panel);
border-radius: 16px;
}

.icon {
font-size: 24px;
color: var(--warn);
}

.iconInner {
display: block;
margin: 0 auto;
}

.title {
font-weight: bold;
font-size: 1.1em;
}

.urlAddress {
padding: var(--margin);
border-radius: calc(var(--radius) / 2);
border: 1px solid var(--divider);
overflow-x: auto;
white-space: nowrap;
}

.buttons {
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: center;
}
</style>
9 changes: 6 additions & 3 deletions packages/frontend/src/components/global/MkUrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<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"
@contextmenu.stop="() => {}"
:is="self ? 'MkA' : 'a'" ref="el" :class="$style.root" class="_link" :[attr]="self ? props.url.substring(local.length) : props.url" :rel="rel" :target="target"
@contextmenu.stop="() => {}" @click="(ev: MouseEvent) => warningExternalWebsite(ev, props.url)"
>
<template v-if="!self">
<span :class="$style.schema">{{ schema }}//</span>
Expand All @@ -31,15 +31,18 @@ import * as os from '@/os.js';
import { useTooltip } from '@/scripts/use-tooltip.js';
import { safeURIDecode } from '@/scripts/safe-uri-decode.js';
import { isEnabledUrlPreview } from '@/instance.js';
import { warningExternalWebsite } from '@/scripts/warning-external-website.js';

const props = withDefaults(defineProps<{
url: string;
rel?: string;
showUrlPreview?: boolean;
}>(), {
rel: 'nofollow noopener',
showUrlPreview: true,
});

// eslint-disable-next-line vue/no-setup-props-destructure
const self = props.url.startsWith(local);
const url = new URL(props.url);
if (!['http:', 'https:'].includes(url.protocol)) throw new Error('invalid url');
Expand All @@ -62,7 +65,7 @@ const pathname = safeURIDecode(url.pathname);
const query = safeURIDecode(url.search);
const hash = safeURIDecode(url.hash);
const attr = self ? 'to' : 'href';
const target = self ? null : '_blank';
const target = self ? undefined : '_blank';
</script>

<style lang="scss" module>
Expand Down
Loading
Loading