dompurify 2.3.5 → 2.3.6

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,7 +6,7 @@
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 2.3.5.
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 2.3.6.
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
 
@@ -185,6 +185,9 @@ var clean = DOMPurify.sanitize(dirty, {ADD_TAGS: ['my-tag']});
185
185
  // extend the existing array of allowed attributes and add my-attr to allow-list
186
186
  var clean = DOMPurify.sanitize(dirty, {ADD_ATTR: ['my-attr']});
187
187
 
188
+ // prohibit ARIA attributes, leave other safe HTML as is (default is true)
189
+ var clean = DOMPurify.sanitize(dirty, {ALLOW_ARIA_ATTR: false});
190
+
188
191
  // prohibit HTML5 data attributes, leave other safe HTML as is (default is true)
189
192
  var clean = DOMPurify.sanitize(dirty, {ALLOW_DATA_ATTR: false});
190
193
 
@@ -1,4 +1,4 @@
1
- /*! @license DOMPurify 2.3.5 | (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.5/LICENSE */
1
+ /*! @license DOMPurify 2.3.6 | (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.6/LICENSE */
2
2
 
3
3
  'use strict';
4
4
 
@@ -186,6 +186,7 @@ var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-
186
186
  var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
187
187
  var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
188
188
  );
189
+ var DOCTYPE_NAME = seal(/^html$/i);
189
190
 
190
191
  var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
191
192
 
@@ -245,7 +246,7 @@ function createDOMPurify() {
245
246
  * Version label, exposed for easier checks
246
247
  * if DOMPurify is up to date or not
247
248
  */
248
- DOMPurify.version = '2.3.5';
249
+ DOMPurify.version = '2.3.6';
249
250
 
250
251
  /**
251
252
  * Array of elements that DOMPurify removed during sanitation.
@@ -840,7 +841,9 @@ function createDOMPurify() {
840
841
  * @return {Iterator} iterator instance
841
842
  */
842
843
  var _createIterator = function _createIterator(root) {
843
- return createNodeIterator.call(root.ownerDocument || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
844
+ return createNodeIterator.call(root.ownerDocument || root, root,
845
+ // eslint-disable-next-line no-bitwise
846
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
844
847
  };
845
848
 
846
849
  /**
@@ -932,6 +935,12 @@ function createDOMPurify() {
932
935
 
933
936
  /* Remove element if anything forbids its presence */
934
937
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
938
+ /* Check if we have a custom element to handle */
939
+ if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
940
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
941
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
942
+ }
943
+
935
944
  /* Keep content except for bad-listed elements */
936
945
  if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
937
946
  var parentNode = getParentNode(currentNode) || currentNode.parentNode;
@@ -946,11 +955,6 @@ function createDOMPurify() {
946
955
  }
947
956
  }
948
957
 
949
- if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
950
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
951
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
952
- }
953
-
954
958
  _forceRemove(currentNode);
955
959
  return true;
956
960
  }
@@ -1334,6 +1338,11 @@ function createDOMPurify() {
1334
1338
 
1335
1339
  var serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1336
1340
 
1341
+ /* Serialize doctype if allowed */
1342
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1343
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1344
+ }
1345
+
1337
1346
  /* Sanitize final string template-safe */
1338
1347
  if (SAFE_FOR_TEMPLATES) {
1339
1348
  serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$$1, ' ');