dompurify 1.0.7 → 1.0.11
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 +29 -7
- package/dist/purify.cjs.js +235 -60
- package/dist/purify.cjs.js.map +1 -1
- package/dist/purify.es.js +235 -60
- package/dist/purify.es.js.map +1 -1
- package/dist/purify.js +235 -60
- package/dist/purify.js.map +1 -1
- package/dist/purify.min.js +1 -1
- package/dist/purify.min.js.map +1 -1
- package/package.json +17 -20
- package/package-lock.json +0 -10785
- package/yarn.lock +0 -5776
package/README.md
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
# DOMPurify
|
|
1
|
+
# DOMPurify
|
|
2
|
+
|
|
3
|
+
[](http://badge.fury.io/bo/dompurify) · [](http://badge.fury.io/js/dompurify) · [](https://travis-ci.org/cure53/DOMPurify) · [](https://www.npmjs.com/package/dompurify) · [](https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js) · [](https://packagephobia.now.sh/result?p=dompurify)
|
|
2
4
|
|
|
3
5
|
[](https://nodei.co/npm/dompurify/)
|
|
4
6
|
|
|
5
7
|
DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.
|
|
6
8
|
|
|
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.
|
|
9
|
+
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.11.
|
|
8
10
|
|
|
9
11
|
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
12
|
|
|
11
|
-
Our automated tests cover [
|
|
13
|
+
Our automated tests cover [25 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 v8.0.0, v9.0.0, v10.0.0 and v11.0.0, running DOMPurify on [jsdom](https://github.com/tmpvar/jsdom).
|
|
12
14
|
|
|
13
15
|
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
16
|
|
|
@@ -108,7 +110,24 @@ DOMPurify offers a fall-back behavior for older MSIE browsers. It uses the MSIE-
|
|
|
108
110
|
|
|
109
111
|
If not even `toStaticHTML` is supported, DOMPurify does nothing at all. It simply returns exactly the string that you fed it.
|
|
110
112
|
|
|
111
|
-
##
|
|
113
|
+
## What about DOMPurify and Trusted Types?
|
|
114
|
+
|
|
115
|
+
In version 1.0.9, support for [Trusted Types API](https://github.com/WICG/trusted-types) was added to DOMPurify.
|
|
116
|
+
|
|
117
|
+
When `DOMPurify.sanitize` is used in the environment where the Trusted Types API is available (this happens e.g. in Chrome `chrome://flags/#enable-experimental-web-platform-features`), it returns a `TrustedHTML` value instead of a string (the behavior for `RETURN_DOM`, `RETURN_DOM_FRAGMENT`, and `RETURN_DOM_IMPORT` config options does not change).
|
|
118
|
+
|
|
119
|
+
That return value is implicitly casted to a string when needed, returning the actual sanitized HTML snippet. In particular, you can directly use it with DOM sinks like `innerHTML`, or concatenate it with other strings. For most use cases, the API change does not introduce any visible change.
|
|
120
|
+
|
|
121
|
+
That said, `TrustedHTML` values are intentionally immutable, and don't inherit from `String.prototype`. In rare cases where you expect the value to implement String prototype functions (e.g. if you want to `String.replace` the sanitized output), cast the value to a string like so:
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
const sanitizedAsString = (DOMPurify.sanitize(foo) + '');
|
|
125
|
+
sanitizedAsString.replace(...)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Please note, that if that change breaks your application, you *might* be doing something wrong. The sanitized HTML snippet should not be modified, as it might introduce XSS vulnerabilities.
|
|
129
|
+
|
|
130
|
+
## Can I configure DOMPurify?
|
|
112
131
|
|
|
113
132
|
Yes. The included default configuration values are pretty good already - but you can of course override them. Check out the [`/demos`](https://github.com/cure53/DOMPurify/tree/master/demos) folder to see a bunch of examples on how you can [customize DOMPurify](https://github.com/cure53/DOMPurify/tree/master/demos#what-is-this).
|
|
114
133
|
|
|
@@ -117,6 +136,9 @@ Yes. The included default configuration values are pretty good already - but you
|
|
|
117
136
|
var clean = DOMPurify.sanitize(dirty, {SAFE_FOR_JQUERY: true});
|
|
118
137
|
|
|
119
138
|
// strip {{ ... }} and <% ... %> to make output safe for template systems
|
|
139
|
+
// be careful please, this mode is not recommended for production usage.
|
|
140
|
+
// allowing template parsing in user-controlled HTML is not advised at all.
|
|
141
|
+
// only use this mode if there is really no alternative.
|
|
120
142
|
var clean = DOMPurify.sanitize(dirty, {SAFE_FOR_TEMPLATES: true});
|
|
121
143
|
|
|
122
144
|
// allow only <b>
|
|
@@ -177,7 +199,7 @@ var clean = DOMPurify.sanitize(dirty, {WHOLE_DOCUMENT: true});
|
|
|
177
199
|
// disable DOM Clobbering protection on output (default is true, handle with care!)
|
|
178
200
|
var clean = DOMPurify.sanitize(dirty, {SANITIZE_DOM: false});
|
|
179
201
|
|
|
180
|
-
//
|
|
202
|
+
// keep an element's content when the element is removed (default is true)
|
|
181
203
|
var clean = DOMPurify.sanitize(dirty, {KEEP_CONTENT: false});
|
|
182
204
|
|
|
183
205
|
// glue elements like style, script or others to document.body and prevent unintuitive browser behavior in several edge-cases (default is false)
|
|
@@ -235,7 +257,7 @@ We support both `yarn` and `npm@5.2` officially while providing lock-files for e
|
|
|
235
257
|
|
|
236
258
|
#### Scripts
|
|
237
259
|
|
|
238
|
-
We rely on npm run-scripts for integrating with
|
|
260
|
+
We rely on npm run-scripts for integrating with our 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`.
|
|
239
261
|
|
|
240
262
|
These are our npm scripts:
|
|
241
263
|
|
|
@@ -269,7 +291,7 @@ Several people need to be listed here!
|
|
|
269
291
|
|
|
270
292
|
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)!
|
|
271
293
|
|
|
272
|
-
Further, thanks [@neilj](https://twitter.com/neilj) and [@0xsobky](https://twitter.com/0xsobky) for their code reviews and countless small optimizations, fixes and beautifications.
|
|
294
|
+
Further, thanks [@neilj](https://twitter.com/neilj) and [@0xsobky](https://twitter.com/0xsobky) for their code reviews and countless small optimizations, fixes and beautifications. Thanks also go out to [@kkotowicz](https://twitter.com/kkotowicz) for his Trusted Types implementation and the connected section on our README page.
|
|
273
295
|
|
|
274
296
|
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!
|
|
275
297
|
|