dompurify 2.5.0 → 2.5.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/dist/purify.es.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @license DOMPurify 2.5.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.5.0/LICENSE */
1
+ /*! @license DOMPurify 2.5.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.5.2/LICENSE */
2
2
 
3
3
  function _typeof(obj) {
4
4
  "@babel/helpers - typeof";
@@ -281,7 +281,7 @@ function createDOMPurify() {
281
281
  * Version label, exposed for easier checks
282
282
  * if DOMPurify is up to date or not
283
283
  */
284
- DOMPurify.version = '2.5.0';
284
+ DOMPurify.version = '2.5.2';
285
285
 
286
286
  /**
287
287
  * Array of elements that DOMPurify removed during sanitation.
@@ -507,6 +507,9 @@ function createDOMPurify() {
507
507
  /* Keep a reference to config to pass to hooks */
508
508
  var CONFIG = null;
509
509
 
510
+ /* Specify the maximum element nesting depth to prevent mXSS */
511
+ var MAX_NESTING_DEPTH = 255;
512
+
510
513
  /* Ideally, do not touch anything below this line */
511
514
  /* ______________________________________________ */
512
515
 
@@ -668,7 +671,7 @@ function createDOMPurify() {
668
671
  CONFIG = cfg;
669
672
  };
670
673
  var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
671
- var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']);
674
+ var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'annotation-xml']);
672
675
 
673
676
  // Certain elements are allowed in both SVG and HTML
674
677
  // namespace. We need to specify them explicitly
@@ -901,7 +904,7 @@ function createDOMPurify() {
901
904
  * @return {Boolean} true if clobbered, false if safe
902
905
  */
903
906
  var _isClobbered = function _isClobbered(elm) {
904
- return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
907
+ return elm instanceof HTMLFormElement && (typeof elm.__depth !== 'undefined' && typeof elm.__depth !== 'number' || typeof elm.__removalCount !== 'undefined' && typeof elm.__removalCount !== 'number' || typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
905
908
  };
906
909
 
907
910
  /**
@@ -1007,7 +1010,9 @@ function createDOMPurify() {
1007
1010
  if (childNodes && parentNode) {
1008
1011
  var childCount = childNodes.length;
1009
1012
  for (var i = childCount - 1; i >= 0; --i) {
1010
- parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1013
+ var childClone = cloneNode(childNodes[i], true);
1014
+ childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
1015
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
1011
1016
  }
1012
1017
  }
1013
1018
  }
@@ -1237,9 +1242,29 @@ function createDOMPurify() {
1237
1242
  if (_sanitizeElements(shadowNode)) {
1238
1243
  continue;
1239
1244
  }
1245
+ var parentNode = getParentNode(shadowNode);
1246
+
1247
+ /* Set the nesting depth of an element */
1248
+ if (shadowNode.nodeType === 1) {
1249
+ if (parentNode && parentNode.__depth) {
1250
+ /*
1251
+ We want the depth of the node in the original tree, which can
1252
+ change when it's removed from its parent.
1253
+ */
1254
+ shadowNode.__depth = (shadowNode.__removalCount || 0) + parentNode.__depth + 1;
1255
+ } else {
1256
+ shadowNode.__depth = 1;
1257
+ }
1258
+ }
1259
+
1260
+ /* Remove an element if nested too deeply to avoid mXSS */
1261
+ if (shadowNode.__depth >= MAX_NESTING_DEPTH) {
1262
+ _forceRemove(shadowNode);
1263
+ }
1240
1264
 
1241
1265
  /* Deep shadow DOM detected */
1242
1266
  if (shadowNode.content instanceof DocumentFragment) {
1267
+ shadowNode.content.__depth = shadowNode.__depth;
1243
1268
  _sanitizeShadowDOM(shadowNode.content);
1244
1269
  }
1245
1270
 
@@ -1369,9 +1394,29 @@ function createDOMPurify() {
1369
1394
  if (_sanitizeElements(currentNode)) {
1370
1395
  continue;
1371
1396
  }
1397
+ var parentNode = getParentNode(currentNode);
1398
+
1399
+ /* Set the nesting depth of an element */
1400
+ if (currentNode.nodeType === 1) {
1401
+ if (parentNode && parentNode.__depth) {
1402
+ /*
1403
+ We want the depth of the node in the original tree, which can
1404
+ change when it's removed from its parent.
1405
+ */
1406
+ currentNode.__depth = (currentNode.__removalCount || 0) + parentNode.__depth + 1;
1407
+ } else {
1408
+ currentNode.__depth = 1;
1409
+ }
1410
+ }
1411
+
1412
+ /* Remove an element if nested too deeply to avoid mXSS */
1413
+ if (currentNode.__depth >= MAX_NESTING_DEPTH) {
1414
+ _forceRemove(currentNode);
1415
+ }
1372
1416
 
1373
1417
  /* Shadow DOM detected, sanitize it */
1374
1418
  if (currentNode.content instanceof DocumentFragment) {
1419
+ currentNode.content.__depth = currentNode.__depth;
1375
1420
  _sanitizeShadowDOM(currentNode.content);
1376
1421
  }
1377
1422