dompurify 2.5.1 → 2.5.3

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.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 */
1
+ /*! @license DOMPurify 2.5.3 | (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.3/LICENSE */
2
2
 
3
3
  function _typeof(obj) {
4
4
  "@babel/helpers - typeof";
@@ -110,6 +110,7 @@ var stringIndexOf = unapply(String.prototype.indexOf);
110
110
  var stringTrim = unapply(String.prototype.trim);
111
111
  var regExpTest = unapply(RegExp.prototype.test);
112
112
  var typeErrorCreate = unconstruct(TypeError);
113
+ var numberIsNaN = unapply(Number.isNaN);
113
114
  function unapply(func) {
114
115
  return function (thisArg) {
115
116
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -281,7 +282,7 @@ function createDOMPurify() {
281
282
  * Version label, exposed for easier checks
282
283
  * if DOMPurify is up to date or not
283
284
  */
284
- DOMPurify.version = '2.5.1';
285
+ DOMPurify.version = '2.5.3';
285
286
 
286
287
  /**
287
288
  * Array of elements that DOMPurify removed during sanitation.
@@ -671,7 +672,7 @@ function createDOMPurify() {
671
672
  CONFIG = cfg;
672
673
  };
673
674
  var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
674
- var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']);
675
+ var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'annotation-xml']);
675
676
 
676
677
  // Certain elements are allowed in both SVG and HTML
677
678
  // namespace. We need to specify them explicitly
@@ -1063,7 +1064,7 @@ function createDOMPurify() {
1063
1064
  // eslint-disable-next-line complexity
1064
1065
  var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1065
1066
  /* Make sure attribute cannot clobber */
1066
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1067
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement || value === '__depth' || value === '__removalCount')) {
1067
1068
  return false;
1068
1069
  }
1069
1070
 
@@ -1165,6 +1166,12 @@ function createDOMPurify() {
1165
1166
  continue;
1166
1167
  }
1167
1168
 
1169
+ /* Work around a security issue with comments inside attributes */
1170
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
1171
+ _removeAttribute(name, currentNode);
1172
+ continue;
1173
+ }
1174
+
1168
1175
  /* Sanitize attribute content to be template-safe */
1169
1176
  if (SAFE_FOR_TEMPLATES) {
1170
1177
  value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
@@ -1215,7 +1222,11 @@ function createDOMPurify() {
1215
1222
  /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1216
1223
  currentNode.setAttribute(name, value);
1217
1224
  }
1218
- arrayPop(DOMPurify.removed);
1225
+ if (_isClobbered(currentNode)) {
1226
+ _forceRemove(currentNode);
1227
+ } else {
1228
+ arrayPop(DOMPurify.removed);
1229
+ }
1219
1230
  } catch (_) {}
1220
1231
  }
1221
1232
 
@@ -1242,22 +1253,26 @@ function createDOMPurify() {
1242
1253
  if (_sanitizeElements(shadowNode)) {
1243
1254
  continue;
1244
1255
  }
1256
+ var parentNode = getParentNode(shadowNode);
1245
1257
 
1246
1258
  /* Set the nesting depth of an element */
1247
1259
  if (shadowNode.nodeType === 1) {
1248
- if (shadowNode.parentNode && shadowNode.parentNode.__depth) {
1260
+ if (parentNode && parentNode.__depth) {
1249
1261
  /*
1250
1262
  We want the depth of the node in the original tree, which can
1251
1263
  change when it's removed from its parent.
1252
1264
  */
1253
- shadowNode.__depth = (shadowNode.__removalCount || 0) + shadowNode.parentNode.__depth + 1;
1265
+ shadowNode.__depth = (shadowNode.__removalCount || 0) + parentNode.__depth + 1;
1254
1266
  } else {
1255
1267
  shadowNode.__depth = 1;
1256
1268
  }
1257
1269
  }
1258
1270
 
1259
- /* Remove an element if nested too deeply to avoid mXSS */
1260
- if (shadowNode.__depth >= MAX_NESTING_DEPTH) {
1271
+ /*
1272
+ * Remove an element if nested too deeply to avoid mXSS
1273
+ * or if the __depth might have been tampered with
1274
+ */
1275
+ if (shadowNode.__depth >= MAX_NESTING_DEPTH || numberIsNaN(shadowNode.__depth)) {
1261
1276
  _forceRemove(shadowNode);
1262
1277
  }
1263
1278
 
@@ -1393,22 +1408,26 @@ function createDOMPurify() {
1393
1408
  if (_sanitizeElements(currentNode)) {
1394
1409
  continue;
1395
1410
  }
1411
+ var parentNode = getParentNode(currentNode);
1396
1412
 
1397
1413
  /* Set the nesting depth of an element */
1398
1414
  if (currentNode.nodeType === 1) {
1399
- if (currentNode.parentNode && currentNode.parentNode.__depth) {
1415
+ if (parentNode && parentNode.__depth) {
1400
1416
  /*
1401
1417
  We want the depth of the node in the original tree, which can
1402
1418
  change when it's removed from its parent.
1403
1419
  */
1404
- currentNode.__depth = (currentNode.__removalCount || 0) + currentNode.parentNode.__depth + 1;
1420
+ currentNode.__depth = (currentNode.__removalCount || 0) + parentNode.__depth + 1;
1405
1421
  } else {
1406
1422
  currentNode.__depth = 1;
1407
1423
  }
1408
1424
  }
1409
1425
 
1410
- /* Remove an element if nested too deeply to avoid mXSS */
1411
- if (currentNode.__depth >= MAX_NESTING_DEPTH) {
1426
+ /*
1427
+ * Remove an element if nested too deeply to avoid mXSS
1428
+ * or if the __depth might have been tampered with
1429
+ */
1430
+ if (currentNode.__depth >= MAX_NESTING_DEPTH || numberIsNaN(currentNode.__depth)) {
1412
1431
  _forceRemove(currentNode);
1413
1432
  }
1414
1433