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.es.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 _typeof(obj) {
|
|
4
4
|
"@babel/helpers - typeof";
|
|
@@ -49,6 +49,10 @@ function _construct(Parent, args, Class) {
|
|
|
49
49
|
return _construct.apply(null, arguments);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function _slicedToArray(arr, i) {
|
|
53
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
54
|
+
}
|
|
55
|
+
|
|
52
56
|
function _toConsumableArray(arr) {
|
|
53
57
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
54
58
|
}
|
|
@@ -57,10 +61,44 @@ function _arrayWithoutHoles(arr) {
|
|
|
57
61
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
58
62
|
}
|
|
59
63
|
|
|
64
|
+
function _arrayWithHoles(arr) {
|
|
65
|
+
if (Array.isArray(arr)) return arr;
|
|
66
|
+
}
|
|
67
|
+
|
|
60
68
|
function _iterableToArray(iter) {
|
|
61
69
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
62
70
|
}
|
|
63
71
|
|
|
72
|
+
function _iterableToArrayLimit(arr, i) {
|
|
73
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
74
|
+
|
|
75
|
+
if (_i == null) return;
|
|
76
|
+
var _arr = [];
|
|
77
|
+
var _n = true;
|
|
78
|
+
var _d = false;
|
|
79
|
+
|
|
80
|
+
var _s, _e;
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
84
|
+
_arr.push(_s.value);
|
|
85
|
+
|
|
86
|
+
if (i && _arr.length === i) break;
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
_d = true;
|
|
90
|
+
_e = err;
|
|
91
|
+
} finally {
|
|
92
|
+
try {
|
|
93
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
94
|
+
} finally {
|
|
95
|
+
if (_d) throw _e;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return _arr;
|
|
100
|
+
}
|
|
101
|
+
|
|
64
102
|
function _unsupportedIterableToArray(o, minLen) {
|
|
65
103
|
if (!o) return;
|
|
66
104
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -82,7 +120,68 @@ function _nonIterableSpread() {
|
|
|
82
120
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
83
121
|
}
|
|
84
122
|
|
|
85
|
-
|
|
123
|
+
function _nonIterableRest() {
|
|
124
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
128
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
129
|
+
|
|
130
|
+
if (!it) {
|
|
131
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
132
|
+
if (it) o = it;
|
|
133
|
+
var i = 0;
|
|
134
|
+
|
|
135
|
+
var F = function () {};
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
s: F,
|
|
139
|
+
n: function () {
|
|
140
|
+
if (i >= o.length) return {
|
|
141
|
+
done: true
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
done: false,
|
|
145
|
+
value: o[i++]
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
e: function (e) {
|
|
149
|
+
throw e;
|
|
150
|
+
},
|
|
151
|
+
f: F
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var normalCompletion = true,
|
|
159
|
+
didErr = false,
|
|
160
|
+
err;
|
|
161
|
+
return {
|
|
162
|
+
s: function () {
|
|
163
|
+
it = it.call(o);
|
|
164
|
+
},
|
|
165
|
+
n: function () {
|
|
166
|
+
var step = it.next();
|
|
167
|
+
normalCompletion = step.done;
|
|
168
|
+
return step;
|
|
169
|
+
},
|
|
170
|
+
e: function (e) {
|
|
171
|
+
didErr = true;
|
|
172
|
+
err = e;
|
|
173
|
+
},
|
|
174
|
+
f: function () {
|
|
175
|
+
try {
|
|
176
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
177
|
+
} finally {
|
|
178
|
+
if (didErr) throw err;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
var entries = Object.entries,
|
|
86
185
|
setPrototypeOf = Object.setPrototypeOf,
|
|
87
186
|
isFrozen = Object.isFrozen,
|
|
88
187
|
getPrototypeOf = Object.getPrototypeOf,
|
|
@@ -187,20 +286,28 @@ function addToSet(set, array, transformCaseFunc) {
|
|
|
187
286
|
|
|
188
287
|
function clone(object) {
|
|
189
288
|
var newObject = create(null);
|
|
190
|
-
var property;
|
|
191
289
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
290
|
+
var _iterator = _createForOfIteratorHelper(entries(object)),
|
|
291
|
+
_step;
|
|
292
|
+
|
|
293
|
+
try {
|
|
294
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
295
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
296
|
+
property = _step$value[0],
|
|
297
|
+
value = _step$value[1];
|
|
298
|
+
|
|
299
|
+
newObject[property] = value;
|
|
195
300
|
}
|
|
301
|
+
} catch (err) {
|
|
302
|
+
_iterator.e(err);
|
|
303
|
+
} finally {
|
|
304
|
+
_iterator.f();
|
|
196
305
|
}
|
|
197
306
|
|
|
198
307
|
return newObject;
|
|
199
308
|
}
|
|
200
|
-
/*
|
|
201
|
-
*
|
|
202
|
-
* if the prop is function or getter and behaves
|
|
203
|
-
* accordingly. */
|
|
309
|
+
/* This method automatically checks if the prop is function
|
|
310
|
+
* or getter and behaves accordingly. */
|
|
204
311
|
|
|
205
312
|
function lookupGetter(object, prop) {
|
|
206
313
|
while (object !== null) {
|
|
@@ -322,7 +429,7 @@ function createDOMPurify() {
|
|
|
322
429
|
*/
|
|
323
430
|
|
|
324
431
|
|
|
325
|
-
DOMPurify.version = '
|
|
432
|
+
DOMPurify.version = '3.0.0';
|
|
326
433
|
/**
|
|
327
434
|
* Array of elements that DOMPurify removed during sanitation.
|
|
328
435
|
* Empty if nothing was removed.
|
|
@@ -377,18 +484,12 @@ function createDOMPurify() {
|
|
|
377
484
|
createDocumentFragment = _document.createDocumentFragment,
|
|
378
485
|
getElementsByTagName = _document.getElementsByTagName;
|
|
379
486
|
var importNode = originalDocument.importNode;
|
|
380
|
-
var documentMode = {};
|
|
381
|
-
|
|
382
|
-
try {
|
|
383
|
-
documentMode = clone(document).documentMode ? document.documentMode : {};
|
|
384
|
-
} catch (_) {}
|
|
385
|
-
|
|
386
487
|
var hooks = {};
|
|
387
488
|
/**
|
|
388
489
|
* Expose whether this browser supports running the full DOMPurify.
|
|
389
490
|
*/
|
|
390
491
|
|
|
391
|
-
DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined'
|
|
492
|
+
DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined';
|
|
392
493
|
var MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
|
|
393
494
|
ERB_EXPR$1 = ERB_EXPR,
|
|
394
495
|
TMPLIT_EXPR$1 = TMPLIT_EXPR,
|
|
@@ -452,6 +553,10 @@ function createDOMPurify() {
|
|
|
452
553
|
/* Decide if unknown protocols are okay */
|
|
453
554
|
|
|
454
555
|
var ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
556
|
+
/* Decide if self-closing tags in attributes are allowed.
|
|
557
|
+
* Usually removed due to a mXSS issue in jQuery 3.0 */
|
|
558
|
+
|
|
559
|
+
var ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
455
560
|
/* Output should be safe for common template engines.
|
|
456
561
|
* This means, DOMPurify removes data attributes, mustaches and ERB
|
|
457
562
|
*/
|
|
@@ -604,6 +709,8 @@ function createDOMPurify() {
|
|
|
604
709
|
|
|
605
710
|
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
|
|
606
711
|
|
|
712
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
|
|
713
|
+
|
|
607
714
|
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
|
|
608
715
|
|
|
609
716
|
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
|
|
@@ -861,11 +968,7 @@ function createDOMPurify() {
|
|
|
861
968
|
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
862
969
|
node.parentNode.removeChild(node);
|
|
863
970
|
} catch (_) {
|
|
864
|
-
|
|
865
|
-
node.outerHTML = emptyHTML;
|
|
866
|
-
} catch (_) {
|
|
867
|
-
node.remove();
|
|
868
|
-
}
|
|
971
|
+
node.remove();
|
|
869
972
|
}
|
|
870
973
|
};
|
|
871
974
|
/**
|
|
@@ -1044,14 +1147,6 @@ function createDOMPurify() {
|
|
|
1044
1147
|
|
|
1045
1148
|
return true;
|
|
1046
1149
|
}
|
|
1047
|
-
/* Check if tagname contains Unicode */
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
|
|
1051
|
-
_forceRemove(currentNode);
|
|
1052
|
-
|
|
1053
|
-
return true;
|
|
1054
|
-
}
|
|
1055
1150
|
/* Now let's check the element's type and name */
|
|
1056
1151
|
|
|
1057
1152
|
|
|
@@ -1070,14 +1165,6 @@ function createDOMPurify() {
|
|
|
1070
1165
|
|
|
1071
1166
|
return true;
|
|
1072
1167
|
}
|
|
1073
|
-
/* Mitigate a problem with templates inside select */
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
|
|
1077
|
-
_forceRemove(currentNode);
|
|
1078
|
-
|
|
1079
|
-
return true;
|
|
1080
|
-
}
|
|
1081
1168
|
/* Remove element if anything forbids its presence */
|
|
1082
1169
|
|
|
1083
1170
|
|
|
@@ -1115,6 +1202,8 @@ function createDOMPurify() {
|
|
|
1115
1202
|
|
|
1116
1203
|
return true;
|
|
1117
1204
|
}
|
|
1205
|
+
/* Make sure that older browsers don't get noscript mXSS */
|
|
1206
|
+
|
|
1118
1207
|
|
|
1119
1208
|
if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
|
|
1120
1209
|
_forceRemove(currentNode);
|
|
@@ -1267,7 +1356,7 @@ function createDOMPurify() {
|
|
|
1267
1356
|
/* Work around a security issue in jQuery 3.0 */
|
|
1268
1357
|
|
|
1269
1358
|
|
|
1270
|
-
if (regExpTest(/\/>/i, value)) {
|
|
1359
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
1271
1360
|
_removeAttribute(name, currentNode);
|
|
1272
1361
|
|
|
1273
1362
|
continue;
|
|
@@ -1391,7 +1480,6 @@ function createDOMPurify() {
|
|
|
1391
1480
|
var body;
|
|
1392
1481
|
var importedNode;
|
|
1393
1482
|
var currentNode;
|
|
1394
|
-
var oldNode;
|
|
1395
1483
|
var returnNode;
|
|
1396
1484
|
/* Make sure we have a string to sanitize.
|
|
1397
1485
|
DO NOT return early, as this will return the wrong type if
|
|
@@ -1417,20 +1505,10 @@ function createDOMPurify() {
|
|
|
1417
1505
|
}
|
|
1418
1506
|
}
|
|
1419
1507
|
}
|
|
1420
|
-
/*
|
|
1508
|
+
/* Return dirty HTML if DOMPurify cannot run */
|
|
1421
1509
|
|
|
1422
1510
|
|
|
1423
1511
|
if (!DOMPurify.isSupported) {
|
|
1424
|
-
if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
|
|
1425
|
-
if (typeof dirty === 'string') {
|
|
1426
|
-
return window.toStaticHTML(dirty);
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
if (_isNode(dirty)) {
|
|
1430
|
-
return window.toStaticHTML(dirty.outerHTML);
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
1512
|
return dirty;
|
|
1435
1513
|
}
|
|
1436
1514
|
/* Assign config vars */
|
|
@@ -1503,13 +1581,7 @@ function createDOMPurify() {
|
|
|
1503
1581
|
|
|
1504
1582
|
|
|
1505
1583
|
while (currentNode = nodeIterator.nextNode()) {
|
|
1506
|
-
/* Fix IE's strange behavior with manipulated textNodes #89 */
|
|
1507
|
-
if (currentNode.nodeType === 3 && currentNode === oldNode) {
|
|
1508
|
-
continue;
|
|
1509
|
-
}
|
|
1510
1584
|
/* Sanitize tags and elements */
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
1585
|
if (_sanitizeElements(currentNode)) {
|
|
1514
1586
|
continue;
|
|
1515
1587
|
}
|
|
@@ -1523,13 +1595,10 @@ function createDOMPurify() {
|
|
|
1523
1595
|
|
|
1524
1596
|
|
|
1525
1597
|
_sanitizeAttributes(currentNode);
|
|
1526
|
-
|
|
1527
|
-
oldNode = currentNode;
|
|
1528
1598
|
}
|
|
1529
|
-
|
|
1530
|
-
oldNode = null;
|
|
1531
1599
|
/* If we sanitized `dirty` in-place, return it. */
|
|
1532
1600
|
|
|
1601
|
+
|
|
1533
1602
|
if (IN_PLACE) {
|
|
1534
1603
|
return dirty;
|
|
1535
1604
|
}
|
|
@@ -1548,7 +1617,7 @@ function createDOMPurify() {
|
|
|
1548
1617
|
returnNode = body;
|
|
1549
1618
|
}
|
|
1550
1619
|
|
|
1551
|
-
if (ALLOWED_ATTR.shadowroot) {
|
|
1620
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmod) {
|
|
1552
1621
|
/*
|
|
1553
1622
|
AdoptNode() is not used because internal state is not reset
|
|
1554
1623
|
(e.g. the past names map of a HTMLFormElement), this is safe
|