dompurify 2.4.3 → 3.0.0
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 +132 -63
- package/dist/purify.cjs.js.map +1 -1
- package/dist/purify.es.js +132 -63
- package/dist/purify.es.js.map +1 -1
- package/dist/purify.js +132 -63
- 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/dist/purify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @license DOMPurify
|
|
1
|
+
/*! @license DOMPurify 3.0.0 | (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.0/LICENSE */
|
|
2
2
|
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -55,6 +55,10 @@
|
|
|
55
55
|
return _construct.apply(null, arguments);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
function _slicedToArray(arr, i) {
|
|
59
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
60
|
+
}
|
|
61
|
+
|
|
58
62
|
function _toConsumableArray(arr) {
|
|
59
63
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
60
64
|
}
|
|
@@ -63,10 +67,44 @@
|
|
|
63
67
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
64
68
|
}
|
|
65
69
|
|
|
70
|
+
function _arrayWithHoles(arr) {
|
|
71
|
+
if (Array.isArray(arr)) return arr;
|
|
72
|
+
}
|
|
73
|
+
|
|
66
74
|
function _iterableToArray(iter) {
|
|
67
75
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
function _iterableToArrayLimit(arr, i) {
|
|
79
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
80
|
+
|
|
81
|
+
if (_i == null) return;
|
|
82
|
+
var _arr = [];
|
|
83
|
+
var _n = true;
|
|
84
|
+
var _d = false;
|
|
85
|
+
|
|
86
|
+
var _s, _e;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
90
|
+
_arr.push(_s.value);
|
|
91
|
+
|
|
92
|
+
if (i && _arr.length === i) break;
|
|
93
|
+
}
|
|
94
|
+
} catch (err) {
|
|
95
|
+
_d = true;
|
|
96
|
+
_e = err;
|
|
97
|
+
} finally {
|
|
98
|
+
try {
|
|
99
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
100
|
+
} finally {
|
|
101
|
+
if (_d) throw _e;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return _arr;
|
|
106
|
+
}
|
|
107
|
+
|
|
70
108
|
function _unsupportedIterableToArray(o, minLen) {
|
|
71
109
|
if (!o) return;
|
|
72
110
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -88,7 +126,68 @@
|
|
|
88
126
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
89
127
|
}
|
|
90
128
|
|
|
91
|
-
|
|
129
|
+
function _nonIterableRest() {
|
|
130
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
134
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
135
|
+
|
|
136
|
+
if (!it) {
|
|
137
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
138
|
+
if (it) o = it;
|
|
139
|
+
var i = 0;
|
|
140
|
+
|
|
141
|
+
var F = function () {};
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
s: F,
|
|
145
|
+
n: function () {
|
|
146
|
+
if (i >= o.length) return {
|
|
147
|
+
done: true
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
done: false,
|
|
151
|
+
value: o[i++]
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
e: function (e) {
|
|
155
|
+
throw e;
|
|
156
|
+
},
|
|
157
|
+
f: F
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
var normalCompletion = true,
|
|
165
|
+
didErr = false,
|
|
166
|
+
err;
|
|
167
|
+
return {
|
|
168
|
+
s: function () {
|
|
169
|
+
it = it.call(o);
|
|
170
|
+
},
|
|
171
|
+
n: function () {
|
|
172
|
+
var step = it.next();
|
|
173
|
+
normalCompletion = step.done;
|
|
174
|
+
return step;
|
|
175
|
+
},
|
|
176
|
+
e: function (e) {
|
|
177
|
+
didErr = true;
|
|
178
|
+
err = e;
|
|
179
|
+
},
|
|
180
|
+
f: function () {
|
|
181
|
+
try {
|
|
182
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
183
|
+
} finally {
|
|
184
|
+
if (didErr) throw err;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var entries = Object.entries,
|
|
92
191
|
setPrototypeOf = Object.setPrototypeOf,
|
|
93
192
|
isFrozen = Object.isFrozen,
|
|
94
193
|
getPrototypeOf = Object.getPrototypeOf,
|
|
@@ -193,20 +292,28 @@
|
|
|
193
292
|
|
|
194
293
|
function clone(object) {
|
|
195
294
|
var newObject = create(null);
|
|
196
|
-
var property;
|
|
197
295
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
296
|
+
var _iterator = _createForOfIteratorHelper(entries(object)),
|
|
297
|
+
_step;
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
301
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
302
|
+
property = _step$value[0],
|
|
303
|
+
value = _step$value[1];
|
|
304
|
+
|
|
305
|
+
newObject[property] = value;
|
|
201
306
|
}
|
|
307
|
+
} catch (err) {
|
|
308
|
+
_iterator.e(err);
|
|
309
|
+
} finally {
|
|
310
|
+
_iterator.f();
|
|
202
311
|
}
|
|
203
312
|
|
|
204
313
|
return newObject;
|
|
205
314
|
}
|
|
206
|
-
/*
|
|
207
|
-
*
|
|
208
|
-
* if the prop is function or getter and behaves
|
|
209
|
-
* accordingly. */
|
|
315
|
+
/* This method automatically checks if the prop is function
|
|
316
|
+
* or getter and behaves accordingly. */
|
|
210
317
|
|
|
211
318
|
function lookupGetter(object, prop) {
|
|
212
319
|
while (object !== null) {
|
|
@@ -328,7 +435,7 @@
|
|
|
328
435
|
*/
|
|
329
436
|
|
|
330
437
|
|
|
331
|
-
DOMPurify.version = '
|
|
438
|
+
DOMPurify.version = '3.0.0';
|
|
332
439
|
/**
|
|
333
440
|
* Array of elements that DOMPurify removed during sanitation.
|
|
334
441
|
* Empty if nothing was removed.
|
|
@@ -383,18 +490,12 @@
|
|
|
383
490
|
createDocumentFragment = _document.createDocumentFragment,
|
|
384
491
|
getElementsByTagName = _document.getElementsByTagName;
|
|
385
492
|
var importNode = originalDocument.importNode;
|
|
386
|
-
var documentMode = {};
|
|
387
|
-
|
|
388
|
-
try {
|
|
389
|
-
documentMode = clone(document).documentMode ? document.documentMode : {};
|
|
390
|
-
} catch (_) {}
|
|
391
|
-
|
|
392
493
|
var hooks = {};
|
|
393
494
|
/**
|
|
394
495
|
* Expose whether this browser supports running the full DOMPurify.
|
|
395
496
|
*/
|
|
396
497
|
|
|
397
|
-
DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined'
|
|
498
|
+
DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined';
|
|
398
499
|
var MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
|
|
399
500
|
ERB_EXPR$1 = ERB_EXPR,
|
|
400
501
|
TMPLIT_EXPR$1 = TMPLIT_EXPR,
|
|
@@ -458,6 +559,10 @@
|
|
|
458
559
|
/* Decide if unknown protocols are okay */
|
|
459
560
|
|
|
460
561
|
var ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
562
|
+
/* Decide if self-closing tags in attributes are allowed.
|
|
563
|
+
* Usually removed due to a mXSS issue in jQuery 3.0 */
|
|
564
|
+
|
|
565
|
+
var ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
461
566
|
/* Output should be safe for common template engines.
|
|
462
567
|
* This means, DOMPurify removes data attributes, mustaches and ERB
|
|
463
568
|
*/
|
|
@@ -610,6 +715,8 @@
|
|
|
610
715
|
|
|
611
716
|
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
|
|
612
717
|
|
|
718
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
|
|
719
|
+
|
|
613
720
|
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
|
|
614
721
|
|
|
615
722
|
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
|
|
@@ -867,11 +974,7 @@
|
|
|
867
974
|
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
868
975
|
node.parentNode.removeChild(node);
|
|
869
976
|
} catch (_) {
|
|
870
|
-
|
|
871
|
-
node.outerHTML = emptyHTML;
|
|
872
|
-
} catch (_) {
|
|
873
|
-
node.remove();
|
|
874
|
-
}
|
|
977
|
+
node.remove();
|
|
875
978
|
}
|
|
876
979
|
};
|
|
877
980
|
/**
|
|
@@ -1050,14 +1153,6 @@
|
|
|
1050
1153
|
|
|
1051
1154
|
return true;
|
|
1052
1155
|
}
|
|
1053
|
-
/* Check if tagname contains Unicode */
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
|
|
1057
|
-
_forceRemove(currentNode);
|
|
1058
|
-
|
|
1059
|
-
return true;
|
|
1060
|
-
}
|
|
1061
1156
|
/* Now let's check the element's type and name */
|
|
1062
1157
|
|
|
1063
1158
|
|
|
@@ -1076,14 +1171,6 @@
|
|
|
1076
1171
|
|
|
1077
1172
|
return true;
|
|
1078
1173
|
}
|
|
1079
|
-
/* Mitigate a problem with templates inside select */
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
|
|
1083
|
-
_forceRemove(currentNode);
|
|
1084
|
-
|
|
1085
|
-
return true;
|
|
1086
|
-
}
|
|
1087
1174
|
/* Remove element if anything forbids its presence */
|
|
1088
1175
|
|
|
1089
1176
|
|
|
@@ -1121,6 +1208,8 @@
|
|
|
1121
1208
|
|
|
1122
1209
|
return true;
|
|
1123
1210
|
}
|
|
1211
|
+
/* Make sure that older browsers don't get noscript mXSS */
|
|
1212
|
+
|
|
1124
1213
|
|
|
1125
1214
|
if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
|
|
1126
1215
|
_forceRemove(currentNode);
|
|
@@ -1273,7 +1362,7 @@
|
|
|
1273
1362
|
/* Work around a security issue in jQuery 3.0 */
|
|
1274
1363
|
|
|
1275
1364
|
|
|
1276
|
-
if (regExpTest(/\/>/i, value)) {
|
|
1365
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
1277
1366
|
_removeAttribute(name, currentNode);
|
|
1278
1367
|
|
|
1279
1368
|
continue;
|
|
@@ -1397,7 +1486,6 @@
|
|
|
1397
1486
|
var body;
|
|
1398
1487
|
var importedNode;
|
|
1399
1488
|
var currentNode;
|
|
1400
|
-
var oldNode;
|
|
1401
1489
|
var returnNode;
|
|
1402
1490
|
/* Make sure we have a string to sanitize.
|
|
1403
1491
|
DO NOT return early, as this will return the wrong type if
|
|
@@ -1423,20 +1511,10 @@
|
|
|
1423
1511
|
}
|
|
1424
1512
|
}
|
|
1425
1513
|
}
|
|
1426
|
-
/*
|
|
1514
|
+
/* Return dirty HTML if DOMPurify cannot run */
|
|
1427
1515
|
|
|
1428
1516
|
|
|
1429
1517
|
if (!DOMPurify.isSupported) {
|
|
1430
|
-
if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
|
|
1431
|
-
if (typeof dirty === 'string') {
|
|
1432
|
-
return window.toStaticHTML(dirty);
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
if (_isNode(dirty)) {
|
|
1436
|
-
return window.toStaticHTML(dirty.outerHTML);
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
1518
|
return dirty;
|
|
1441
1519
|
}
|
|
1442
1520
|
/* Assign config vars */
|
|
@@ -1509,13 +1587,7 @@
|
|
|
1509
1587
|
|
|
1510
1588
|
|
|
1511
1589
|
while (currentNode = nodeIterator.nextNode()) {
|
|
1512
|
-
/* Fix IE's strange behavior with manipulated textNodes #89 */
|
|
1513
|
-
if (currentNode.nodeType === 3 && currentNode === oldNode) {
|
|
1514
|
-
continue;
|
|
1515
|
-
}
|
|
1516
1590
|
/* Sanitize tags and elements */
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
1591
|
if (_sanitizeElements(currentNode)) {
|
|
1520
1592
|
continue;
|
|
1521
1593
|
}
|
|
@@ -1529,13 +1601,10 @@
|
|
|
1529
1601
|
|
|
1530
1602
|
|
|
1531
1603
|
_sanitizeAttributes(currentNode);
|
|
1532
|
-
|
|
1533
|
-
oldNode = currentNode;
|
|
1534
1604
|
}
|
|
1535
|
-
|
|
1536
|
-
oldNode = null;
|
|
1537
1605
|
/* If we sanitized `dirty` in-place, return it. */
|
|
1538
1606
|
|
|
1607
|
+
|
|
1539
1608
|
if (IN_PLACE) {
|
|
1540
1609
|
return dirty;
|
|
1541
1610
|
}
|
|
@@ -1554,7 +1623,7 @@
|
|
|
1554
1623
|
returnNode = body;
|
|
1555
1624
|
}
|
|
1556
1625
|
|
|
1557
|
-
if (ALLOWED_ATTR.shadowroot) {
|
|
1626
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmod) {
|
|
1558
1627
|
/*
|
|
1559
1628
|
AdoptNode() is not used because internal state is not reset
|
|
1560
1629
|
(e.g. the past names map of a HTMLFormElement), this is safe
|