dompurify 2.3.12 → 2.4.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/dist/purify.es.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @license DOMPurify 2.3.12 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.12/LICENSE */
1
+ /*! @license DOMPurify 2.4.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.4.1/LICENSE */
2
2
 
3
3
  function _typeof(obj) {
4
4
  "@babel/helpers - typeof";
@@ -123,6 +123,7 @@ var arrayForEach = unapply(Array.prototype.forEach);
123
123
  var arrayPop = unapply(Array.prototype.pop);
124
124
  var arrayPush = unapply(Array.prototype.push);
125
125
  var stringToLowerCase = unapply(String.prototype.toLowerCase);
126
+ var stringToString = unapply(String.prototype.toString);
126
127
  var stringMatch = unapply(String.prototype.match);
127
128
  var stringReplace = unapply(String.prototype.replace);
128
129
  var stringIndexOf = unapply(String.prototype.indexOf);
@@ -249,6 +250,7 @@ var xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xli
249
250
  var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
250
251
 
251
252
  var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
253
+ var TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
252
254
  var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
253
255
 
254
256
  var ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
@@ -320,7 +322,7 @@ function createDOMPurify() {
320
322
  */
321
323
 
322
324
 
323
- DOMPurify.version = '2.3.12';
325
+ DOMPurify.version = '2.4.1';
324
326
  /**
325
327
  * Array of elements that DOMPurify removed during sanitation.
326
328
  * Empty if nothing was removed.
@@ -389,6 +391,7 @@ function createDOMPurify() {
389
391
  DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;
390
392
  var MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
391
393
  ERB_EXPR$1 = ERB_EXPR,
394
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
392
395
  DATA_ATTR$1 = DATA_ATTR,
393
396
  ARIA_ATTR$1 = ARIA_ATTR,
394
397
  IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
@@ -528,6 +531,10 @@ function createDOMPurify() {
528
531
 
529
532
  var NAMESPACE = HTML_NAMESPACE;
530
533
  var IS_EMPTY_INPUT = false;
534
+ /* Allowed XHTML+XML namespaces */
535
+
536
+ var ALLOWED_NAMESPACES = null;
537
+ var DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
531
538
  /* Parsing of strict XHTML documents */
532
539
 
533
540
  var PARSER_MEDIA_TYPE;
@@ -571,13 +578,12 @@ function createDOMPurify() {
571
578
  PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
572
579
  SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE; // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
573
580
 
574
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? function (x) {
575
- return x;
576
- } : stringToLowerCase;
581
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
577
582
  /* Set configuration parameters */
578
583
 
579
584
  ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
580
585
  ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
586
+ ALLOWED_NAMESPACES = 'ALLOWED_NAMESPACES' in cfg ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
581
587
  URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent
582
588
  cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent
583
589
  transformCaseFunc // eslint-disable-line indent
@@ -760,7 +766,7 @@ function createDOMPurify() {
760
766
 
761
767
  if (!parent || !parent.tagName) {
762
768
  parent = {
763
- namespaceURI: HTML_NAMESPACE,
769
+ namespaceURI: NAMESPACE,
764
770
  tagName: 'template'
765
771
  };
766
772
  }
@@ -768,13 +774,17 @@ function createDOMPurify() {
768
774
  var tagName = stringToLowerCase(element.tagName);
769
775
  var parentTagName = stringToLowerCase(parent.tagName);
770
776
 
777
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
778
+ return false;
779
+ }
780
+
771
781
  if (element.namespaceURI === SVG_NAMESPACE) {
772
782
  // The only way to switch from HTML namespace to SVG
773
783
  // is via <svg>. If it happens via any other tag, then
774
784
  // it should be killed.
775
785
  if (parent.namespaceURI === HTML_NAMESPACE) {
776
786
  return tagName === 'svg';
777
- } // The only way to switch from MathML to SVG is via
787
+ } // The only way to switch from MathML to SVG is via`
778
788
  // svg if parent is either <annotation-xml> or MathML
779
789
  // text integration points.
780
790
 
@@ -822,9 +832,15 @@ function createDOMPurify() {
822
832
 
823
833
 
824
834
  return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
835
+ } // For XHTML and XML documents that support custom namespaces
836
+
837
+
838
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
839
+ return true;
825
840
  } // The code should never reach this place (this means
826
841
  // that the element somehow got namespace that is not
827
- // HTML, SVG or MathML). Return false just in case.
842
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
843
+ // Return false just in case.
828
844
 
829
845
 
830
846
  return false;
@@ -908,7 +924,7 @@ function createDOMPurify() {
908
924
  leadingWhitespace = matches && matches[0];
909
925
  }
910
926
 
911
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml') {
927
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
912
928
  // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
913
929
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
914
930
  }
@@ -971,7 +987,7 @@ function createDOMPurify() {
971
987
 
972
988
 
973
989
  var _isClobbered = function _isClobbered(elm) {
974
- 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');
990
+ 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');
975
991
  };
976
992
  /**
977
993
  * _isNode
@@ -1113,6 +1129,7 @@ function createDOMPurify() {
1113
1129
  content = currentNode.textContent;
1114
1130
  content = stringReplace(content, MUSTACHE_EXPR$1, ' ');
1115
1131
  content = stringReplace(content, ERB_EXPR$1, ' ');
1132
+ content = stringReplace(content, TMPLIT_EXPR$1, ' ');
1116
1133
 
1117
1134
  if (currentNode.textContent !== content) {
1118
1135
  arrayPush(DOMPurify.removed, {
@@ -1261,6 +1278,7 @@ function createDOMPurify() {
1261
1278
  if (SAFE_FOR_TEMPLATES) {
1262
1279
  value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
1263
1280
  value = stringReplace(value, ERB_EXPR$1, ' ');
1281
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
1264
1282
  }
1265
1283
  /* Is `value` valid for this attribute? */
1266
1284
 
@@ -1556,6 +1574,7 @@ function createDOMPurify() {
1556
1574
  if (SAFE_FOR_TEMPLATES) {
1557
1575
  serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$1, ' ');
1558
1576
  serializedHTML = stringReplace(serializedHTML, ERB_EXPR$1, ' ');
1577
+ serializedHTML = stringReplace(serializedHTML, TMPLIT_EXPR$1, ' ');
1559
1578
  }
1560
1579
 
1561
1580
  return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;