dompurify 2.5.0 → 2.5.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/README.md CHANGED
@@ -6,11 +6,11 @@
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.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.1.1.
10
10
 
11
11
  DOMPurify is written in JavaScript and works in all modern browsers (Safari (10+), Opera (15+), Internet Explorer (10+), Edge, Firefox and Chrome - as well as almost anything else using Blink or WebKit). It doesn't break on MSIE6 or other legacy browsers. It either uses [a fall-back](#what-about-older-browsers-like-msie8) or simply does nothing.
12
12
 
13
- **Note that DOMPurify v2.5.0 is the latest version supporting MSIE. For important security updates compatible with MSIE, please use the 2.x branch.**
13
+ **Note that DOMPurify v2.5.1 is the latest version supporting MSIE. For important security updates compatible with MSIE, please use the 2.x branch.**
14
14
 
15
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 v14.x, v16.x, v17.x and v18.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
 
@@ -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.1 | (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.1/LICENSE */
2
2
 
3
3
  'use strict';
4
4
 
@@ -283,7 +283,7 @@ function createDOMPurify() {
283
283
  * Version label, exposed for easier checks
284
284
  * if DOMPurify is up to date or not
285
285
  */
286
- DOMPurify.version = '2.5.0';
286
+ DOMPurify.version = '2.5.1';
287
287
 
288
288
  /**
289
289
  * Array of elements that DOMPurify removed during sanitation.
@@ -509,6 +509,9 @@ function createDOMPurify() {
509
509
  /* Keep a reference to config to pass to hooks */
510
510
  var CONFIG = null;
511
511
 
512
+ /* Specify the maximum element nesting depth to prevent mXSS */
513
+ var MAX_NESTING_DEPTH = 255;
514
+
512
515
  /* Ideally, do not touch anything below this line */
513
516
  /* ______________________________________________ */
514
517
 
@@ -903,7 +906,7 @@ function createDOMPurify() {
903
906
  * @return {Boolean} true if clobbered, false if safe
904
907
  */
905
908
  var _isClobbered = function _isClobbered(elm) {
906
- 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');
909
+ 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');
907
910
  };
908
911
 
909
912
  /**
@@ -1009,7 +1012,9 @@ function createDOMPurify() {
1009
1012
  if (childNodes && parentNode) {
1010
1013
  var childCount = childNodes.length;
1011
1014
  for (var i = childCount - 1; i >= 0; --i) {
1012
- parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1015
+ var childClone = cloneNode(childNodes[i], true);
1016
+ childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
1017
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
1013
1018
  }
1014
1019
  }
1015
1020
  }
@@ -1240,8 +1245,27 @@ function createDOMPurify() {
1240
1245
  continue;
1241
1246
  }
1242
1247
 
1248
+ /* Set the nesting depth of an element */
1249
+ if (shadowNode.nodeType === 1) {
1250
+ if (shadowNode.parentNode && shadowNode.parentNode.__depth) {
1251
+ /*
1252
+ We want the depth of the node in the original tree, which can
1253
+ change when it's removed from its parent.
1254
+ */
1255
+ shadowNode.__depth = (shadowNode.__removalCount || 0) + shadowNode.parentNode.__depth + 1;
1256
+ } else {
1257
+ shadowNode.__depth = 1;
1258
+ }
1259
+ }
1260
+
1261
+ /* Remove an element if nested too deeply to avoid mXSS */
1262
+ if (shadowNode.__depth >= MAX_NESTING_DEPTH) {
1263
+ _forceRemove(shadowNode);
1264
+ }
1265
+
1243
1266
  /* Deep shadow DOM detected */
1244
1267
  if (shadowNode.content instanceof DocumentFragment) {
1268
+ shadowNode.content.__depth = shadowNode.__depth;
1245
1269
  _sanitizeShadowDOM(shadowNode.content);
1246
1270
  }
1247
1271
 
@@ -1372,8 +1396,27 @@ function createDOMPurify() {
1372
1396
  continue;
1373
1397
  }
1374
1398
 
1399
+ /* Set the nesting depth of an element */
1400
+ if (currentNode.nodeType === 1) {
1401
+ if (currentNode.parentNode && currentNode.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) + currentNode.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
+ }
1416
+
1375
1417
  /* Shadow DOM detected, sanitize it */
1376
1418
  if (currentNode.content instanceof DocumentFragment) {
1419
+ currentNode.content.__depth = currentNode.__depth;
1377
1420
  _sanitizeShadowDOM(currentNode.content);
1378
1421
  }
1379
1422