dompurify 0.9.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -22
- package/dist/purify.cjs.js +954 -0
- package/dist/purify.cjs.js.map +1 -0
- package/dist/purify.es.js +952 -0
- package/dist/purify.es.js.map +1 -0
- package/dist/purify.js +960 -0
- package/dist/purify.js.map +1 -0
- package/dist/purify.min.js +2 -2
- package/dist/purify.min.js.map +1 -1
- package/package-lock.json +6620 -0
- package/package.json +81 -21
- package/yarn.lock +4419 -0
- package/src/purify.js +0 -1004
package/README.md
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://nodei.co/npm/dompurify/)
|
|
4
4
|
|
|
5
|
-
DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.
|
|
5
|
+
DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.
|
|
6
6
|
|
|
7
|
-
It's also very simple to use and get started with.
|
|
7
|
+
It's also very simple to use and get started with. DOMPurify was [started in February 2014](https://github.com/cure53/DOMPurify/commit/a630922616927373485e0e787ab19e73e3691b2b) and, meanwhile, has reached version 1.0.3!
|
|
8
8
|
|
|
9
|
-
DOMPurify is written in JavaScript and works in all modern browsers (Safari, Opera (15+), Internet Explorer (10+), Edge, Firefox and Chrome - as well as almost anything else using Blink or WebKit). It doesn't break on
|
|
9
|
+
DOMPurify is written in JavaScript and works in all modern browsers (Safari, Opera (15+), Internet Explorer (10+), Edge, Firefox and Chrome - as well as almost anything else using Blink or WebKit). It doesn't break on MSIE6 or other legacy browsers. It either uses [a fall-back](#what-about-older-browsers-like-msie8) or simply does nothing.
|
|
10
10
|
|
|
11
|
-
Our automated tests cover [16 different browsers](https://github.com/cure53/DOMPurify/blob/master/test/karma.
|
|
11
|
+
Our automated tests cover [16 different browsers](https://github.com/cure53/DOMPurify/blob/master/test/karma.custom-launchers.config.js#L5) right now, more to come. We also cover Node.js v4.0.0, v5.0.0 and v6.0.0, running DOMPurify on [jsdom](https://github.com/tmpvar/jsdom).
|
|
12
12
|
|
|
13
|
-
DOMPurify is written by security people who have vast background in web attacks and XSS. Fear not. For more details please also read about our [Security Goals & Threat Model](https://github.com/cure53/DOMPurify/wiki/Security-Goals-&-Threat-Model)
|
|
13
|
+
DOMPurify is written by security people who have vast background in web attacks and XSS. Fear not. For more details please also read about our [Security Goals & Threat Model](https://github.com/cure53/DOMPurify/wiki/Security-Goals-&-Threat-Model). Please, read it. Like, really.
|
|
14
14
|
|
|
15
15
|
## What does it do?
|
|
16
16
|
|
|
@@ -58,20 +58,14 @@ npm install dompurify
|
|
|
58
58
|
|
|
59
59
|
```javascript
|
|
60
60
|
const createDOMPurify = require('dompurify');
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
FetchExternalResources: false, // disables resource loading over HTTP / filesystem
|
|
65
|
-
ProcessExternalResources: false // do not execute JS within script blocks
|
|
66
|
-
}
|
|
67
|
-
}).defaultView;
|
|
61
|
+
const { JSDOM } = require('jsdom');
|
|
62
|
+
|
|
63
|
+
const window = (new JSDOM('')).window;
|
|
68
64
|
const DOMPurify = createDOMPurify(window);
|
|
69
65
|
|
|
70
66
|
const clean = DOMPurify.sanitize(dirty);
|
|
71
67
|
```
|
|
72
68
|
|
|
73
|
-
Strictly speaking, DOMPurify creates a document without a browsing context and you can replace it with `const window = jsdom.jsdom().defaultView;`, however, the longer case protects against accidental bugs in jsdom or DOMPurify.
|
|
74
|
-
|
|
75
69
|
## Is there a demo?
|
|
76
70
|
|
|
77
71
|
Of course there is a demo! [Play with DOMPurify](https://cure53.de/purify)
|
|
@@ -87,8 +81,8 @@ How does purified markup look like? Well, [the demo](https://cure53.de/purify) s
|
|
|
87
81
|
```javascript
|
|
88
82
|
DOMPurify.sanitize('<img src=x onerror=alert(1)//>'); // becomes <img src="x">
|
|
89
83
|
DOMPurify.sanitize('<svg><g/onload=alert(2)//<p>'); // becomes <svg><g></g></svg>
|
|
90
|
-
DOMPurify.sanitize('<p>abc<iframe/\/src=jAva	script:alert(3)>def'); // becomes <p>
|
|
91
|
-
DOMPurify.sanitize('<math><mi//xlink:href="data:x,<script>alert(4)</script>">'); // becomes <math></math>
|
|
84
|
+
DOMPurify.sanitize('<p>abc<iframe/\/src=jAva	script:alert(3)>def'); // becomes <p>abcdef</p>
|
|
85
|
+
DOMPurify.sanitize('<math><mi//xlink:href="data:x,<script>alert(4)</script>">'); // becomes <math><mi></mi></math>
|
|
92
86
|
DOMPurify.sanitize('<TABLE><tr><td>HELLO</tr></TABL>'); // becomes <table><tbody><tr><td>HELLO</td></tr></tbody></table>
|
|
93
87
|
DOMPurify.sanitize('<UL><li><A HREF=//google.com>click</UL>'); // becomes <ul><li><a href="//google.com">click</a></li></ul>
|
|
94
88
|
```
|
|
@@ -120,6 +114,15 @@ var clean = DOMPurify.sanitize(dirty, {ALLOWED_TAGS: ['b']});
|
|
|
120
114
|
// allow only <b> and <q> with style attributes (for whatever reason)
|
|
121
115
|
var clean = DOMPurify.sanitize(dirty, {ALLOWED_TAGS: ['b', 'q'], ALLOWED_ATTR: ['style']});
|
|
122
116
|
|
|
117
|
+
// allow all safe HTML elements but neither SVG nor MathML
|
|
118
|
+
var clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {html: true}});
|
|
119
|
+
|
|
120
|
+
// allow all safe SVG elements and SVG Filters
|
|
121
|
+
var clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {svg: true, svgFilters: true}});
|
|
122
|
+
|
|
123
|
+
// allow all safe MathML elements and SVG
|
|
124
|
+
var clean = DOMPurify.sanitize(dirty, {USE_PROFILES: {mathMl: true, svg: true}});
|
|
125
|
+
|
|
123
126
|
// leave all as it is but forbid <style>
|
|
124
127
|
var clean = DOMPurify.sanitize(dirty, {FORBID_TAGS: ['style']});
|
|
125
128
|
|
|
@@ -136,9 +139,14 @@ var clean = DOMPurify.sanitize(dirty, {ADD_ATTR: ['my-attr']});
|
|
|
136
139
|
var clean = DOMPurify.sanitize(dirty, {ALLOW_DATA_ATTR: false});
|
|
137
140
|
|
|
138
141
|
// allow external protocol handlers in URL attributes (default is false)
|
|
139
|
-
// by default only http, https, ftp, ftps, tel and
|
|
142
|
+
// by default only http, https, ftp, ftps, tel, mailto, callto, cid and xmpp are allowed.
|
|
140
143
|
var clean = DOMPurify.sanitize(dirty, {ALLOW_UNKNOWN_PROTOCOLS: true});
|
|
141
144
|
|
|
145
|
+
// allow specific protocols handlers in URL attributes (default is false)
|
|
146
|
+
// by default only http, https, ftp, ftps, tel, mailto, callto, cid and xmpp are allowed.
|
|
147
|
+
// Default RegExp: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
|
|
148
|
+
var clean = DOMPurify.sanitize(dirty, {ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|xxx):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;});
|
|
149
|
+
|
|
142
150
|
// return a DOM HTMLBodyElement instead of an HTML string (default is false)
|
|
143
151
|
var clean = DOMPurify.sanitize(dirty, {RETURN_DOM: true});
|
|
144
152
|
|
|
@@ -203,6 +211,32 @@ You can further run local tests by executing `npm test`. The tests work fine wit
|
|
|
203
211
|
|
|
204
212
|
All relevant commits will be signed with the key `0x24BB6BF4` for additional security (since 8th of April 2016).
|
|
205
213
|
|
|
214
|
+
### Development and contributing
|
|
215
|
+
|
|
216
|
+
#### Installation (`yarn i`)
|
|
217
|
+
|
|
218
|
+
We support both `yarn` and `npm@5.2` officially while providing lock-files for either dependency manager to provide reproducible installs and builds on either or. TravisCI itself is configured to install dependencies using `yarn`. When using an older version of `npm` we can not fully ensure the versions of installed dependencies which might lead to unanticipated problems.
|
|
219
|
+
|
|
220
|
+
#### Scripts
|
|
221
|
+
|
|
222
|
+
We rely on npm run-scripts for integrating with out tooling infrastructure. We use ESLint as a pre-commit hook to ensure code consistency. Moreover, to ease formatting we use [prettier](https://github.com/prettier/prettier) while building the `/dist` assets happens through `rollup`.
|
|
223
|
+
|
|
224
|
+
These are our npm scripts:
|
|
225
|
+
|
|
226
|
+
- `npm run dev` to start building while watching sources for changes
|
|
227
|
+
- `npm run test` to run our test suite via jsdom and karma
|
|
228
|
+
- `test:jsdom` to only run tests through jsdom
|
|
229
|
+
- `test:karma` to only run tests through karma
|
|
230
|
+
- `npm run lint` to lint the sources using ESLint (via xo)
|
|
231
|
+
- `npm run format` to format our sources using prettier to ease to pass ESLint
|
|
232
|
+
- `npm run build` to build our distribution assets minified and unminified as a UMD module
|
|
233
|
+
- `npm run build:umd` to only build an unminified UMD module
|
|
234
|
+
- `npm run build:umd:min` to only build a minified UMD module
|
|
235
|
+
|
|
236
|
+
Note: all run scripts triggered via `npm run <script>` can also be started using `yarn <script>`.
|
|
237
|
+
|
|
238
|
+
There are more npm scripts but they are mainly to integrate with CI or are meant to be "private" for instance to amend build distribution files with every commit.
|
|
239
|
+
|
|
206
240
|
## Security Mailing List
|
|
207
241
|
|
|
208
242
|
We maintain a mailing list that notifies whenever a security-critical release of DOMPurify was published. This means, if someone found a bypass and we fixed it with a release (which always happens when a bypass was found) a mail will go out to that list. This usually happens within minutes or few hours after learning about a bypass. The list can be subscribed to here:
|
|
@@ -213,14 +247,14 @@ Feature releases will not be announced to this list.
|
|
|
213
247
|
|
|
214
248
|
## Who contributed?
|
|
215
249
|
|
|
216
|
-
Several people need to be listed here!
|
|
250
|
+
Several people need to be listed here!
|
|
217
251
|
|
|
218
|
-
[@garethheyes](https://twitter.com/garethheyes) and [@filedescriptor](https://twitter.com/filedescriptor) for invaluable help, [@shafigullin](https://twitter.com/shafigullin) for breaking the library multiple times and thereby strengthening it, [@mmrupp](https://twitter.com/mmrupp) and [@irsdl](https://twitter.com/irsdl) for doing the same.
|
|
252
|
+
[@garethheyes](https://twitter.com/garethheyes) and [@filedescriptor](https://twitter.com/filedescriptor) for invaluable help, [@shafigullin](https://twitter.com/shafigullin) for breaking the library multiple times and thereby strengthening it, [@mmrupp](https://twitter.com/mmrupp) and [@irsdl](https://twitter.com/irsdl) for doing the same. And lastly, thanks to @ShikariSenpai and @ansjdnakjdnajkd for spotting the [massive Safari 10.1 bug](https://github.com/cure53/DOMPurify/releases/tag/0.8.6) in the first place.
|
|
219
253
|
|
|
220
|
-
Big thanks also go to [@asutherland](https://twitter.com/asutherland), [@mathias](https://twitter.com/mathias), [@cgvwzq](https://twitter.com/cgvwzq), [@robbertatwork](https://twitter.com/robbertatwork), [@giutro](https://twitter.com/giutro) and [@fhemberger](https://twitter.com/fhemberger)!
|
|
254
|
+
Big thanks also go to [@ydaniv](https://github.com/ydaniv), [@asutherland](https://twitter.com/asutherland), [@mathias](https://twitter.com/mathias), [@cgvwzq](https://twitter.com/cgvwzq), [@robbertatwork](https://twitter.com/robbertatwork), [@giutro](https://twitter.com/giutro) and [@fhemberger](https://twitter.com/fhemberger)!
|
|
221
255
|
|
|
222
|
-
Further, thanks [@neilj](https://twitter.com/neilj) and [@0xsobky](https://twitter.com/0xsobky) for their code reviews and countless small optimizations, fixes and beautifications.
|
|
256
|
+
Further, thanks [@neilj](https://twitter.com/neilj) and [@0xsobky](https://twitter.com/0xsobky) for their code reviews and countless small optimizations, fixes and beautifications.
|
|
223
257
|
|
|
224
|
-
Big thanks also go to [@tdeekens](https://twitter.com/tdeekens) for doing all the hard work and getting us on track with Travis CI and BrowserStack. And thanks to [@Joris-van-der-Wel](https://github.com/Joris-van-der-Wel) for setting up DOMPurify for jsdom and creating the additional test suite.
|
|
258
|
+
Big thanks also go to [@tdeekens](https://twitter.com/tdeekens) for doing all the hard work and getting us on track with Travis CI and BrowserStack. And thanks to [@Joris-van-der-Wel](https://github.com/Joris-van-der-Wel) for setting up DOMPurify for jsdom and creating the additional test suite. And again [@tdeekens](https://twitter.com/tdeekens) for his [incredible efforts](https://github.com/cure53/DOMPurify/pull/206) and contribution to refactor DOMPurify into using ES201x, proper build tools, better test coverage and much more!
|
|
225
259
|
|
|
226
260
|
And last but not least, thanks to [BrowserStack](https://browserstack.com) for supporting this project with their services for free and delivering excellent, dedicated and very professional support on top of that.
|