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.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 (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -116,6 +116,7 @@
116
116
  var stringTrim = unapply(String.prototype.trim);
117
117
  var regExpTest = unapply(RegExp.prototype.test);
118
118
  var typeErrorCreate = unconstruct(TypeError);
119
+ var numberIsNaN = unapply(Number.isNaN);
119
120
  function unapply(func) {
120
121
  return function (thisArg) {
121
122
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -287,7 +288,7 @@
287
288
  * Version label, exposed for easier checks
288
289
  * if DOMPurify is up to date or not
289
290
  */
290
- DOMPurify.version = '2.5.1';
291
+ DOMPurify.version = '2.5.3';
291
292
 
292
293
  /**
293
294
  * Array of elements that DOMPurify removed during sanitation.
@@ -677,7 +678,7 @@
677
678
  CONFIG = cfg;
678
679
  };
679
680
  var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
680
- var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']);
681
+ var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'annotation-xml']);
681
682
 
682
683
  // Certain elements are allowed in both SVG and HTML
683
684
  // namespace. We need to specify them explicitly
@@ -1069,7 +1070,7 @@
1069
1070
  // eslint-disable-next-line complexity
1070
1071
  var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1071
1072
  /* Make sure attribute cannot clobber */
1072
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1073
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement || value === '__depth' || value === '__removalCount')) {
1073
1074
  return false;
1074
1075
  }
1075
1076
 
@@ -1171,6 +1172,12 @@
1171
1172
  continue;
1172
1173
  }
1173
1174
 
1175
+ /* Work around a security issue with comments inside attributes */
1176
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
1177
+ _removeAttribute(name, currentNode);
1178
+ continue;
1179
+ }
1180
+
1174
1181
  /* Sanitize attribute content to be template-safe */
1175
1182
  if (SAFE_FOR_TEMPLATES) {
1176
1183
  value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
@@ -1221,7 +1228,11 @@
1221
1228
  /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1222
1229
  currentNode.setAttribute(name, value);
1223
1230
  }
1224
- arrayPop(DOMPurify.removed);
1231
+ if (_isClobbered(currentNode)) {
1232
+ _forceRemove(currentNode);
1233
+ } else {
1234
+ arrayPop(DOMPurify.removed);
1235
+ }
1225
1236
  } catch (_) {}
1226
1237
  }
1227
1238
 
@@ -1248,22 +1259,26 @@
1248
1259
  if (_sanitizeElements(shadowNode)) {
1249
1260
  continue;
1250
1261
  }
1262
+ var parentNode = getParentNode(shadowNode);
1251
1263
 
1252
1264
  /* Set the nesting depth of an element */
1253
1265
  if (shadowNode.nodeType === 1) {
1254
- if (shadowNode.parentNode && shadowNode.parentNode.__depth) {
1266
+ if (parentNode && parentNode.__depth) {
1255
1267
  /*
1256
1268
  We want the depth of the node in the original tree, which can
1257
1269
  change when it's removed from its parent.
1258
1270
  */
1259
- shadowNode.__depth = (shadowNode.__removalCount || 0) + shadowNode.parentNode.__depth + 1;
1271
+ shadowNode.__depth = (shadowNode.__removalCount || 0) + parentNode.__depth + 1;
1260
1272
  } else {
1261
1273
  shadowNode.__depth = 1;
1262
1274
  }
1263
1275
  }
1264
1276
 
1265
- /* Remove an element if nested too deeply to avoid mXSS */
1266
- if (shadowNode.__depth >= MAX_NESTING_DEPTH) {
1277
+ /*
1278
+ * Remove an element if nested too deeply to avoid mXSS
1279
+ * or if the __depth might have been tampered with
1280
+ */
1281
+ if (shadowNode.__depth >= MAX_NESTING_DEPTH || numberIsNaN(shadowNode.__depth)) {
1267
1282
  _forceRemove(shadowNode);
1268
1283
  }
1269
1284
 
@@ -1399,22 +1414,26 @@
1399
1414
  if (_sanitizeElements(currentNode)) {
1400
1415
  continue;
1401
1416
  }
1417
+ var parentNode = getParentNode(currentNode);
1402
1418
 
1403
1419
  /* Set the nesting depth of an element */
1404
1420
  if (currentNode.nodeType === 1) {
1405
- if (currentNode.parentNode && currentNode.parentNode.__depth) {
1421
+ if (parentNode && parentNode.__depth) {
1406
1422
  /*
1407
1423
  We want the depth of the node in the original tree, which can
1408
1424
  change when it's removed from its parent.
1409
1425
  */
1410
- currentNode.__depth = (currentNode.__removalCount || 0) + currentNode.parentNode.__depth + 1;
1426
+ currentNode.__depth = (currentNode.__removalCount || 0) + parentNode.__depth + 1;
1411
1427
  } else {
1412
1428
  currentNode.__depth = 1;
1413
1429
  }
1414
1430
  }
1415
1431
 
1416
- /* Remove an element if nested too deeply to avoid mXSS */
1417
- if (currentNode.__depth >= MAX_NESTING_DEPTH) {
1432
+ /*
1433
+ * Remove an element if nested too deeply to avoid mXSS
1434
+ * or if the __depth might have been tampered with
1435
+ */
1436
+ if (currentNode.__depth >= MAX_NESTING_DEPTH || numberIsNaN(currentNode.__depth)) {
1418
1437
  _forceRemove(currentNode);
1419
1438
  }
1420
1439