dompurify 3.3.0 → 3.3.2
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 +9 -6
- package/dist/purify.cjs.d.ts +6 -2
- package/dist/purify.cjs.js +21 -4
- package/dist/purify.cjs.js.map +1 -1
- package/dist/purify.es.d.mts +6 -2
- package/dist/purify.es.mjs +21 -4
- package/dist/purify.es.mjs.map +1 -1
- package/dist/purify.js +21 -4
- package/dist/purify.js.map +1 -1
- package/dist/purify.min.js +2 -2
- package/dist/purify.min.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# DOMPurify
|
|
2
2
|
|
|
3
|
-
[](http://badge.fury.io/js/dompurify)  [](https://www.npmjs.com/package/dompurify) ](http://badge.fury.io/js/dompurify)  [](https://www.npmjs.com/package/dompurify)  [](https://github.com/cure53/DOMPurify/network/dependents) [](https://cloudback.it)
|
|
4
4
|
|
|
5
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. DOMPurify was [started in February 2014](https://github.com/cure53/DOMPurify/commit/a630922616927373485e0e787ab19e73e3691b2b) and, meanwhile, has reached version **v3.3.
|
|
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 **v3.3.2**.
|
|
8
8
|
|
|
9
|
-
DOMPurify
|
|
9
|
+
DOMPurify runs as JavaScript and works in all modern browsers (Safari (10+), Opera (15+), Edge, Firefox and Chrome - as well as almost anything else using Blink, Gecko or WebKit). It doesn't break on MSIE or other legacy browsers. It simply does nothing.
|
|
10
10
|
|
|
11
11
|
**Note that [DOMPurify v2.5.8](https://github.com/cure53/DOMPurify/releases/tag/2.5.8) is the latest version supporting MSIE. For important security updates compatible with MSIE, please use the [2.x branch](https://github.com/cure53/DOMPurify/tree/2.x).**
|
|
12
12
|
|
|
13
|
-
Our automated tests cover [28 different browsers](https://github.com/cure53/DOMPurify/blob/main/test/karma.custom-launchers.config.js#L5) right now, more to come. We also cover Node.js
|
|
13
|
+
Our automated tests cover [28 different browsers](https://github.com/cure53/DOMPurify/blob/main/test/karma.custom-launchers.config.js#L5) right now, more to come. We also cover Node.js v20.x, v22.x, 24.x and v25.x, running DOMPurify on [jsdom](https://github.com/jsdom/jsdom). Older Node versions are known to work as well, but hey... no guarantees.
|
|
14
14
|
|
|
15
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.
|
|
16
16
|
|
|
@@ -65,7 +65,7 @@ After sanitizing your markup, you can also have a look at the property `DOMPurif
|
|
|
65
65
|
|
|
66
66
|
### Running DOMPurify on the server
|
|
67
67
|
|
|
68
|
-
DOMPurify technically also works server-side with Node.js. Our support strives to follow the [Node.js release cycle](https://nodejs.org/en/about/releases
|
|
68
|
+
DOMPurify technically also works server-side with Node.js. Our support strives to follow the [Node.js release cycle](https://nodejs.org/en/about/previous-releases).
|
|
69
69
|
|
|
70
70
|
Running DOMPurify on the server requires a DOM to be present, which is probably no surprise. Usually, [jsdom](https://github.com/jsdom/jsdom) is the tool of choice and we **strongly recommend** to use the latest version of _jsdom_.
|
|
71
71
|
|
|
@@ -368,6 +368,9 @@ const clean = DOMPurify.sanitize(dirty, {FORCE_BODY: true});
|
|
|
368
368
|
// remove all <a> elements under <p> elements that are removed
|
|
369
369
|
const clean = DOMPurify.sanitize(dirty, {FORBID_CONTENTS: ['a'], FORBID_TAGS: ['p']});
|
|
370
370
|
|
|
371
|
+
// extend the default FORBID_CONTENTS list to also remove <a> elements under <p> elements
|
|
372
|
+
const clean = DOMPurify.sanitize(dirty, {ADD_FORBID_CONTENTS: ['a'], FORBID_TAGS: ['p']});
|
|
373
|
+
|
|
371
374
|
// change the parser type so sanitized data is treated as XML and not as HTML, which is the default
|
|
372
375
|
const clean = DOMPurify.sanitize(dirty, {PARSER_MEDIA_TYPE: 'application/xhtml+xml'});
|
|
373
376
|
```
|
|
@@ -437,7 +440,7 @@ We support `npm` officially. GitHub Actions workflow is configured to install de
|
|
|
437
440
|
|
|
438
441
|
#### Scripts
|
|
439
442
|
|
|
440
|
-
We
|
|
443
|
+
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`.
|
|
441
444
|
|
|
442
445
|
These are our npm scripts:
|
|
443
446
|
|
package/dist/purify.cjs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! @license DOMPurify 3.3.
|
|
1
|
+
/*! @license DOMPurify 3.3.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.2/LICENSE */
|
|
2
2
|
|
|
3
|
-
import { TrustedTypePolicy, TrustedHTML, TrustedTypesWindow } from 'trusted-types/lib';
|
|
3
|
+
import { TrustedTypePolicy, TrustedHTML, TrustedTypesWindow } from 'trusted-types/lib/index.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Configuration to control DOMPurify behavior.
|
|
@@ -94,6 +94,10 @@ interface Config {
|
|
|
94
94
|
* Add child elements to be removed when their parent is removed.
|
|
95
95
|
*/
|
|
96
96
|
FORBID_CONTENTS?: string[] | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Extend the existing or default array of forbidden content elements.
|
|
99
|
+
*/
|
|
100
|
+
ADD_FORBID_CONTENTS?: string[] | undefined;
|
|
97
101
|
/**
|
|
98
102
|
* Add elements to block-list.
|
|
99
103
|
*/
|
package/dist/purify.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @license DOMPurify 3.3.
|
|
1
|
+
/*! @license DOMPurify 3.3.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.2/LICENSE */
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -307,7 +307,7 @@ const _createHooksMap = function _createHooksMap() {
|
|
|
307
307
|
function createDOMPurify() {
|
|
308
308
|
let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
|
|
309
309
|
const DOMPurify = root => createDOMPurify(root);
|
|
310
|
-
DOMPurify.version = '3.3.
|
|
310
|
+
DOMPurify.version = '3.3.2';
|
|
311
311
|
DOMPurify.removed = [];
|
|
312
312
|
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
|
|
313
313
|
// Not running in a browser, provide a factory function
|
|
@@ -602,7 +602,7 @@ function createDOMPurify() {
|
|
|
602
602
|
/* Parse profile info */
|
|
603
603
|
if (USE_PROFILES) {
|
|
604
604
|
ALLOWED_TAGS = addToSet({}, text);
|
|
605
|
-
ALLOWED_ATTR =
|
|
605
|
+
ALLOWED_ATTR = create(null);
|
|
606
606
|
if (USE_PROFILES.html === true) {
|
|
607
607
|
addToSet(ALLOWED_TAGS, html$1);
|
|
608
608
|
addToSet(ALLOWED_ATTR, html);
|
|
@@ -623,6 +623,13 @@ function createDOMPurify() {
|
|
|
623
623
|
addToSet(ALLOWED_ATTR, xml);
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
|
+
/* Prevent function-based ADD_ATTR / ADD_TAGS from leaking across calls */
|
|
627
|
+
if (!objectHasOwnProperty(cfg, 'ADD_TAGS')) {
|
|
628
|
+
EXTRA_ELEMENT_HANDLING.tagCheck = null;
|
|
629
|
+
}
|
|
630
|
+
if (!objectHasOwnProperty(cfg, 'ADD_ATTR')) {
|
|
631
|
+
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
|
|
632
|
+
}
|
|
626
633
|
/* Merge configuration parameters */
|
|
627
634
|
if (cfg.ADD_TAGS) {
|
|
628
635
|
if (typeof cfg.ADD_TAGS === 'function') {
|
|
@@ -653,6 +660,12 @@ function createDOMPurify() {
|
|
|
653
660
|
}
|
|
654
661
|
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
655
662
|
}
|
|
663
|
+
if (cfg.ADD_FORBID_CONTENTS) {
|
|
664
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
665
|
+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
666
|
+
}
|
|
667
|
+
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
668
|
+
}
|
|
656
669
|
/* Add #text in case KEEP_CONTENT is set to true */
|
|
657
670
|
if (KEEP_CONTENT) {
|
|
658
671
|
ALLOWED_TAGS['#text'] = true;
|
|
@@ -1014,6 +1027,10 @@ function createDOMPurify() {
|
|
|
1014
1027
|
*/
|
|
1015
1028
|
// eslint-disable-next-line complexity
|
|
1016
1029
|
const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
|
|
1030
|
+
/* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
|
|
1031
|
+
if (FORBID_ATTR[lcName]) {
|
|
1032
|
+
return false;
|
|
1033
|
+
}
|
|
1017
1034
|
/* Make sure attribute cannot clobber */
|
|
1018
1035
|
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
|
|
1019
1036
|
return false;
|
|
@@ -1106,7 +1123,7 @@ function createDOMPurify() {
|
|
|
1106
1123
|
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
1107
1124
|
}
|
|
1108
1125
|
/* Work around a security issue with comments inside attributes */
|
|
1109
|
-
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
|
|
1126
|
+
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
|
|
1110
1127
|
_removeAttribute(name, currentNode);
|
|
1111
1128
|
continue;
|
|
1112
1129
|
}
|