Skip to content

[Doc]: add non-trusted template rule to security guide #1992 #2011

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

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion src/v2/guide/security.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: セキュリティ
updated: 2019-11-18
updated: 2020-02-05
type: guide
order: 504
---
Expand All @@ -11,6 +11,19 @@ order: 504

新たな脆弱性の発見はめったにありませんが、常に Vue とその公式ライブラリの最新バージョンを使用し、アプリケーションのセキュリティを可能な限り維持することをお勧めします。

## ルール No.1: 信頼できないテンプレートを絶対に使わない

Vue を使うときの最も基本的なセキュリティルールは、**信頼できないコンテンツをコンポーネントのテンプレートとして絶対に使わない** ということです。そうすることは、あなたのアプリケーション内で任意の JavaScript 実行を許してしまうことと同じです。さらに悪いことに、コードがサーバーサイドレンダリング中に実行された場合には、サーバー側の欠陥につながります。例えば、次のような使い方です:

``` js
new Vue({
el: '#app',
template: `<div>` + userProvidedString + `</div>` // 絶対にしてはいけない
})
```

Vue のテンプレートは JavaScript にコンパイルされ、テンプレート中の式はレンダリング処理の過程で実行されます。式は特定のレンダリングコンテキストで評価されますが、潜在的にはグローバルに実行される複雑な実行環境となるため、Vue のようなフレームワークでパフォーマンスの非現実的なオーバーヘッドを受けることなく悪意のあるコード実行を完全に防ぐことは困難です。この手の問題を回避する最も直接的な方法は、完全にあなたの管理下にある信頼されたコンテンツだけを Vue テンプレートのコンテンツにすることです。

## Vue が行っているセキュリティ対策

### HTML コンテンツ
Expand Down