Skip to content

Commit 06856f2

Browse files
committed
Add warning about client-side sanitization.
1 parent 3266d66 commit 06856f2

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
[Vue](https://vuejs.org)'s default `v-text` is HTML-insensitive, while `v-html` doesn't perform sanitization by default.
44

5-
`v-sanitize` is a Vue directive for HTML sanitization, powered by the flexible [sanitize-html](https://www.npmjs.com/package/sanitize-html). The directive can receive either a string, that will undergo a partial sanitization if no modifier is present, or an array of two elements, the first being a `sanitize-html` allowlist ([know more here](https://github.com/punkave/sanitize-html)) and the second being the string to be sanitized.
5+
`v-sanitize` is a Vue directive for HTML sanitization, powered by the flexible [sanitize-html](https://www.npmjs.com/package/sanitize-html). The directive can receive either a string, that will undergo a partial sanitization if no modifier is present, or an array of two elements, the first being a `sanitize-html` allowlist ([know more here](https://github.com/apostrophecms/sanitize-html)) and the second being the string to be sanitized.
66

77
```html
88
<div v-sanitize="unsafe_html"></div>
99
```
1010

11+
## Warning
12+
13+
The validation and sanitization of user-provided input should be performed on the back-end, before storing it on the database. You should resort to client-side input sanitization only if you don't control the back-end, e.g., consuming content from an external API.
14+
1115
## Setup
1216

1317
Start getting it with NPM or Yarn ([see package](https://www.npmjs.com/package/vue-sanitize-directive)).

docs-src/src/components/Demo.vue

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<template>
22
<div class="container">
3-
<img class="logo" src="../assets/logo.svg">
3+
<img class="logo" src="../assets/logo.svg" height="150" width="150" alt="">
44
<h1>v-sanitize</h1>
55

66
<p><a href="https://vuejs.org/" target="_blank">Vue</a>'s default <code>v-text</code> is HTML-insensitive, while <code>v-html</code> doesn't perform sanitization by default.</p>
7-
<p><code>v-sanitize</code> is a Vue directive for HTML sanitization, powered by the flexible <a href="https://www.npmjs.com/package/sanitize-html" target="_blank">sanitize-html</a>. The directive can receive either a string, that will undergo a partial sanitization if no modifier is present, or an array of two elements, the first being a <code>sanitize-html</code> allowlist (<a href="https://github.com/punkave/sanitize-html" target="_blank">know more here</a>) and the second being the string to be sanitized.</p>
7+
<p><code>v-sanitize</code> is a Vue directive for HTML sanitization, powered by the flexible <a href="https://www.npmjs.com/package/sanitize-html" target="_blank">sanitize-html</a>. The directive can receive either a string, that will undergo a partial sanitization if no modifier is present, or an array of two elements, the first being a <code>sanitize-html</code> allowlist (<a href="https://github.com/apostrophecms/sanitize-html" target="_blank">know more here</a>) and the second being the string to be sanitized.</p>
88
<pre class="editor" v-pre>
99
<code>&lt;<span class="red">div</span> <span class="orange">v-sanitize</span>="<span class="green">unsafe_html</span>"&gt;&lt;/<span class="red">div</span>&gt;</code>
1010
</pre>
1111

12+
<div class="warning">
13+
<h2>Warning</h2>
14+
<p>The validation and sanitization of user-provided input should be performed on the back-end, before storing it on the database. You should resort to client-side input sanitization only if you don't control the back-end, e.g., consuming content from an external API.</p>
15+
</div>
16+
1217
<h2>Setup</h2>
1318
<p>Start getting it with NPM or Yarn (<a href="https://www.npmjs.com/package/vue-sanitize-directive" target="_blank">see package</a>).</p>
1419
<pre class="editor">
@@ -50,15 +55,15 @@
5055
<div class="demo" v-sanitize.nothing="html"></div>
5156

5257
<h3>Custom allowlists</h3>
53-
<p>Edit the box below, as JSON. Read <a href="https://github.com/punkave/sanitize-html" target="_blank">sanitize-html docs</a> for more details.</p>
58+
<p>Edit the box below, as JSON. Read <a href="https://github.com/apostrophecms/sanitize-html" target="_blank">sanitize-html docs</a> for more details.</p>
5459
<div class="table">
5560
<div class="row">
5661
<div class="col">
57-
<textarea rows="5" v-model="editableFilter"></textarea>
62+
<textarea aria-label="Allowlist" rows="5" v-model="editableFilter"></textarea>
5863
<button @click="updateFilter()">Update allowlist</button>
5964
</div>
6065
<div class="col">
61-
<textarea rows="5" v-model="editableHtml"></textarea>
66+
<textarea aria-label="HTML input" rows="5" v-model="editableHtml"></textarea>
6267
<button @click="updateHtml()">Update HTML</button>
6368
</div>
6469
<div class="col">
@@ -77,7 +82,7 @@
7782
import { FILTER_BASIC, FILTER_INLINE, FILTER_NOTHING, FILTER_STRIP } from 'vue-sanitize-directive'
7883
7984
const html = `
80-
<iframe src="https://www.example.org"></iframe>
85+
<iframe src="https://www.openstreetmap.org/export/embed.html" title="Example page"></iframe>
8186
<p>This is a <strong>test</strong>.</p>
8287
`
8388
@@ -197,6 +202,16 @@ code
197202
.white
198203
color: #A6ACCD
199204
205+
.warning
206+
background-color: #FECDD3
207+
border-radius: $border-radius
208+
color: #881337
209+
margin: 20px
210+
padding: 0.1px
211+
212+
h2
213+
color: #9F1239
214+
200215
footer
201216
background-color: $brand-primary
202217
border-radius: $border-radius

docs/assets/index.65928647.css renamed to docs/assets/index.7ce22dbb.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)