dompurify 2.4.5 → 3.0.1
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/LICENSE +1 -1
- package/README.md +6 -10
- package/dist/purify.cjs.js +124 -61
- package/dist/purify.cjs.js.map +1 -1
- package/dist/purify.es.js +124 -61
- package/dist/purify.es.js.map +1 -1
- package/dist/purify.js +124 -61
- 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 +2 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.
|
|
8
8
|
|
|
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 3.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 3.0.1.
|
|
10
10
|
|
|
11
|
-
DOMPurify is written in JavaScript and works in all modern browsers (Safari (10+), Opera (15+),
|
|
11
|
+
DOMPurify is written in 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.
|
|
12
12
|
|
|
13
|
-
**Note that DOMPurify v2.4.5 is the final version supporting MSIE. For important security updates compatible with MSIE, please use the 2.x branch.**
|
|
13
|
+
**Note that [DOMPurify v2.4.5](https://github.com/cure53/DOMPurify/releases/tag/2.4.4) is the final version supporting MSIE. For important security updates compatible with MSIE, please use the [2.x branch](https://github.com/cure53/DOMPurify/tree/2.x).**
|
|
14
14
|
|
|
15
|
-
Our automated tests cover [19 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
|
|
15
|
+
Our automated tests cover [19 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 v16.x, v17.x, v18.x and v19.x, running DOMPurify on [jsdom](https://github.com/jsdom/jsdom). Older Node versions are known to work as well, but hey... no guarantees.
|
|
16
16
|
|
|
17
17
|
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.
|
|
18
18
|
|
|
@@ -145,13 +145,9 @@ DOMPurify.sanitize('<UL><li><A HREF=//google.com>click</UL>'); // becomes <ul><l
|
|
|
145
145
|
|
|
146
146
|
DOMPurify currently supports HTML5, SVG and MathML. DOMPurify per default allows CSS, HTML custom data attributes. DOMPurify also supports the Shadow DOM - and sanitizes DOM templates recursively. DOMPurify also allows you to sanitize HTML for being used with the jQuery `$()` and `elm.html()` API without any known problems.
|
|
147
147
|
|
|
148
|
-
## What about
|
|
148
|
+
## What about legacy browsers like Internet Explorer?
|
|
149
149
|
|
|
150
|
-
DOMPurify
|
|
151
|
-
|
|
152
|
-
If not even `toStaticHTML` is supported, DOMPurify does nothing at all. It simply returns exactly the string that you fed it.
|
|
153
|
-
|
|
154
|
-
DOMPurify also exposes a property called `isSupported`, which tells you whether DOMPurify will be able to do its job.
|
|
150
|
+
DOMPurify does nothing at all. It simply returns exactly the string that you fed it. DOMPurify exposes a property called `isSupported`, which tells you whether it will be able to do its job, so you can come up with your own backup plan.
|
|
155
151
|
|
|
156
152
|
## What about DOMPurify and Trusted Types?
|
|
157
153
|
|
package/dist/purify.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @license DOMPurify
|
|
1
|
+
/*! @license DOMPurify 3.0.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.1/LICENSE */
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -51,6 +51,10 @@ function _construct(Parent, args, Class) {
|
|
|
51
51
|
return _construct.apply(null, arguments);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
function _slicedToArray(arr, i) {
|
|
55
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
56
|
+
}
|
|
57
|
+
|
|
54
58
|
function _toConsumableArray(arr) {
|
|
55
59
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
56
60
|
}
|
|
@@ -59,10 +63,44 @@ function _arrayWithoutHoles(arr) {
|
|
|
59
63
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
function _arrayWithHoles(arr) {
|
|
67
|
+
if (Array.isArray(arr)) return arr;
|
|
68
|
+
}
|
|
69
|
+
|
|
62
70
|
function _iterableToArray(iter) {
|
|
63
71
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
64
72
|
}
|
|
65
73
|
|
|
74
|
+
function _iterableToArrayLimit(arr, i) {
|
|
75
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
76
|
+
|
|
77
|
+
if (_i == null) return;
|
|
78
|
+
var _arr = [];
|
|
79
|
+
var _n = true;
|
|
80
|
+
var _d = false;
|
|
81
|
+
|
|
82
|
+
var _s, _e;
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
86
|
+
_arr.push(_s.value);
|
|
87
|
+
|
|
88
|
+
if (i && _arr.length === i) break;
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
_d = true;
|
|
92
|
+
_e = err;
|
|
93
|
+
} finally {
|
|
94
|
+
try {
|
|
95
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
96
|
+
} finally {
|
|
97
|
+
if (_d) throw _e;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return _arr;
|
|
102
|
+
}
|
|
103
|
+
|
|
66
104
|
function _unsupportedIterableToArray(o, minLen) {
|
|
67
105
|
if (!o) return;
|
|
68
106
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -84,7 +122,68 @@ function _nonIterableSpread() {
|
|
|
84
122
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
85
123
|
}
|
|
86
124
|
|
|
87
|
-
|
|
125
|
+
function _nonIterableRest() {
|
|
126
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
130
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
131
|
+
|
|
132
|
+
if (!it) {
|
|
133
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
134
|
+
if (it) o = it;
|
|
135
|
+
var i = 0;
|
|
136
|
+
|
|
137
|
+
var F = function () {};
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
s: F,
|
|
141
|
+
n: function () {
|
|
142
|
+
if (i >= o.length) return {
|
|
143
|
+
done: true
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
done: false,
|
|
147
|
+
value: o[i++]
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
e: function (e) {
|
|
151
|
+
throw e;
|
|
152
|
+
},
|
|
153
|
+
f: F
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
var normalCompletion = true,
|
|
161
|
+
didErr = false,
|
|
162
|
+
err;
|
|
163
|
+
return {
|
|
164
|
+
s: function () {
|
|
165
|
+
it = it.call(o);
|
|
166
|
+
},
|
|
167
|
+
n: function () {
|
|
168
|
+
var step = it.next();
|
|
169
|
+
normalCompletion = step.done;
|
|
170
|
+
return step;
|
|
171
|
+
},
|
|
172
|
+
e: function (e) {
|
|
173
|
+
didErr = true;
|
|
174
|
+
err = e;
|
|
175
|
+
},
|
|
176
|
+
f: function () {
|
|
177
|
+
try {
|
|
178
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
179
|
+
} finally {
|
|
180
|
+
if (didErr) throw err;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var entries = Object.entries,
|
|
88
187
|
setPrototypeOf = Object.setPrototypeOf,
|
|
89
188
|
isFrozen = Object.isFrozen,
|
|
90
189
|
getPrototypeOf = Object.getPrototypeOf,
|
|
@@ -189,20 +288,28 @@ function addToSet(set, array, transformCaseFunc) {
|
|
|
189
288
|
|
|
190
289
|
function clone(object) {
|
|
191
290
|
var newObject = create(null);
|
|
192
|
-
var property;
|
|
193
291
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
292
|
+
var _iterator = _createForOfIteratorHelper(entries(object)),
|
|
293
|
+
_step;
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
297
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
298
|
+
property = _step$value[0],
|
|
299
|
+
value = _step$value[1];
|
|
300
|
+
|
|
301
|
+
newObject[property] = value;
|
|
197
302
|
}
|
|
303
|
+
} catch (err) {
|
|
304
|
+
_iterator.e(err);
|
|
305
|
+
} finally {
|
|
306
|
+
_iterator.f();
|
|
198
307
|
}
|
|
199
308
|
|
|
200
309
|
return newObject;
|
|
201
310
|
}
|
|
202
|
-
/*
|
|
203
|
-
*
|
|
204
|
-
* if the prop is function or getter and behaves
|
|
205
|
-
* accordingly. */
|
|
311
|
+
/* This method automatically checks if the prop is function
|
|
312
|
+
* or getter and behaves accordingly. */
|
|
206
313
|
|
|
207
314
|
function lookupGetter(object, prop) {
|
|
208
315
|
while (object !== null) {
|
|
@@ -324,7 +431,7 @@ function createDOMPurify() {
|
|
|
324
431
|
*/
|
|
325
432
|
|
|
326
433
|
|
|
327
|
-
DOMPurify.version = '
|
|
434
|
+
DOMPurify.version = '3.0.1';
|
|
328
435
|
/**
|
|
329
436
|
* Array of elements that DOMPurify removed during sanitation.
|
|
330
437
|
* Empty if nothing was removed.
|
|
@@ -379,18 +486,12 @@ function createDOMPurify() {
|
|
|
379
486
|
createDocumentFragment = _document.createDocumentFragment,
|
|
380
487
|
getElementsByTagName = _document.getElementsByTagName;
|
|
381
488
|
var importNode = originalDocument.importNode;
|
|
382
|
-
var documentMode = {};
|
|
383
|
-
|
|
384
|
-
try {
|
|
385
|
-
documentMode = clone(document).documentMode ? document.documentMode : {};
|
|
386
|
-
} catch (_) {}
|
|
387
|
-
|
|
388
489
|
var hooks = {};
|
|
389
490
|
/**
|
|
390
491
|
* Expose whether this browser supports running the full DOMPurify.
|
|
391
492
|
*/
|
|
392
493
|
|
|
393
|
-
DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined'
|
|
494
|
+
DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined';
|
|
394
495
|
var MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
|
|
395
496
|
ERB_EXPR$1 = ERB_EXPR,
|
|
396
497
|
TMPLIT_EXPR$1 = TMPLIT_EXPR,
|
|
@@ -870,11 +971,7 @@ function createDOMPurify() {
|
|
|
870
971
|
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
871
972
|
node.parentNode.removeChild(node);
|
|
872
973
|
} catch (_) {
|
|
873
|
-
|
|
874
|
-
node.outerHTML = emptyHTML;
|
|
875
|
-
} catch (_) {
|
|
876
|
-
node.remove();
|
|
877
|
-
}
|
|
974
|
+
node.remove();
|
|
878
975
|
}
|
|
879
976
|
};
|
|
880
977
|
/**
|
|
@@ -1053,14 +1150,6 @@ function createDOMPurify() {
|
|
|
1053
1150
|
|
|
1054
1151
|
return true;
|
|
1055
1152
|
}
|
|
1056
|
-
/* Check if tagname contains Unicode */
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
|
|
1060
|
-
_forceRemove(currentNode);
|
|
1061
|
-
|
|
1062
|
-
return true;
|
|
1063
|
-
}
|
|
1064
1153
|
/* Now let's check the element's type and name */
|
|
1065
1154
|
|
|
1066
1155
|
|
|
@@ -1079,14 +1168,6 @@ function createDOMPurify() {
|
|
|
1079
1168
|
|
|
1080
1169
|
return true;
|
|
1081
1170
|
}
|
|
1082
|
-
/* Mitigate a problem with templates inside select */
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
|
|
1086
|
-
_forceRemove(currentNode);
|
|
1087
|
-
|
|
1088
|
-
return true;
|
|
1089
|
-
}
|
|
1090
1171
|
/* Remove element if anything forbids its presence */
|
|
1091
1172
|
|
|
1092
1173
|
|
|
@@ -1124,6 +1205,8 @@ function createDOMPurify() {
|
|
|
1124
1205
|
|
|
1125
1206
|
return true;
|
|
1126
1207
|
}
|
|
1208
|
+
/* Make sure that older browsers don't get noscript mXSS */
|
|
1209
|
+
|
|
1127
1210
|
|
|
1128
1211
|
if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
|
|
1129
1212
|
_forceRemove(currentNode);
|
|
@@ -1400,7 +1483,6 @@ function createDOMPurify() {
|
|
|
1400
1483
|
var body;
|
|
1401
1484
|
var importedNode;
|
|
1402
1485
|
var currentNode;
|
|
1403
|
-
var oldNode;
|
|
1404
1486
|
var returnNode;
|
|
1405
1487
|
/* Make sure we have a string to sanitize.
|
|
1406
1488
|
DO NOT return early, as this will return the wrong type if
|
|
@@ -1426,20 +1508,10 @@ function createDOMPurify() {
|
|
|
1426
1508
|
}
|
|
1427
1509
|
}
|
|
1428
1510
|
}
|
|
1429
|
-
/*
|
|
1511
|
+
/* Return dirty HTML if DOMPurify cannot run */
|
|
1430
1512
|
|
|
1431
1513
|
|
|
1432
1514
|
if (!DOMPurify.isSupported) {
|
|
1433
|
-
if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
|
|
1434
|
-
if (typeof dirty === 'string') {
|
|
1435
|
-
return window.toStaticHTML(dirty);
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
if (_isNode(dirty)) {
|
|
1439
|
-
return window.toStaticHTML(dirty.outerHTML);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
1515
|
return dirty;
|
|
1444
1516
|
}
|
|
1445
1517
|
/* Assign config vars */
|
|
@@ -1512,13 +1584,7 @@ function createDOMPurify() {
|
|
|
1512
1584
|
|
|
1513
1585
|
|
|
1514
1586
|
while (currentNode = nodeIterator.nextNode()) {
|
|
1515
|
-
/* Fix IE's strange behavior with manipulated textNodes #89 */
|
|
1516
|
-
if (currentNode.nodeType === 3 && currentNode === oldNode) {
|
|
1517
|
-
continue;
|
|
1518
|
-
}
|
|
1519
1587
|
/* Sanitize tags and elements */
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
1588
|
if (_sanitizeElements(currentNode)) {
|
|
1523
1589
|
continue;
|
|
1524
1590
|
}
|
|
@@ -1532,13 +1598,10 @@ function createDOMPurify() {
|
|
|
1532
1598
|
|
|
1533
1599
|
|
|
1534
1600
|
_sanitizeAttributes(currentNode);
|
|
1535
|
-
|
|
1536
|
-
oldNode = currentNode;
|
|
1537
1601
|
}
|
|
1538
|
-
|
|
1539
|
-
oldNode = null;
|
|
1540
1602
|
/* If we sanitized `dirty` in-place, return it. */
|
|
1541
1603
|
|
|
1604
|
+
|
|
1542
1605
|
if (IN_PLACE) {
|
|
1543
1606
|
return dirty;
|
|
1544
1607
|
}
|