Skip to content

Commit 9790624

Browse files
committed
add non-trusted template rule to security guide
1 parent f6b50c5 commit 9790624

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/v2/guide/security.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ When a vulnerability is reported, it immediately becomes our top concern, with a
1010

1111
While the discovery of new vulnerabilities is rare, we also recommend always using the latest versions of Vue and its official companion libraries to ensure your application remains as secure as possible.
1212

13+
## Rule No.1: Never Use Non-trusted Templates
14+
15+
The most fundamental security rule when using Vue is **never use non-trusted content as your component template**. Doing so is equivalent to allowing arbitrary JavaScript execution in your application - and worse, could lead to server breaches if the code is executed during server-side rendering. An example of such usage:
16+
17+
``` js
18+
new Vue({
19+
el: '#app',
20+
template: `<div>` + userProvidedString + `</div>` // NEVER DO THIS
21+
})
22+
```
23+
24+
Vue templates are compiled into JavaScript, and expressions inside templates will be executed as part of the rendering process. Although the expressions are evaluated against a specific rendering context, due to the complexity of potential global execution environments, it is impractical for a framework like Vue to completely shield you from potential malicious code execution without incurring unrealistic performance overhead. The most straightforward way to avoid this category of problems altogether is to make sure the contents of your Vue templates are always trusted and entirely controlled by you.
25+
1326
## What Vue Does to Protect You
1427

1528
### HTML content

0 commit comments

Comments
 (0)