dompurify 2.5.2 → 2.5.4

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.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 */
1
+ /*! @license DOMPurify 2.5.4 | (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.4/LICENSE */
2
2
 
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -116,6 +116,10 @@
116
116
  var stringTrim = unapply(String.prototype.trim);
117
117
  var regExpTest = unapply(RegExp.prototype.test);
118
118
  var typeErrorCreate = unconstruct(TypeError);
119
+ function numberIsNaN(x) {
120
+ // eslint-disable-next-line unicorn/prefer-number-properties
121
+ return typeof x === 'number' && isNaN(x);
122
+ }
119
123
  function unapply(func) {
120
124
  return function (thisArg) {
121
125
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -287,7 +291,7 @@
287
291
  * Version label, exposed for easier checks
288
292
  * if DOMPurify is up to date or not
289
293
  */
290
- DOMPurify.version = '2.5.2';
294
+ DOMPurify.version = '2.5.4';
291
295
 
292
296
  /**
293
297
  * Array of elements that DOMPurify removed during sanitation.
@@ -1069,7 +1073,7 @@
1069
1073
  // eslint-disable-next-line complexity
1070
1074
  var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1071
1075
  /* Make sure attribute cannot clobber */
1072
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1076
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement || value === '__depth' || value === '__removalCount')) {
1073
1077
  return false;
1074
1078
  }
1075
1079
 
@@ -1171,6 +1175,12 @@
1171
1175
  continue;
1172
1176
  }
1173
1177
 
1178
+ /* Work around a security issue with comments inside attributes */
1179
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
1180
+ _removeAttribute(name, currentNode);
1181
+ continue;
1182
+ }
1183
+
1174
1184
  /* Sanitize attribute content to be template-safe */
1175
1185
  if (SAFE_FOR_TEMPLATES) {
1176
1186
  value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
@@ -1221,7 +1231,11 @@
1221
1231
  /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1222
1232
  currentNode.setAttribute(name, value);
1223
1233
  }
1224
- arrayPop(DOMPurify.removed);
1234
+ if (_isClobbered(currentNode)) {
1235
+ _forceRemove(currentNode);
1236
+ } else {
1237
+ arrayPop(DOMPurify.removed);
1238
+ }
1225
1239
  } catch (_) {}
1226
1240
  }
1227
1241
 
@@ -1263,8 +1277,11 @@
1263
1277
  }
1264
1278
  }
1265
1279
 
1266
- /* Remove an element if nested too deeply to avoid mXSS */
1267
- if (shadowNode.__depth >= MAX_NESTING_DEPTH) {
1280
+ /*
1281
+ * Remove an element if nested too deeply to avoid mXSS
1282
+ * or if the __depth might have been tampered with
1283
+ */
1284
+ if (shadowNode.__depth >= MAX_NESTING_DEPTH || numberIsNaN(shadowNode.__depth)) {
1268
1285
  _forceRemove(shadowNode);
1269
1286
  }
1270
1287
 
@@ -1415,8 +1432,11 @@
1415
1432
  }
1416
1433
  }
1417
1434
 
1418
- /* Remove an element if nested too deeply to avoid mXSS */
1419
- if (currentNode.__depth >= MAX_NESTING_DEPTH) {
1435
+ /*
1436
+ * Remove an element if nested too deeply to avoid mXSS
1437
+ * or if the __depth might have been tampered with
1438
+ */
1439
+ if (currentNode.__depth >= MAX_NESTING_DEPTH || numberIsNaN(currentNode.__depth)) {
1420
1440
  _forceRemove(currentNode);
1421
1441
  }
1422
1442