igv 3.8.0 → 3.8.2

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/igv.esm.js CHANGED
@@ -10606,24 +10606,65 @@ function didSelectSingleTrackType(types) {
10606
10606
  return 1 === unique.length
10607
10607
  }
10608
10608
 
10609
- /*! @license DOMPurify 3.3.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.3/LICENSE */
10609
+ /*! @license DOMPurify 3.4.10 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.10/LICENSE */
10610
10610
 
10611
- const {
10612
- entries,
10613
- setPrototypeOf,
10614
- isFrozen,
10615
- getPrototypeOf,
10616
- getOwnPropertyDescriptor
10617
- } = Object;
10618
- let {
10619
- freeze,
10620
- seal,
10621
- create
10622
- } = Object; // eslint-disable-line import/no-mutable-exports
10623
- let {
10624
- apply,
10625
- construct
10626
- } = typeof Reflect !== 'undefined' && Reflect;
10611
+ function _arrayLikeToArray(r, a) {
10612
+ (null == a || a > r.length) && (a = r.length);
10613
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10614
+ return n;
10615
+ }
10616
+ function _arrayWithHoles(r) {
10617
+ if (Array.isArray(r)) return r;
10618
+ }
10619
+ function _iterableToArrayLimit(r, l) {
10620
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
10621
+ if (null != t) {
10622
+ var e,
10623
+ n,
10624
+ i,
10625
+ u,
10626
+ a = [],
10627
+ f = true,
10628
+ o = false;
10629
+ try {
10630
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
10631
+ } catch (r) {
10632
+ o = true, n = r;
10633
+ } finally {
10634
+ try {
10635
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
10636
+ } finally {
10637
+ if (o) throw n;
10638
+ }
10639
+ }
10640
+ return a;
10641
+ }
10642
+ }
10643
+ function _nonIterableRest() {
10644
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
10645
+ }
10646
+ function _slicedToArray(r, e) {
10647
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
10648
+ }
10649
+ function _unsupportedIterableToArray(r, a) {
10650
+ if (r) {
10651
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
10652
+ var t = {}.toString.call(r).slice(8, -1);
10653
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
10654
+ }
10655
+ }
10656
+
10657
+ const entries = Object.entries,
10658
+ setPrototypeOf = Object.setPrototypeOf,
10659
+ isFrozen = Object.isFrozen,
10660
+ getPrototypeOf = Object.getPrototypeOf,
10661
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
10662
+ let freeze = Object.freeze,
10663
+ seal = Object.seal,
10664
+ create = Object.create; // eslint-disable-line import/no-mutable-exports
10665
+ let _ref = typeof Reflect !== 'undefined' && Reflect,
10666
+ apply = _ref.apply,
10667
+ construct = _ref.construct;
10627
10668
  if (!freeze) {
10628
10669
  freeze = function freeze(x) {
10629
10670
  return x;
@@ -10655,13 +10696,19 @@ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
10655
10696
  const arrayPop = unapply(Array.prototype.pop);
10656
10697
  const arrayPush = unapply(Array.prototype.push);
10657
10698
  const arraySplice = unapply(Array.prototype.splice);
10699
+ const arrayIsArray = Array.isArray;
10658
10700
  const stringToLowerCase = unapply(String.prototype.toLowerCase);
10659
10701
  const stringToString = unapply(String.prototype.toString);
10660
10702
  const stringMatch = unapply(String.prototype.match);
10661
10703
  const stringReplace = unapply(String.prototype.replace);
10662
10704
  const stringIndexOf = unapply(String.prototype.indexOf);
10663
10705
  const stringTrim = unapply(String.prototype.trim);
10706
+ const numberToString = unapply(Number.prototype.toString);
10707
+ const booleanToString = unapply(Boolean.prototype.toString);
10708
+ const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
10709
+ const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
10664
10710
  const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
10711
+ const objectToString = unapply(Object.prototype.toString);
10665
10712
  const regExpTest = unapply(RegExp.prototype.test);
10666
10713
  const typeErrorCreate = unconstruct(TypeError);
10667
10714
  /**
@@ -10711,6 +10758,9 @@ function addToSet(set, array) {
10711
10758
  // Prevent prototype setters from intercepting set as a this value.
10712
10759
  setPrototypeOf(set, null);
10713
10760
  }
10761
+ if (!arrayIsArray(array)) {
10762
+ return set;
10763
+ }
10714
10764
  let l = array.length;
10715
10765
  while (l--) {
10716
10766
  let element = array[l];
@@ -10751,10 +10801,13 @@ function cleanArray(array) {
10751
10801
  */
10752
10802
  function clone(object) {
10753
10803
  const newObject = create(null);
10754
- for (const [property, value] of entries(object)) {
10804
+ for (const _ref2 of entries(object)) {
10805
+ var _ref3 = _slicedToArray(_ref2, 2);
10806
+ const property = _ref3[0];
10807
+ const value = _ref3[1];
10755
10808
  const isPropertyExist = objectHasOwnProperty(object, property);
10756
10809
  if (isPropertyExist) {
10757
- if (Array.isArray(value)) {
10810
+ if (arrayIsArray(value)) {
10758
10811
  newObject[property] = cleanArray(value);
10759
10812
  } else if (value && typeof value === 'object' && value.constructor === Object) {
10760
10813
  newObject[property] = clone(value);
@@ -10765,6 +10818,58 @@ function clone(object) {
10765
10818
  }
10766
10819
  return newObject;
10767
10820
  }
10821
+ /**
10822
+ * Convert non-node values into strings without depending on direct property access.
10823
+ *
10824
+ * @param value - The value to stringify.
10825
+ * @returns A string representation of the provided value.
10826
+ */
10827
+ function stringifyValue(value) {
10828
+ switch (typeof value) {
10829
+ case 'string':
10830
+ {
10831
+ return value;
10832
+ }
10833
+ case 'number':
10834
+ {
10835
+ return numberToString(value);
10836
+ }
10837
+ case 'boolean':
10838
+ {
10839
+ return booleanToString(value);
10840
+ }
10841
+ case 'bigint':
10842
+ {
10843
+ return bigintToString ? bigintToString(value) : '0';
10844
+ }
10845
+ case 'symbol':
10846
+ {
10847
+ return symbolToString ? symbolToString(value) : 'Symbol()';
10848
+ }
10849
+ case 'undefined':
10850
+ {
10851
+ return objectToString(value);
10852
+ }
10853
+ case 'function':
10854
+ case 'object':
10855
+ {
10856
+ if (value === null) {
10857
+ return objectToString(value);
10858
+ }
10859
+ const valueAsRecord = value;
10860
+ const valueToString = lookupGetter(valueAsRecord, 'toString');
10861
+ if (typeof valueToString === 'function') {
10862
+ const stringified = valueToString(valueAsRecord);
10863
+ return typeof stringified === 'string' ? stringified : objectToString(stringified);
10864
+ }
10865
+ return objectToString(value);
10866
+ }
10867
+ default:
10868
+ {
10869
+ return objectToString(value);
10870
+ }
10871
+ }
10872
+ }
10768
10873
  /**
10769
10874
  * This method automatically checks if the prop is function or getter and behaves accordingly.
10770
10875
  *
@@ -10790,6 +10895,14 @@ function lookupGetter(object, prop) {
10790
10895
  }
10791
10896
  return fallbackValue;
10792
10897
  }
10898
+ function isRegex(value) {
10899
+ try {
10900
+ regExpTest(value, '');
10901
+ return true;
10902
+ } catch (_unused) {
10903
+ return false;
10904
+ }
10905
+ }
10793
10906
 
10794
10907
  const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
10795
10908
  const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
@@ -10805,15 +10918,14 @@ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mgly
10805
10918
  const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
10806
10919
  const text = freeze(['#text']);
10807
10920
 
10808
- const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
10921
+ const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'command', 'commandfor', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns']);
10809
10922
  const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
10810
- const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
10923
+ const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lquote', 'lspace', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
10811
10924
  const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
10812
10925
 
10813
- // eslint-disable-next-line unicorn/better-regex
10814
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
10815
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
10816
- const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
10926
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
10927
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
10928
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
10817
10929
  const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
10818
10930
  const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
10819
10931
  const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
@@ -10823,20 +10935,13 @@ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205
10823
10935
  );
10824
10936
  const DOCTYPE_NAME = seal(/^html$/i);
10825
10937
  const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
10826
-
10827
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
10828
- __proto__: null,
10829
- ARIA_ATTR: ARIA_ATTR,
10830
- ATTR_WHITESPACE: ATTR_WHITESPACE,
10831
- CUSTOM_ELEMENT: CUSTOM_ELEMENT,
10832
- DATA_ATTR: DATA_ATTR,
10833
- DOCTYPE_NAME: DOCTYPE_NAME,
10834
- ERB_EXPR: ERB_EXPR,
10835
- IS_ALLOWED_URI: IS_ALLOWED_URI,
10836
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
10837
- MUSTACHE_EXPR: MUSTACHE_EXPR,
10838
- TMPLIT_EXPR: TMPLIT_EXPR
10839
- });
10938
+ // Markup-significant character probes used by _sanitizeElements.
10939
+ // Shared module-level instances are safe despite the sticky /g flags:
10940
+ // unapply() resets lastIndex for RegExp receivers before every call.
10941
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
10942
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
10943
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
10944
+ const SELF_CLOSING_TAG = seal(/\/>/i);
10840
10945
 
10841
10946
  /* eslint-disable @typescript-eslint/indent */
10842
10947
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
@@ -10849,7 +10954,7 @@ const NODE_TYPE = {
10849
10954
  // Deprecated
10850
10955
  entityNode: 6,
10851
10956
  // Deprecated
10852
- progressingInstruction: 7,
10957
+ processingInstruction: 7,
10853
10958
  comment: 8,
10854
10959
  document: 9,
10855
10960
  documentType: 10,
@@ -10910,10 +11015,25 @@ const _createHooksMap = function _createHooksMap() {
10910
11015
  uponSanitizeShadowNode: []
10911
11016
  };
10912
11017
  };
11018
+ /**
11019
+ * Resolve a set-valued configuration option: a fresh set built from
11020
+ * cfg[key] when it is an own array property (seeded with a clone of
11021
+ * options.base when given, case-normalized via options.transform),
11022
+ * the fallback set otherwise.
11023
+ *
11024
+ * @param cfg the cloned, prototype-free configuration object
11025
+ * @param key the configuration property to read
11026
+ * @param fallback the set to use when the option is absent or not an array
11027
+ * @param options transform and optional base set to merge into
11028
+ * @returns the resolved set
11029
+ */
11030
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
11031
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
11032
+ };
10913
11033
  function createDOMPurify() {
10914
11034
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
10915
11035
  const DOMPurify = root => createDOMPurify(root);
10916
- DOMPurify.version = '3.3.3';
11036
+ DOMPurify.version = '3.4.10';
10917
11037
  DOMPurify.removed = [];
10918
11038
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
10919
11039
  // Not running in a browser, provide a factory function
@@ -10921,28 +11041,29 @@ function createDOMPurify() {
10921
11041
  DOMPurify.isSupported = false;
10922
11042
  return DOMPurify;
10923
11043
  }
10924
- let {
10925
- document
10926
- } = window;
11044
+ let document = window.document;
10927
11045
  const originalDocument = document;
10928
11046
  const currentScript = originalDocument.currentScript;
10929
- const {
10930
- DocumentFragment,
10931
- HTMLTemplateElement,
10932
- Node,
10933
- Element,
10934
- NodeFilter,
10935
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
10936
- HTMLFormElement,
10937
- DOMParser,
10938
- trustedTypes
10939
- } = window;
11047
+ window.DocumentFragment;
11048
+ const HTMLTemplateElement = window.HTMLTemplateElement,
11049
+ Node = window.Node,
11050
+ Element = window.Element,
11051
+ NodeFilter = window.NodeFilter,
11052
+ _window$NamedNodeMap = window.NamedNodeMap;
11053
+ _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap;
11054
+ window.HTMLFormElement;
11055
+ const DOMParser = window.DOMParser,
11056
+ trustedTypes = window.trustedTypes;
10940
11057
  const ElementPrototype = Element.prototype;
10941
11058
  const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
10942
11059
  const remove = lookupGetter(ElementPrototype, 'remove');
10943
11060
  const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
10944
11061
  const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
10945
11062
  const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
11063
+ const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
11064
+ const getAttributes = lookupGetter(ElementPrototype, 'attributes');
11065
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
11066
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
10946
11067
  // As per issue #47, the web-components registry is inherited by a
10947
11068
  // new document created via createHTMLDocument. As per the spec
10948
11069
  // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
@@ -10957,33 +11078,74 @@ function createDOMPurify() {
10957
11078
  }
10958
11079
  let trustedTypesPolicy;
10959
11080
  let emptyHTML = '';
10960
- const {
10961
- implementation,
10962
- createNodeIterator,
10963
- createDocumentFragment,
10964
- getElementsByTagName
10965
- } = document;
10966
- const {
10967
- importNode
10968
- } = originalDocument;
11081
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
11082
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
11083
+ // on duplicate policy names — and is the only policy allowed to persist
11084
+ // across configurations and survive `clearConfig()`.
11085
+ let defaultTrustedTypesPolicy;
11086
+ let defaultTrustedTypesPolicyResolved = false;
11087
+ // Tracks whether we are already inside a call to the configured Trusted Types
11088
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
11089
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
11090
+ // re-enter the policy and recurse until the stack overflows. We detect that
11091
+ // re-entry and throw a clear, actionable error instead. The guard is shared
11092
+ // across both callbacks, because either one re-entering `sanitize` triggers
11093
+ // the same unbounded recursion.
11094
+ let IN_TRUSTED_TYPES_POLICY = 0;
11095
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
11096
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
11097
+ throw typeErrorCreate('A configured TRUSTED_TYPES_POLICY callback (createHTML or ' + 'createScriptURL) must not call DOMPurify.sanitize, as that causes ' + 'infinite recursion. Do not pass a policy whose callbacks wrap ' + 'DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted ' + 'Types" section of the README.');
11098
+ }
11099
+ };
11100
+ const _createTrustedHTML = function _createTrustedHTML(html) {
11101
+ _assertNotInTrustedTypesPolicy();
11102
+ IN_TRUSTED_TYPES_POLICY++;
11103
+ try {
11104
+ return trustedTypesPolicy.createHTML(html);
11105
+ } finally {
11106
+ IN_TRUSTED_TYPES_POLICY--;
11107
+ }
11108
+ };
11109
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
11110
+ _assertNotInTrustedTypesPolicy();
11111
+ IN_TRUSTED_TYPES_POLICY++;
11112
+ try {
11113
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
11114
+ } finally {
11115
+ IN_TRUSTED_TYPES_POLICY--;
11116
+ }
11117
+ };
11118
+ // Lazily resolve (and cache) the instance's internal default policy.
11119
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
11120
+ // repeated (Trusted Types throws on duplicate names), and a failed or
11121
+ // unsupported attempt must not be retried on every parse.
11122
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
11123
+ if (!defaultTrustedTypesPolicyResolved) {
11124
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
11125
+ defaultTrustedTypesPolicyResolved = true;
11126
+ }
11127
+ return defaultTrustedTypesPolicy;
11128
+ };
11129
+ const _document = document,
11130
+ implementation = _document.implementation,
11131
+ createNodeIterator = _document.createNodeIterator,
11132
+ createDocumentFragment = _document.createDocumentFragment,
11133
+ getElementsByTagName = _document.getElementsByTagName;
11134
+ const importNode = originalDocument.importNode;
10969
11135
  let hooks = _createHooksMap();
10970
11136
  /**
10971
11137
  * Expose whether this browser supports running the full DOMPurify.
10972
11138
  */
10973
11139
  DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
10974
- const {
10975
- MUSTACHE_EXPR,
10976
- ERB_EXPR,
10977
- TMPLIT_EXPR,
10978
- DATA_ATTR,
10979
- ARIA_ATTR,
10980
- IS_SCRIPT_OR_DATA,
10981
- ATTR_WHITESPACE,
10982
- CUSTOM_ELEMENT
10983
- } = EXPRESSIONS;
10984
- let {
10985
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
10986
- } = EXPRESSIONS;
11140
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
11141
+ ERB_EXPR$1 = ERB_EXPR,
11142
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
11143
+ DATA_ATTR$1 = DATA_ATTR,
11144
+ ARIA_ATTR$1 = ARIA_ATTR,
11145
+ IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
11146
+ ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
11147
+ CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
11148
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
10987
11149
  /**
10988
11150
  * We consider the elements and attributes below to be safe. Ideally
10989
11151
  * don't add any new ones but feel free to remove unwanted ones.
@@ -11102,7 +11264,17 @@ function createDOMPurify() {
11102
11264
  let USE_PROFILES = {};
11103
11265
  /* Tags to ignore content of when KEEP_CONTENT is true */
11104
11266
  let FORBID_CONTENTS = null;
11105
- const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
11267
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
11268
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
11269
+ // the UA (customizable <select>) — including any on* handlers — and the
11270
+ // engine re-mirrors synchronously whenever a removal changes which
11271
+ // option/selectedcontent is current, even inside DOMPurify's inert
11272
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
11273
+ // mirror target ahead of the walk, which the engine refills, looping
11274
+ // forever (DoS) and amplifying output. Dropping its content on removal
11275
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
11276
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
11277
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
11106
11278
  /* Tags that are safe for data: URIs */
11107
11279
  let DATA_URI_TAGS = null;
11108
11280
  const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
@@ -11118,8 +11290,10 @@ function createDOMPurify() {
11118
11290
  /* Allowed XHTML+XML namespaces */
11119
11291
  let ALLOWED_NAMESPACES = null;
11120
11292
  const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
11121
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
11122
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
11293
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
11294
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
11295
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
11296
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
11123
11297
  // Certain elements are allowed in both SVG and HTML
11124
11298
  // namespace. We need to specify them explicitly
11125
11299
  // so that they don't get erroneously deleted from
@@ -11161,15 +11335,33 @@ function createDOMPurify() {
11161
11335
  // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
11162
11336
  transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
11163
11337
  /* Set configuration parameters */
11164
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
11165
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
11166
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
11167
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
11168
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
11169
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
11170
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
11171
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
11172
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
11338
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
11339
+ transform: transformCaseFunc
11340
+ });
11341
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
11342
+ transform: transformCaseFunc
11343
+ });
11344
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
11345
+ transform: stringToString
11346
+ });
11347
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
11348
+ transform: transformCaseFunc,
11349
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
11350
+ });
11351
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
11352
+ transform: transformCaseFunc,
11353
+ base: DEFAULT_DATA_URI_TAGS
11354
+ });
11355
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
11356
+ transform: transformCaseFunc
11357
+ });
11358
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
11359
+ transform: transformCaseFunc
11360
+ });
11361
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
11362
+ transform: transformCaseFunc
11363
+ });
11364
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
11173
11365
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
11174
11366
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
11175
11367
  ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
@@ -11185,20 +11377,22 @@ function createDOMPurify() {
11185
11377
  SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
11186
11378
  KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
11187
11379
  IN_PLACE = cfg.IN_PLACE || false; // Default false
11188
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
11189
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
11190
- MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
11191
- HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
11192
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
11193
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
11194
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
11195
- }
11196
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
11197
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
11198
- }
11199
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
11200
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
11201
- }
11380
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
11381
+ NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
11382
+ MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS); // Default built-in map
11383
+ HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS); // Default built-in map
11384
+ const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
11385
+ CUSTOM_ELEMENT_HANDLING = create(null);
11386
+ if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
11387
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
11388
+ }
11389
+ if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
11390
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
11391
+ }
11392
+ if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
11393
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
11394
+ }
11395
+ seal(CUSTOM_ELEMENT_HANDLING);
11202
11396
  if (SAFE_FOR_TEMPLATES) {
11203
11397
  ALLOW_DATA_ATTR = false;
11204
11398
  }
@@ -11229,44 +11423,41 @@ function createDOMPurify() {
11229
11423
  addToSet(ALLOWED_ATTR, xml);
11230
11424
  }
11231
11425
  }
11232
- /* Prevent function-based ADD_ATTR / ADD_TAGS from leaking across calls */
11233
- if (!objectHasOwnProperty(cfg, 'ADD_TAGS')) {
11234
- EXTRA_ELEMENT_HANDLING.tagCheck = null;
11235
- }
11236
- if (!objectHasOwnProperty(cfg, 'ADD_ATTR')) {
11237
- EXTRA_ELEMENT_HANDLING.attributeCheck = null;
11238
- }
11426
+ /* Always reset function-based ADD_TAGS / ADD_ATTR checks to prevent
11427
+ * leaking across calls when switching from function to array config */
11428
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
11429
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
11239
11430
  /* Merge configuration parameters */
11240
- if (cfg.ADD_TAGS) {
11431
+ if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
11241
11432
  if (typeof cfg.ADD_TAGS === 'function') {
11242
11433
  EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
11243
- } else {
11434
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
11244
11435
  if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
11245
11436
  ALLOWED_TAGS = clone(ALLOWED_TAGS);
11246
11437
  }
11247
11438
  addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
11248
11439
  }
11249
11440
  }
11250
- if (cfg.ADD_ATTR) {
11441
+ if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
11251
11442
  if (typeof cfg.ADD_ATTR === 'function') {
11252
11443
  EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
11253
- } else {
11444
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
11254
11445
  if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
11255
11446
  ALLOWED_ATTR = clone(ALLOWED_ATTR);
11256
11447
  }
11257
11448
  addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
11258
11449
  }
11259
11450
  }
11260
- if (cfg.ADD_URI_SAFE_ATTR) {
11451
+ if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
11261
11452
  addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
11262
11453
  }
11263
- if (cfg.FORBID_CONTENTS) {
11454
+ if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
11264
11455
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
11265
11456
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
11266
11457
  }
11267
11458
  addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
11268
11459
  }
11269
- if (cfg.ADD_FORBID_CONTENTS) {
11460
+ if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
11270
11461
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
11271
11462
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
11272
11463
  }
@@ -11285,6 +11476,13 @@ function createDOMPurify() {
11285
11476
  addToSet(ALLOWED_TAGS, ['tbody']);
11286
11477
  delete FORBID_TAGS.tbody;
11287
11478
  }
11479
+ // Re-derive the active Trusted Types policy from this configuration on
11480
+ // every parse. The active policy must never be sticky closure state that
11481
+ // outlives the config that set it: a caller-supplied policy left in place
11482
+ // after `clearConfig()` — or after a later call that supplied none, or
11483
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
11484
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
11485
+ // See GHSA-vxr8-fq34-vvx9.
11288
11486
  if (cfg.TRUSTED_TYPES_POLICY) {
11289
11487
  if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
11290
11488
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
@@ -11292,20 +11490,62 @@ function createDOMPurify() {
11292
11490
  if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
11293
11491
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
11294
11492
  }
11295
- // Overwrite existing TrustedTypes policy.
11493
+ // A caller-supplied policy applies to this configuration only.
11494
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
11296
11495
  trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
11297
- // Sign local variables required by `sanitize`.
11298
- emptyHTML = trustedTypesPolicy.createHTML('');
11496
+ // Sign local variables required by `sanitize`. If the supplied policy's
11497
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
11498
+ // throws via the re-entrancy guard. Restore the previous policy first so
11499
+ // the instance is not left in a poisoned state. See #1422.
11500
+ try {
11501
+ emptyHTML = _createTrustedHTML('');
11502
+ } catch (error) {
11503
+ trustedTypesPolicy = previousTrustedTypesPolicy;
11504
+ throw error;
11505
+ }
11506
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
11507
+ // Explicit opt-out for this call: perform no Trusted Types signing and
11508
+ // create nothing (so a strict `trusted-types` CSP that disallows a
11509
+ // `dompurify` policy can still call `sanitize` from inside its own
11510
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
11511
+ // `null` also drops any previously retained caller policy, so it cannot
11512
+ // resurface on a later call, while still allowing the next config-less
11513
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
11514
+ trustedTypesPolicy = undefined;
11515
+ emptyHTML = '';
11299
11516
  } else {
11300
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
11517
+ // No policy supplied: keep the currently active policy if one is set — a
11518
+ // previously supplied policy is intentionally sticky across config-less
11519
+ // calls — otherwise fall back to the instance's own internal policy,
11520
+ // created at most once. (A policy supplied for a *single* call still
11521
+ // lingers by design; what must not linger is a policy whose configuration
11522
+ // has been torn down via `clearConfig()`, which restores the default.)
11301
11523
  if (trustedTypesPolicy === undefined) {
11302
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
11524
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
11303
11525
  }
11304
- // If creating the internal policy succeeded sign internal variables.
11305
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
11306
- emptyHTML = trustedTypesPolicy.createHTML('');
11526
+ // Sign internal variables only when a policy is active. A falsy policy
11527
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
11528
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
11529
+ // a non-policy and throw. See #1422.
11530
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
11531
+ emptyHTML = _createTrustedHTML('');
11307
11532
  }
11308
11533
  }
11534
+ /*
11535
+ * Mirror the clone-before-mutate pattern already applied above for
11536
+ * cfg.ADD_TAGS / cfg.ADD_ATTR: if any uponSanitize* hook is
11537
+ * registered AND the set still points at the default constant,
11538
+ * clone it. The hook then mutates the clone (in-call widening
11539
+ * still works exactly as documented) and the next default-cfg
11540
+ * call rebinds to the untouched original via the reassignment at
11541
+ * the top of this function.
11542
+ */
11543
+ if ((hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) && ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
11544
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
11545
+ }
11546
+ if (hooks.uponSanitizeAttribute.length > 0 && ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
11547
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
11548
+ }
11309
11549
  // Prevent further manipulation of configuration.
11310
11550
  // Not available in IE8, Safari 5, etc.
11311
11551
  if (freeze) {
@@ -11318,6 +11558,77 @@ function createDOMPurify() {
11318
11558
  * correctly. */
11319
11559
  const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
11320
11560
  const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
11561
+ /**
11562
+ * Namespace rules for an element in the SVG namespace.
11563
+ *
11564
+ * @param tagName the element's lowercase tag name
11565
+ * @param parent the (possibly simulated) parent node
11566
+ * @param parentTagName the parent's lowercase tag name
11567
+ * @returns true if a spec-compliant parser could produce this element
11568
+ */
11569
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
11570
+ // The only way to switch from HTML namespace to SVG
11571
+ // is via <svg>. If it happens via any other tag, then
11572
+ // it should be killed.
11573
+ if (parent.namespaceURI === HTML_NAMESPACE) {
11574
+ return tagName === 'svg';
11575
+ }
11576
+ // The only way to switch from MathML to SVG is via <svg>
11577
+ // if the parent is either <annotation-xml> or a MathML
11578
+ // text integration point.
11579
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
11580
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
11581
+ }
11582
+ // We only allow elements that are defined in SVG
11583
+ // spec. All others are disallowed in SVG namespace.
11584
+ return Boolean(ALL_SVG_TAGS[tagName]);
11585
+ };
11586
+ /**
11587
+ * Namespace rules for an element in the MathML namespace.
11588
+ *
11589
+ * @param tagName the element's lowercase tag name
11590
+ * @param parent the (possibly simulated) parent node
11591
+ * @param parentTagName the parent's lowercase tag name
11592
+ * @returns true if a spec-compliant parser could produce this element
11593
+ */
11594
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
11595
+ // The only way to switch from HTML namespace to MathML
11596
+ // is via <math>. If it happens via any other tag, then
11597
+ // it should be killed.
11598
+ if (parent.namespaceURI === HTML_NAMESPACE) {
11599
+ return tagName === 'math';
11600
+ }
11601
+ // The only way to switch from SVG to MathML is via
11602
+ // <math> and HTML integration points
11603
+ if (parent.namespaceURI === SVG_NAMESPACE) {
11604
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
11605
+ }
11606
+ // We only allow elements that are defined in MathML
11607
+ // spec. All others are disallowed in MathML namespace.
11608
+ return Boolean(ALL_MATHML_TAGS[tagName]);
11609
+ };
11610
+ /**
11611
+ * Namespace rules for an element in the HTML namespace.
11612
+ *
11613
+ * @param tagName the element's lowercase tag name
11614
+ * @param parent the (possibly simulated) parent node
11615
+ * @param parentTagName the parent's lowercase tag name
11616
+ * @returns true if a spec-compliant parser could produce this element
11617
+ */
11618
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
11619
+ // The only way to switch from SVG to HTML is via
11620
+ // HTML integration points, and from MathML to HTML
11621
+ // is via MathML text integration points
11622
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
11623
+ return false;
11624
+ }
11625
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
11626
+ return false;
11627
+ }
11628
+ // We disallow tags that are specific for MathML
11629
+ // or SVG and should never appear in HTML namespace
11630
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
11631
+ };
11321
11632
  /**
11322
11633
  * @param element a DOM element whose namespace is being checked
11323
11634
  * @returns Return false if the element has a
@@ -11340,51 +11651,13 @@ function createDOMPurify() {
11340
11651
  return false;
11341
11652
  }
11342
11653
  if (element.namespaceURI === SVG_NAMESPACE) {
11343
- // The only way to switch from HTML namespace to SVG
11344
- // is via <svg>. If it happens via any other tag, then
11345
- // it should be killed.
11346
- if (parent.namespaceURI === HTML_NAMESPACE) {
11347
- return tagName === 'svg';
11348
- }
11349
- // The only way to switch from MathML to SVG is via`
11350
- // svg if parent is either <annotation-xml> or MathML
11351
- // text integration points.
11352
- if (parent.namespaceURI === MATHML_NAMESPACE) {
11353
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
11354
- }
11355
- // We only allow elements that are defined in SVG
11356
- // spec. All others are disallowed in SVG namespace.
11357
- return Boolean(ALL_SVG_TAGS[tagName]);
11654
+ return _checkSvgNamespace(tagName, parent, parentTagName);
11358
11655
  }
11359
11656
  if (element.namespaceURI === MATHML_NAMESPACE) {
11360
- // The only way to switch from HTML namespace to MathML
11361
- // is via <math>. If it happens via any other tag, then
11362
- // it should be killed.
11363
- if (parent.namespaceURI === HTML_NAMESPACE) {
11364
- return tagName === 'math';
11365
- }
11366
- // The only way to switch from SVG to MathML is via
11367
- // <math> and HTML integration points
11368
- if (parent.namespaceURI === SVG_NAMESPACE) {
11369
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
11370
- }
11371
- // We only allow elements that are defined in MathML
11372
- // spec. All others are disallowed in MathML namespace.
11373
- return Boolean(ALL_MATHML_TAGS[tagName]);
11657
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
11374
11658
  }
11375
11659
  if (element.namespaceURI === HTML_NAMESPACE) {
11376
- // The only way to switch from SVG to HTML is via
11377
- // HTML integration points, and from MathML to HTML
11378
- // is via MathML text integration points
11379
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
11380
- return false;
11381
- }
11382
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
11383
- return false;
11384
- }
11385
- // We disallow tags that are specific for MathML
11386
- // or SVG and should never appear in HTML namespace
11387
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
11660
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
11388
11661
  }
11389
11662
  // For XHTML and XML documents that support custom namespaces
11390
11663
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
@@ -11409,7 +11682,74 @@ function createDOMPurify() {
11409
11682
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
11410
11683
  getParentNode(node).removeChild(node);
11411
11684
  } catch (_) {
11685
+ /* The normal detach failed — this is reached for a parentless node
11686
+ (getParentNode() is null, so .removeChild throws). Element.prototype
11687
+ .remove() is itself a spec no-op on a parentless node, so a recorded
11688
+ "removal" would otherwise hand the caller back an intact,
11689
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
11690
+ the style-with-element-child rule decided to kill). Fail closed by
11691
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
11692
+ rather than trying to "neutralize" the node via its own methods.
11693
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
11694
+ on the node, both of which a <form> root can clobber via a named child
11695
+ (and _isClobbered does not even probe getAttributeNames), so the
11696
+ neutralize step could itself be silently defeated, leaving the payload
11697
+ intact. A throw touches only the cached, clobber-safe remove() and
11698
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
11699
+ to every root-kill reason. REPORT-3.
11700
+ This lives inside the catch, so it never fires for a normally-removed
11701
+ in-tree node: those have a parent, removeChild() succeeds, and the
11702
+ catch is not entered. Only a kept (parentless) root reaches here. */
11412
11703
  remove(node);
11704
+ if (!getParentNode(node)) {
11705
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
11706
+ }
11707
+ }
11708
+ };
11709
+ /**
11710
+ * _neutralizeRoot
11711
+ *
11712
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
11713
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
11714
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
11715
+ * parentless guard throws, or any other re-entrant engine mutation — would
11716
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
11717
+ * after the abort point still carrying its handlers. There is no safe way
11718
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
11719
+ * remove every child and every attribute, then let the caller's catch see
11720
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
11721
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
11722
+ *
11723
+ * @param root the in-place root to empty
11724
+ */
11725
+ const _neutralizeRoot = function _neutralizeRoot(root) {
11726
+ const childNodes = getChildNodes(root);
11727
+ if (childNodes) {
11728
+ const snapshot = [];
11729
+ arrayForEach(childNodes, child => {
11730
+ arrayPush(snapshot, child);
11731
+ });
11732
+ arrayForEach(snapshot, child => {
11733
+ try {
11734
+ remove(child);
11735
+ } catch (_) {
11736
+ /* Best-effort teardown; a still-attached child is handled below */
11737
+ }
11738
+ });
11739
+ }
11740
+ const attributes = getAttributes(root);
11741
+ if (attributes) {
11742
+ for (let i = attributes.length - 1; i >= 0; --i) {
11743
+ const attribute = attributes[i];
11744
+ const name = attribute && attribute.name;
11745
+ if (typeof name === 'string') {
11746
+ try {
11747
+ root.removeAttribute(name);
11748
+ } catch (_) {
11749
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
11750
+ }
11751
+ }
11752
+ }
11413
11753
  }
11414
11754
  };
11415
11755
  /**
@@ -11444,6 +11784,72 @@ function createDOMPurify() {
11444
11784
  }
11445
11785
  }
11446
11786
  };
11787
+ /**
11788
+ * _stripDisallowedAttributes
11789
+ *
11790
+ * Removes every attribute the active configuration does not allow from a
11791
+ * single element, using the same allowlist as the main attribute pass (so
11792
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
11793
+ * neutralise nodes that are being discarded from an in-place tree.
11794
+ *
11795
+ * @param element the element to strip
11796
+ */
11797
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
11798
+ const attributes = getAttributes(element);
11799
+ if (!attributes) {
11800
+ return;
11801
+ }
11802
+ for (let i = attributes.length - 1; i >= 0; --i) {
11803
+ const attribute = attributes[i];
11804
+ const name = attribute && attribute.name;
11805
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
11806
+ continue;
11807
+ }
11808
+ try {
11809
+ element.removeAttribute(name);
11810
+ } catch (_) {
11811
+ /* Clobbered removeAttribute on a doomed node — ignore */
11812
+ }
11813
+ }
11814
+ };
11815
+ /**
11816
+ * _neutralizeSubtree
11817
+ *
11818
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
11819
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
11820
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
11821
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
11822
+ * those dropped nodes are detached from the caller's LIVE tree but a
11823
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
11824
+ * loading) keeps its queued resource event, which fires in page scope after
11825
+ * sanitize returns. This walks a removed subtree and strips every attribute
11826
+ * the active configuration does not allow — so `on*` handlers are cancelled
11827
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
11828
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
11829
+ * queued event can fire. Hook-free by design: these nodes leave the output,
11830
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
11831
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
11832
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
11833
+ * the `<img>`, are reached and scrubbed).
11834
+ *
11835
+ * @param root the root of a removed subtree to neutralise
11836
+ */
11837
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
11838
+ const stack = [root];
11839
+ while (stack.length > 0) {
11840
+ const node = stack.pop();
11841
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
11842
+ if (nodeType === NODE_TYPE.element) {
11843
+ _stripDisallowedAttributes(node);
11844
+ }
11845
+ const childNodes = getChildNodes(node);
11846
+ if (childNodes) {
11847
+ for (let i = childNodes.length - 1; i >= 0; --i) {
11848
+ stack.push(childNodes[i]);
11849
+ }
11850
+ }
11851
+ }
11852
+ };
11447
11853
  /**
11448
11854
  * _initDocument
11449
11855
  *
@@ -11465,7 +11871,7 @@ function createDOMPurify() {
11465
11871
  // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
11466
11872
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
11467
11873
  }
11468
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
11874
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
11469
11875
  /*
11470
11876
  * Use the DOMParser API by default, fallback later if needs be
11471
11877
  * DOMParser not work for svg when has multiple root element.
@@ -11505,29 +11911,254 @@ function createDOMPurify() {
11505
11911
  // eslint-disable-next-line no-bitwise
11506
11912
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
11507
11913
  };
11914
+ /**
11915
+ * Replace template expression syntax (mustache, ERB, template
11916
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
11917
+ * sites. Order matters: mustache, then ERB, then template literal.
11918
+ *
11919
+ * @param value the string to scrub
11920
+ * @returns the scrubbed string
11921
+ */
11922
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
11923
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
11924
+ value = stringReplace(value, ERB_EXPR$1, ' ');
11925
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
11926
+ return value;
11927
+ };
11928
+ /**
11929
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
11930
+ * character data of an element subtree. Used as the final safety net for
11931
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
11932
+ * which only form after text-node normalization (e.g. fragments split across
11933
+ * stripped elements) cannot survive into a template-evaluating framework.
11934
+ *
11935
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
11936
+ * in place rather than round-tripping through innerHTML. This preserves
11937
+ * descendant node references (important for IN_PLACE callers), avoids a
11938
+ * serialize/reparse cycle, and reads literal character data — which means
11939
+ * `<%...%>` in text content matches the ERB regex against its real bytes
11940
+ * instead of the HTML-entity-escaped form innerHTML would produce.
11941
+ *
11942
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
11943
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
11944
+ *
11945
+ * @param node The root element whose character data should be scrubbed.
11946
+ */
11947
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
11948
+ var _node$querySelectorAl;
11949
+ node.normalize();
11950
+ const walker = createNodeIterator.call(node.ownerDocument || node, node,
11951
+ // eslint-disable-next-line no-bitwise
11952
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
11953
+ let currentNode = walker.nextNode();
11954
+ while (currentNode) {
11955
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
11956
+ currentNode = walker.nextNode();
11957
+ }
11958
+ // NodeIterator does not descend into <template>.content per the DOM spec,
11959
+ // so we must explicitly recurse into each template's content fragment,
11960
+ // mirroring the approach used by _sanitizeShadowDOM.
11961
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
11962
+ if (templates) {
11963
+ arrayForEach(templates, tmpl => {
11964
+ if (_isDocumentFragment(tmpl.content)) {
11965
+ _scrubTemplateExpressions2(tmpl.content);
11966
+ }
11967
+ });
11968
+ }
11969
+ };
11508
11970
  /**
11509
11971
  * _isClobbered
11510
11972
  *
11973
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
11974
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
11975
+ * `name` attribute matching a prototype property shadows that property
11976
+ * on direct reads. We use this check at the IN_PLACE entry-point and
11977
+ * during attribute sanitization to refuse clobbered forms.
11978
+ *
11511
11979
  * @param element element to check for clobbering attacks
11512
11980
  * @return true if clobbered, false if safe
11513
11981
  */
11514
11982
  const _isClobbered = function _isClobbered(element) {
11515
- return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
11983
+ // Realm-independent tag-name probe. If we can't determine the tag
11984
+ // name at all, we can't reason about clobbering — return false
11985
+ // (the caller's other defences still apply).
11986
+ const realTagName = getNodeName ? getNodeName(element) : null;
11987
+ if (typeof realTagName !== 'string') {
11988
+ return false;
11989
+ }
11990
+ if (transformCaseFunc(realTagName) !== 'form') {
11991
+ return false;
11992
+ }
11993
+ return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
11994
+ // Realm-safe NamedNodeMap detection: equality against the cached
11995
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
11996
+ // makes the direct read diverge from the cached read; a clean form
11997
+ // (same-realm OR foreign-realm) has both reads pointing at the same
11998
+ // canonical NamedNodeMap.
11999
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
12000
+ // NodeType clobbering probe. Cached Node.prototype.nodeType getter
12001
+ // returns the integer 1 for any Element regardless of realm; direct
12002
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
12003
+ // the named child element. Cheap addition — nodeType is read from
12004
+ // an internal slot, no serialization cost — and removes a residual
12005
+ // clobbering surface used by several mXSS / PI / comment branches
12006
+ // in _sanitizeElements that compare currentNode.nodeType directly.
12007
+ element.nodeType !== getNodeType(element) ||
12008
+ // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
12009
+ // "childNodes" shadows the prototype getter. Direct reads of
12010
+ // form.childNodes from a clobbered form return the named child
12011
+ // instead of the real NodeList, so any walk that reads it directly
12012
+ // skips the form's real children. Compare the direct read to the
12013
+ // cached Node.prototype getter — when the form's named-property
12014
+ // getter intercepts the read, the two values differ and we flag
12015
+ // the form. This catches every clobbering child type (input,
12016
+ // select, etc.) regardless of whether the named child happens to
12017
+ // carry a numeric .length, which a typeof-based probe would miss
12018
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
12019
+ element.childNodes !== getChildNodes(element);
11516
12020
  };
11517
12021
  /**
11518
- * Checks whether the given object is a DOM node.
12022
+ * Checks whether the given value is a DocumentFragment from any realm.
12023
+ *
12024
+ * The realm-independent replacement reads `nodeType` through the cached
12025
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
12026
+ * constant (11). nodeType is a numeric value resolved from the node's
12027
+ * internal slot, identical across realms for the same kind of node.
12028
+ *
12029
+ * @param value object to check
12030
+ * @return true if value is a DocumentFragment-shaped node from any realm
12031
+ */
12032
+ const _isDocumentFragment = function _isDocumentFragment(value) {
12033
+ if (!getNodeType || typeof value !== 'object' || value === null) {
12034
+ return false;
12035
+ }
12036
+ try {
12037
+ return getNodeType(value) === NODE_TYPE.documentFragment;
12038
+ } catch (_) {
12039
+ return false;
12040
+ }
12041
+ };
12042
+ /**
12043
+ * Checks whether the given object is a DOM node, including nodes that
12044
+ * originate from a different window/realm (e.g. an iframe's
12045
+ * contentDocument). The previous `value instanceof Node` check was
12046
+ * realm-bound: nodes from a different window failed it, causing
12047
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
12048
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
11519
12049
  *
11520
12050
  * @param value object to check whether it's a DOM node
11521
- * @return true is object is a DOM node
12051
+ * @return true if value is a DOM node from any realm
11522
12052
  */
11523
12053
  const _isNode = function _isNode(value) {
11524
- return typeof Node === 'function' && value instanceof Node;
12054
+ if (!getNodeType || typeof value !== 'object' || value === null) {
12055
+ return false;
12056
+ }
12057
+ try {
12058
+ return typeof getNodeType(value) === 'number';
12059
+ } catch (_) {
12060
+ return false;
12061
+ }
11525
12062
  };
11526
12063
  function _executeHooks(hooks, currentNode, data) {
12064
+ if (hooks.length === 0) {
12065
+ return;
12066
+ }
11527
12067
  arrayForEach(hooks, hook => {
11528
12068
  hook.call(DOMPurify, currentNode, data, CONFIG);
11529
12069
  });
11530
12070
  }
12071
+ /**
12072
+ * Structural-threat checks that condemn a node regardless of the
12073
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
12074
+ * processing instructions, markup-bearing comments. Pure predicate;
12075
+ * the caller removes. Check order is load-bearing.
12076
+ *
12077
+ * @param currentNode the node to inspect
12078
+ * @param tagName the node's transformCaseFunc'd tag name
12079
+ * @return true if the node must be removed
12080
+ */
12081
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
12082
+ /* Detect mXSS attempts abusing namespace confusion */
12083
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
12084
+ return true;
12085
+ }
12086
+ /* Remove risky CSS construction leading to mXSS */
12087
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
12088
+ return true;
12089
+ }
12090
+ /* Remove any occurrence of processing instructions */
12091
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
12092
+ return true;
12093
+ }
12094
+ /* Remove any kind of possibly harmful comments */
12095
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
12096
+ return true;
12097
+ }
12098
+ return false;
12099
+ };
12100
+ /**
12101
+ * Handle a node whose tag is forbidden or not allowlisted: keep
12102
+ * allowed custom elements (false return exits _sanitizeElements
12103
+ * early - namespace/fallback checks and the afterSanitizeElements
12104
+ * hook are intentionally skipped for kept custom elements), else
12105
+ * hoist content per KEEP_CONTENT and remove.
12106
+ *
12107
+ * @param currentNode the disallowed node
12108
+ * @param tagName the node's transformCaseFunc'd tag name
12109
+ * @return true if the node was removed, false if kept
12110
+ */
12111
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
12112
+ /* Check if we have a custom element to handle */
12113
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
12114
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
12115
+ return false;
12116
+ }
12117
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
12118
+ return false;
12119
+ }
12120
+ }
12121
+ /* Keep content except for bad-listed elements.
12122
+ Use the cached prototype getters exclusively — the previous code
12123
+ had `|| currentNode.parentNode` / `|| currentNode.childNodes`
12124
+ fallbacks, but the cached getters always return the canonical
12125
+ value (or null for a real parent-less node), so the fallback
12126
+ path was dead in safe cases and a clobbering surface in unsafe
12127
+ ones. Falsy cached results stay falsy; the `if (childNodes &&
12128
+ parentNode)` check already gates correctly. */
12129
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
12130
+ const parentNode = getParentNode(currentNode);
12131
+ const childNodes = getChildNodes(currentNode);
12132
+ if (childNodes && parentNode) {
12133
+ const childCount = childNodes.length;
12134
+ /* In-place: hoist the *original* children so the iterator visits
12135
+ and sanitises them through the same allowlist pass as every other
12136
+ node. The caller built the tree in the live document, so the
12137
+ originals carry already-queued resource events (`<img onerror>`,
12138
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
12139
+ those originals detached but still armed, firing in page scope
12140
+ while the returned tree looked clean. Moving is safe in-place: the
12141
+ root is pre-validated as an allowed tag and so is never the node
12142
+ being removed, which keeps `parentNode` inside the iterator root
12143
+ and the relocated child inside the serialised tree.
12144
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
12145
+ at — and the result serialised from — `body`, so a restrictive
12146
+ ALLOWED_TAGS that removes `body` itself must leave its content in
12147
+ place, which only cloning does; and those paths parse into an
12148
+ inert document, so their discarded originals never had a queued
12149
+ event to neutralise.
12150
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
12151
+ valid whether we move (drops the trailing entry) or clone (leaves
12152
+ the list intact). */
12153
+ for (let i = childCount - 1; i >= 0; --i) {
12154
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
12155
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
12156
+ }
12157
+ }
12158
+ }
12159
+ _forceRemove(currentNode);
12160
+ return true;
12161
+ };
11531
12162
  /**
11532
12163
  * _sanitizeElements
11533
12164
  *
@@ -11538,7 +12169,6 @@ function createDOMPurify() {
11538
12169
  * @return true if node was killed, false if left alive
11539
12170
  */
11540
12171
  const _sanitizeElements = function _sanitizeElements(currentNode) {
11541
- let content = null;
11542
12172
  /* Execute a hook if present */
11543
12173
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
11544
12174
  /* Check if element is clobbered or can clobber */
@@ -11547,71 +12177,41 @@ function createDOMPurify() {
11547
12177
  return true;
11548
12178
  }
11549
12179
  /* Now let's check the element's type and name */
11550
- const tagName = transformCaseFunc(currentNode.nodeName);
12180
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
11551
12181
  /* Execute a hook if present */
11552
12182
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
11553
12183
  tagName,
11554
12184
  allowedTags: ALLOWED_TAGS
11555
12185
  });
11556
- /* Detect mXSS attempts abusing namespace confusion */
11557
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
11558
- _forceRemove(currentNode);
11559
- return true;
11560
- }
11561
- /* Remove any occurrence of processing instructions */
11562
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
11563
- _forceRemove(currentNode);
11564
- return true;
11565
- }
11566
- /* Remove any kind of possibly harmful comments */
11567
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
12186
+ /* Remove mXSS vectors, processing instructions and risky comments */
12187
+ if (_isUnsafeNode(currentNode, tagName)) {
11568
12188
  _forceRemove(currentNode);
11569
12189
  return true;
11570
12190
  }
11571
12191
  /* Remove element if anything forbids its presence */
11572
- if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
11573
- /* Check if we have a custom element to handle */
11574
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
11575
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
11576
- return false;
11577
- }
11578
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
11579
- return false;
11580
- }
11581
- }
11582
- /* Keep content except for bad-listed elements */
11583
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
11584
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
11585
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
11586
- if (childNodes && parentNode) {
11587
- const childCount = childNodes.length;
11588
- for (let i = childCount - 1; i >= 0; --i) {
11589
- const childClone = cloneNode(childNodes[i], true);
11590
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
11591
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
11592
- }
11593
- }
11594
- }
11595
- _forceRemove(currentNode);
11596
- return true;
11597
- }
11598
- /* Check whether element has a valid namespace */
11599
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
12192
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
12193
+ return _sanitizeDisallowedNode(currentNode, tagName);
12194
+ }
12195
+ /* Check whether element has a valid namespace.
12196
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
12197
+ nodeType getter rather than `instanceof Element`, which is realm-
12198
+ bound and short-circuits to false for any node minted in a different
12199
+ realm — letting a foreign-realm element with a forbidden namespace
12200
+ slip past the namespace check entirely. */
12201
+ const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
12202
+ if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
11600
12203
  _forceRemove(currentNode);
11601
12204
  return true;
11602
12205
  }
11603
12206
  /* Make sure that older browsers don't get fallback-tag mXSS */
11604
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
12207
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
11605
12208
  _forceRemove(currentNode);
11606
12209
  return true;
11607
12210
  }
11608
12211
  /* Sanitize element content to be template-safe */
11609
12212
  if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
11610
12213
  /* Get the element's text content */
11611
- content = currentNode.textContent;
11612
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
11613
- content = stringReplace(content, expr, ' ');
11614
- });
12214
+ const content = _stripTemplateExpressions(currentNode.textContent);
11615
12215
  if (currentNode.textContent !== content) {
11616
12216
  arrayPush(DOMPurify.removed, {
11617
12217
  element: currentNode.cloneNode()
@@ -11641,11 +12241,12 @@ function createDOMPurify() {
11641
12241
  if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
11642
12242
  return false;
11643
12243
  }
12244
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
11644
12245
  /* Allow valid data-* attributes: At least one character after "-"
11645
12246
  (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
11646
12247
  XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
11647
12248
  We don't need to check the value; it's always URI safe. */
11648
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
12249
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
11649
12250
  if (
11650
12251
  // First condition does a very basic check if a) it's basically a valid custom element tagname AND
11651
12252
  // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
@@ -11657,11 +12258,15 @@ function createDOMPurify() {
11657
12258
  return false;
11658
12259
  }
11659
12260
  /* Check value is safe. First, is attr inert? If so, is safe */
11660
- } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
12261
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if (value) {
11661
12262
  return false;
11662
12263
  } else ;
11663
12264
  return true;
11664
12265
  };
12266
+ /* Names the HTML spec reserves from valid-custom-element-name; these must
12267
+ * never be treated as basic custom elements even when a permissive
12268
+ * CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
12269
+ const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, ['annotation-xml', 'color-profile', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'missing-glyph']);
11665
12270
  /**
11666
12271
  * _isBasicCustomElement
11667
12272
  * checks if at least one dash is included in tagName, and it's not the first char
@@ -11671,7 +12276,64 @@ function createDOMPurify() {
11671
12276
  * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
11672
12277
  */
11673
12278
  const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
11674
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
12279
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
12280
+ };
12281
+ /**
12282
+ * Wrap an attribute value in the matching Trusted Types object when
12283
+ * the active policy requires it. Namespaced attributes pass through
12284
+ * unchanged (no TT support yet, see
12285
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
12286
+ *
12287
+ * @param lcTag lowercase tag name of the containing element
12288
+ * @param lcName lowercase attribute name
12289
+ * @param namespaceURI the attribute's namespace, if any
12290
+ * @param value the attribute value to wrap
12291
+ * @return the value, wrapped when Trusted Types demand it
12292
+ */
12293
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
12294
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
12295
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
12296
+ case 'TrustedHTML':
12297
+ {
12298
+ return _createTrustedHTML(value);
12299
+ }
12300
+ case 'TrustedScriptURL':
12301
+ {
12302
+ return _createTrustedScriptURL(value);
12303
+ }
12304
+ }
12305
+ }
12306
+ return value;
12307
+ };
12308
+ /**
12309
+ * Write a modified attribute value back onto the element. On
12310
+ * success, re-probe for clobbering introduced by the new value and
12311
+ * remove the element when found; otherwise pop the removal entry
12312
+ * recorded by the earlier _removeAttribute (long-standing pairing
12313
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
12314
+ * failure, remove the attribute instead.
12315
+ *
12316
+ * @param currentNode the element carrying the attribute
12317
+ * @param name the attribute name as present on the element
12318
+ * @param namespaceURI the attribute's namespace, if any
12319
+ * @param value the new attribute value
12320
+ */
12321
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
12322
+ try {
12323
+ if (namespaceURI) {
12324
+ currentNode.setAttributeNS(namespaceURI, name, value);
12325
+ } else {
12326
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
12327
+ currentNode.setAttribute(name, value);
12328
+ }
12329
+ if (_isClobbered(currentNode)) {
12330
+ _forceRemove(currentNode);
12331
+ } else {
12332
+ arrayPop(DOMPurify.removed);
12333
+ }
12334
+ } catch (_) {
12335
+ _removeAttribute(name, currentNode);
12336
+ }
11675
12337
  };
11676
12338
  /**
11677
12339
  * _sanitizeAttributes
@@ -11686,9 +12348,7 @@ function createDOMPurify() {
11686
12348
  const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
11687
12349
  /* Execute a hook if present */
11688
12350
  _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
11689
- const {
11690
- attributes
11691
- } = currentNode;
12351
+ const attributes = currentNode.attributes;
11692
12352
  /* Check if we have attributes; if not we might have a text node */
11693
12353
  if (!attributes || _isClobbered(currentNode)) {
11694
12354
  return;
@@ -11701,14 +12361,13 @@ function createDOMPurify() {
11701
12361
  forceKeepAttr: undefined
11702
12362
  };
11703
12363
  let l = attributes.length;
12364
+ const lcTag = transformCaseFunc(currentNode.nodeName);
11704
12365
  /* Go backwards over all attributes; safely remove bad ones */
11705
12366
  while (l--) {
11706
12367
  const attr = attributes[l];
11707
- const {
11708
- name,
11709
- namespaceURI,
11710
- value: attrValue
11711
- } = attr;
12368
+ const name = attr.name,
12369
+ namespaceURI = attr.namespaceURI,
12370
+ attrValue = attr.value;
11712
12371
  const lcName = transformCaseFunc(name);
11713
12372
  const initValue = attrValue;
11714
12373
  let value = name === 'value' ? initValue : stringTrim(initValue);
@@ -11722,12 +12381,14 @@ function createDOMPurify() {
11722
12381
  /* Full DOM Clobbering protection via namespace isolation,
11723
12382
  * Prefix id and name attributes with `user-content-`
11724
12383
  */
11725
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
12384
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
11726
12385
  // Remove the attribute with this value
11727
12386
  _removeAttribute(name, currentNode);
11728
12387
  // Prefix the value and later re-create the attribute with the sanitized value
11729
12388
  value = SANITIZE_NAMED_PROPS_PREFIX + value;
11730
12389
  }
12390
+ // Else: already prefixed, leave the attribute alone — the prefix is
12391
+ // itself the clobbering protection, and re-applying it is incorrect.
11731
12392
  /* Work around a security issue with comments inside attributes */
11732
12393
  if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
11733
12394
  _removeAttribute(name, currentNode);
@@ -11738,7 +12399,7 @@ function createDOMPurify() {
11738
12399
  _removeAttribute(name, currentNode);
11739
12400
  continue;
11740
12401
  }
11741
- /* Did the hooks approve of the attribute? */
12402
+ /* Did the hooks force-keep the attribute? */
11742
12403
  if (hookEvent.forceKeepAttr) {
11743
12404
  continue;
11744
12405
  }
@@ -11748,56 +12409,24 @@ function createDOMPurify() {
11748
12409
  continue;
11749
12410
  }
11750
12411
  /* Work around a security issue in jQuery 3.0 */
11751
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
12412
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
11752
12413
  _removeAttribute(name, currentNode);
11753
12414
  continue;
11754
12415
  }
11755
12416
  /* Sanitize attribute content to be template-safe */
11756
12417
  if (SAFE_FOR_TEMPLATES) {
11757
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
11758
- value = stringReplace(value, expr, ' ');
11759
- });
12418
+ value = _stripTemplateExpressions(value);
11760
12419
  }
11761
12420
  /* Is `value` valid for this attribute? */
11762
- const lcTag = transformCaseFunc(currentNode.nodeName);
11763
12421
  if (!_isValidAttribute(lcTag, lcName, value)) {
11764
12422
  _removeAttribute(name, currentNode);
11765
12423
  continue;
11766
12424
  }
11767
12425
  /* Handle attributes that require Trusted Types */
11768
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
11769
- if (namespaceURI) ; else {
11770
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
11771
- case 'TrustedHTML':
11772
- {
11773
- value = trustedTypesPolicy.createHTML(value);
11774
- break;
11775
- }
11776
- case 'TrustedScriptURL':
11777
- {
11778
- value = trustedTypesPolicy.createScriptURL(value);
11779
- break;
11780
- }
11781
- }
11782
- }
11783
- }
12426
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
11784
12427
  /* Handle invalid data-* attribute set by try-catching it */
11785
12428
  if (value !== initValue) {
11786
- try {
11787
- if (namespaceURI) {
11788
- currentNode.setAttributeNS(namespaceURI, name, value);
11789
- } else {
11790
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
11791
- currentNode.setAttribute(name, value);
11792
- }
11793
- if (_isClobbered(currentNode)) {
11794
- _forceRemove(currentNode);
11795
- } else {
11796
- arrayPop(DOMPurify.removed);
11797
- }
11798
- } catch (_) {
11799
- _removeAttribute(name, currentNode);
11800
- }
12429
+ _setAttributeValue(currentNode, name, namespaceURI, value);
11801
12430
  }
11802
12431
  }
11803
12432
  /* Execute a hook if present */
@@ -11808,7 +12437,7 @@ function createDOMPurify() {
11808
12437
  *
11809
12438
  * @param fragment to iterate over recursively
11810
12439
  */
11811
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
12440
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
11812
12441
  let shadowNode = null;
11813
12442
  const shadowIterator = _createNodeIterator(fragment);
11814
12443
  /* Execute a hook if present */
@@ -11820,14 +12449,133 @@ function createDOMPurify() {
11820
12449
  _sanitizeElements(shadowNode);
11821
12450
  /* Check attributes next */
11822
12451
  _sanitizeAttributes(shadowNode);
11823
- /* Deep shadow DOM detected */
11824
- if (shadowNode.content instanceof DocumentFragment) {
11825
- _sanitizeShadowDOM(shadowNode.content);
12452
+ /* Deep shadow DOM detected.
12453
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
12454
+ DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
12455
+ recurse into <template>.content from foreign realms too. */
12456
+ if (_isDocumentFragment(shadowNode.content)) {
12457
+ _sanitizeShadowDOM2(shadowNode.content);
12458
+ }
12459
+ /* An element iterated here may itself host an attached
12460
+ shadow root. The default NodeIterator does not enter shadow
12461
+ trees, so a shadow root nested inside template.content was
12462
+ previously reached by no walk at all (the pre-pass at
12463
+ _sanitizeAttachedShadowRoots descends via childNodes, which
12464
+ doesn't enter template.content; the template-content recursion
12465
+ above iterates the content but never inspected shadowRoot).
12466
+ Walk it explicitly. The nodeType guard avoids reading
12467
+ shadowRoot off text / comment / CDATA / PI nodes that the
12468
+ iterator also surfaces. */
12469
+ const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
12470
+ if (shadowNodeType === NODE_TYPE.element) {
12471
+ const innerSr = getShadowRoot(shadowNode);
12472
+ if (_isDocumentFragment(innerSr)) {
12473
+ _sanitizeAttachedShadowRoots(innerSr);
12474
+ _sanitizeShadowDOM2(innerSr);
12475
+ }
11826
12476
  }
11827
12477
  }
11828
12478
  /* Execute a hook if present */
11829
12479
  _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
11830
12480
  };
12481
+ /**
12482
+ * _sanitizeAttachedShadowRoots
12483
+ *
12484
+ * Walks `root` and feeds every attached shadow root we encounter into
12485
+ * the existing _sanitizeShadowDOM pipeline. The default node iterator
12486
+ * does not descend into shadow trees, so nodes inside an attached
12487
+ * shadow root would otherwise be skipped entirely.
12488
+ *
12489
+ * Two real input paths put attached shadow roots in front of us:
12490
+ * 1. IN_PLACE on a DOM node that already has shadow roots attached.
12491
+ * 2. DOM-node input where importNode(dirty, true) deep-clones the
12492
+ * shadow root because it was created with `clonable: true`.
12493
+ *
12494
+ * This pass runs once, up front, so the main iteration loop (and the
12495
+ * existing _sanitizeShadowDOM template-content recursion) stay
12496
+ * untouched — string-input paths are not affected.
12497
+ *
12498
+ * @param root the subtree root to walk for attached shadow roots
12499
+ */
12500
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
12501
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
12502
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
12503
+ built straight into the DOM — the IN_PLACE surface) deeper than the JS
12504
+ call-stack budget would otherwise overflow native recursion here and
12505
+ throw at the IN_PLACE entry pre-pass, before a single node is
12506
+ sanitized, leaving the caller's live tree untouched (fail-open). See
12507
+ campaign-3 F4. A heap stack keeps depth off the call stack.
12508
+ Each work item is either a node to descend into, or a deferred
12509
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
12510
+ form preserves the original post-order discipline: a shadow root's
12511
+ nested shadow roots are discovered before the outer shadow is
12512
+ sanitized (which may remove hosts). Pushes are in reverse of the
12513
+ desired processing order (LIFO): template content, then children, then
12514
+ the shadow-sanitize, then the shadow walk — so the order matches the
12515
+ previous recursion exactly. */
12516
+ const stack = [{
12517
+ node: root,
12518
+ shadow: null
12519
+ }];
12520
+ while (stack.length > 0) {
12521
+ const item = stack.pop();
12522
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
12523
+ if (item.shadow) {
12524
+ _sanitizeShadowDOM2(item.shadow);
12525
+ continue;
12526
+ }
12527
+ const node = item.node;
12528
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
12529
+ const isElement = nodeType === NODE_TYPE.element;
12530
+ /* (pushed last → processed first) Children, snapshotted in reverse so
12531
+ the first child is processed first. Snapshotting matters because a
12532
+ hook may detach siblings mid-walk. */
12533
+ const childNodes = getChildNodes(node);
12534
+ if (childNodes) {
12535
+ for (let i = childNodes.length - 1; i >= 0; --i) {
12536
+ stack.push({
12537
+ node: childNodes[i],
12538
+ shadow: null
12539
+ });
12540
+ }
12541
+ }
12542
+ /* (pushed before children → processed after them, matching the old
12543
+ "template content last" order) When the node is a <template>,
12544
+ descend into its content. */
12545
+ if (isElement) {
12546
+ const rootName = getNodeName ? getNodeName(node) : null;
12547
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
12548
+ const content = node.content;
12549
+ if (_isDocumentFragment(content)) {
12550
+ stack.push({
12551
+ node: content,
12552
+ shadow: null
12553
+ });
12554
+ }
12555
+ }
12556
+ }
12557
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
12558
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
12559
+ rather than `instanceof DocumentFragment`, which is realm-bound and
12560
+ silently skipped foreign-realm shadow roots (e.g.
12561
+ iframe.contentDocument attachShadow). */
12562
+ if (isElement) {
12563
+ const sr = getShadowRoot(node);
12564
+ if (_isDocumentFragment(sr)) {
12565
+ /* Push the deferred sanitise first so it pops after the shadow
12566
+ walk we push next, i.e. nested shadow roots are discovered
12567
+ before this one is sanitised. */
12568
+ stack.push({
12569
+ node: null,
12570
+ shadow: sr
12571
+ }, {
12572
+ node: sr,
12573
+ shadow: null
12574
+ });
12575
+ }
12576
+ }
12577
+ }
12578
+ };
11831
12579
  // eslint-disable-next-line complexity
11832
12580
  DOMPurify.sanitize = function (dirty) {
11833
12581
  let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -11844,13 +12592,9 @@ function createDOMPurify() {
11844
12592
  }
11845
12593
  /* Stringify, in case dirty is an object */
11846
12594
  if (typeof dirty !== 'string' && !_isNode(dirty)) {
11847
- if (typeof dirty.toString === 'function') {
11848
- dirty = dirty.toString();
11849
- if (typeof dirty !== 'string') {
11850
- throw typeErrorCreate('dirty is not a string, aborting');
11851
- }
11852
- } else {
11853
- throw typeErrorCreate('toString is not a function');
12595
+ dirty = stringifyValue(dirty);
12596
+ if (typeof dirty !== 'string') {
12597
+ throw typeErrorCreate('dirty is not a string, aborting');
11854
12598
  }
11855
12599
  }
11856
12600
  /* Return dirty HTML if DOMPurify cannot run */
@@ -11863,19 +12607,51 @@ function createDOMPurify() {
11863
12607
  }
11864
12608
  /* Clean up removed elements */
11865
12609
  DOMPurify.removed = [];
11866
- /* Check if dirty is correctly typed for IN_PLACE */
11867
- if (typeof dirty === 'string') {
11868
- IN_PLACE = false;
11869
- }
11870
- if (IN_PLACE) {
11871
- /* Do some early pre-sanitization to avoid unsafe root nodes */
11872
- if (dirty.nodeName) {
11873
- const tagName = transformCaseFunc(dirty.nodeName);
12610
+ /* Resolve IN_PLACE for this call without mutating persistent config.
12611
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
12612
+ where _parseConfig is skipped on later calls: a single string call would
12613
+ disable in-place mode for every subsequent node call, returning a
12614
+ sanitized copy while leaving the caller's node — which in-place callers
12615
+ keep using and whose return value they ignore unsanitized. REPORT-2. */
12616
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
12617
+ if (inPlace) {
12618
+ /* Do some early pre-sanitization to avoid unsafe root nodes.
12619
+ Read nodeName through the cached prototype getter — a clobbering
12620
+ child named "nodeName" on the form root would otherwise shadow
12621
+ the property and let this check skip the root-allowlist
12622
+ validation entirely. */
12623
+ const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
12624
+ if (typeof nn === 'string') {
12625
+ const tagName = transformCaseFunc(nn);
11874
12626
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
11875
12627
  throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
11876
12628
  }
11877
12629
  }
11878
- } else if (dirty instanceof Node) {
12630
+ /* Pre-flight the root through _isClobbered. The iterator-driven
12631
+ removal path can not detach a parent-less root: _forceRemove
12632
+ falls through to Element.prototype.remove(), which per spec
12633
+ is a no-op on a node with no parent. A clobbered root would
12634
+ then survive the main loop with its attributes uninspected,
12635
+ because _sanitizeAttributes early-returns on _isClobbered. The
12636
+ result would be an attacker-controlled form, complete with any
12637
+ event-handler attributes the caller passed in, handed back to
12638
+ the application unsanitized. Refuse to sanitize such a root
12639
+ the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
12640
+ if (_isClobbered(dirty)) {
12641
+ throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
12642
+ }
12643
+ /* Sanitize attached shadow roots before the main iterator runs.
12644
+ The iterator does not descend into shadow trees. Same fail-closed
12645
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
12646
+ inside a shadow root could abort this pre-pass before the walk runs,
12647
+ which would otherwise leave the entire live tree unsanitized. */
12648
+ try {
12649
+ _sanitizeAttachedShadowRoots(dirty);
12650
+ } catch (error) {
12651
+ _neutralizeRoot(dirty);
12652
+ throw error;
12653
+ }
12654
+ } else if (_isNode(dirty)) {
11879
12655
  /* If dirty is a DOM element, append to an empty document to avoid
11880
12656
  elements being stripped by the parser */
11881
12657
  body = _initDocument('<!---->');
@@ -11889,12 +12665,18 @@ function createDOMPurify() {
11889
12665
  // eslint-disable-next-line unicorn/prefer-dom-node-append
11890
12666
  body.appendChild(importedNode);
11891
12667
  }
12668
+ /* Clonable shadow roots are deep-cloned by importNode(); sanitize
12669
+ them before the main iterator runs, since the iterator does not
12670
+ descend into shadow trees. The walk routes every read through a
12671
+ cached prototype getter so clobbering descendants on a form root
12672
+ cannot hide a shadow host from this pass. */
12673
+ _sanitizeAttachedShadowRoots(importedNode);
11892
12674
  } else {
11893
12675
  /* Exit directly if we have nothing to do */
11894
12676
  if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
11895
12677
  // eslint-disable-next-line unicorn/prefer-includes
11896
12678
  dirty.indexOf('<') === -1) {
11897
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
12679
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
11898
12680
  }
11899
12681
  /* Initialize the document to work on */
11900
12682
  body = _initDocument(dirty);
@@ -11908,24 +12690,60 @@ function createDOMPurify() {
11908
12690
  _forceRemove(body.firstChild);
11909
12691
  }
11910
12692
  /* Get node iterator */
11911
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
11912
- /* Now start iterating over the created document */
11913
- while (currentNode = nodeIterator.nextNode()) {
11914
- /* Sanitize tags and elements */
11915
- _sanitizeElements(currentNode);
11916
- /* Check attributes next */
11917
- _sanitizeAttributes(currentNode);
11918
- /* Shadow DOM detected, sanitize it */
11919
- if (currentNode.content instanceof DocumentFragment) {
11920
- _sanitizeShadowDOM(currentNode.content);
12693
+ const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
12694
+ /* Now start iterating over the created document.
12695
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
12696
+ engine/custom-element mutation can detach a node mid-walk so
12697
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
12698
+ barrier the caller's in-place tree would be left half-sanitized with the
12699
+ unvisited tail still armed. On any throw we fail closed — strip the
12700
+ in-place root bare then rethrow so the existing throw contract is
12701
+ preserved. (String/DOM-copy paths never return the partial body, so the
12702
+ propagating throw is already fail-closed there.) */
12703
+ try {
12704
+ while (currentNode = nodeIterator.nextNode()) {
12705
+ /* Sanitize tags and elements */
12706
+ _sanitizeElements(currentNode);
12707
+ /* Check attributes next */
12708
+ _sanitizeAttributes(currentNode);
12709
+ /* Shadow DOM detected, sanitize it.
12710
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
12711
+ instead of instanceof, so foreign-realm <template>.content is
12712
+ walked correctly. */
12713
+ if (_isDocumentFragment(currentNode.content)) {
12714
+ _sanitizeShadowDOM2(currentNode.content);
12715
+ }
11921
12716
  }
12717
+ } catch (error) {
12718
+ if (inPlace) {
12719
+ _neutralizeRoot(dirty);
12720
+ }
12721
+ throw error;
11922
12722
  }
11923
12723
  /* If we sanitized `dirty` in-place, return it. */
11924
- if (IN_PLACE) {
12724
+ if (inPlace) {
12725
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
12726
+ the caller's live tree is detached but may still hold a queued
12727
+ resource-event handler that fires in page scope after we return. The
12728
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
12729
+ non-allow-listed attributes off every other removed subtree (clobber,
12730
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
12731
+ cancelled before any event can fire. Runs synchronously, pre-return. */
12732
+ arrayForEach(DOMPurify.removed, entry => {
12733
+ if (entry.element) {
12734
+ _neutralizeSubtree(entry.element);
12735
+ }
12736
+ });
12737
+ if (SAFE_FOR_TEMPLATES) {
12738
+ _scrubTemplateExpressions2(dirty);
12739
+ }
11925
12740
  return dirty;
11926
12741
  }
11927
12742
  /* Return sanitized string or DOM */
11928
12743
  if (RETURN_DOM) {
12744
+ if (SAFE_FOR_TEMPLATES) {
12745
+ _scrubTemplateExpressions2(body);
12746
+ }
11929
12747
  if (RETURN_DOM_FRAGMENT) {
11930
12748
  returnNode = createDocumentFragment.call(body.ownerDocument);
11931
12749
  while (body.firstChild) {
@@ -11954,11 +12772,9 @@ function createDOMPurify() {
11954
12772
  }
11955
12773
  /* Sanitize final string template-safe */
11956
12774
  if (SAFE_FOR_TEMPLATES) {
11957
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
11958
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
11959
- });
12775
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
11960
12776
  }
11961
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
12777
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
11962
12778
  };
11963
12779
  DOMPurify.setConfig = function () {
11964
12780
  let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -11968,6 +12784,12 @@ function createDOMPurify() {
11968
12784
  DOMPurify.clearConfig = function () {
11969
12785
  CONFIG = null;
11970
12786
  SET_CONFIG = false;
12787
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
12788
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
12789
+ // never recreated — Trusted Types throws on duplicate names) is restored by
12790
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
12791
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
12792
+ emptyHTML = '';
11971
12793
  };
11972
12794
  DOMPurify.isValidAttribute = function (tag, attr, value) {
11973
12795
  /* Initialize shared config vars if necessary. */
@@ -46226,6 +47048,7 @@ class WigTrack extends TrackBase {
46226
47048
  logScale: false,
46227
47049
  windowFunction: 'mean',
46228
47050
  graphType: 'bar',
47051
+ lineWidth: 2,
46229
47052
  normalize: undefined,
46230
47053
  scaleFactor: undefined,
46231
47054
  overflowColor: `rgb(255, 32, 255)`,
@@ -46277,6 +47100,8 @@ class WigTrack extends TrackBase {
46277
47100
  if ("heatmap" === config.graphType && !config.height) {
46278
47101
  this.height = 20;
46279
47102
  }
47103
+
47104
+ this.lineWidth = config.lineWidth || WigTrack.defaults.lineWidth; // Set lineWidth from config
46280
47105
  }
46281
47106
 
46282
47107
  async postInit() {
@@ -46498,11 +47323,11 @@ class WigTrack extends TrackBase {
46498
47323
  const color = options.alpha ? IGVColor.addAlpha(this.getColorForFeature(f), options.alpha) : this.getColorForFeature(f);
46499
47324
 
46500
47325
  if (this.graphType === "line") {
47326
+ const lineWidth = this.lineWidth;
47327
+ const properties = {"fillStyle": color, "strokeStyle": color, "lineWidth": lineWidth};
47328
+
46501
47329
  if (lastY !== undefined) {
46502
- IGVGraphics.strokeLine(ctx, lastPixelEnd, lastY, x, y, {
46503
- "fillStyle": color,
46504
- "strokeStyle": color
46505
- });
47330
+ IGVGraphics.strokeLine(ctx, lastPixelEnd, lastY, x, y, properties);
46506
47331
  }
46507
47332
  IGVGraphics.strokeLine(ctx, x, y, x + width, y, {"fillStyle": color, "strokeStyle": color});
46508
47333
  } else if (this.graphType === "points") {
@@ -76303,6 +77128,9 @@ class XMLSession {
76303
77128
  indexURL: r.getAttribute("index"),
76304
77129
  order: idx
76305
77130
  };
77131
+ if (r.hasAttribute("format")) {
77132
+ config.format = r.getAttribute("format");
77133
+ }
76306
77134
  resourceMap.set(config.url, config);
76307
77135
  if (!hasTrackElements) {
76308
77136
  tracks.push(config);
@@ -76390,6 +77218,13 @@ function extractTrackAttributes(track, config) {
76390
77218
 
76391
77219
  config.name = track.getAttribute("name");
76392
77220
 
77221
+ if(track.hasAttribute("type")) {
77222
+ config.type = track.getAttribute("type");
77223
+ }
77224
+ if(track.hasAttribute("format")) {
77225
+ config.format = track.getAttribute("format");
77226
+ }
77227
+
76393
77228
  const color = track.getAttribute("color");
76394
77229
  if (color) {
76395
77230
  config.color = "rgb(" + color + ")";
@@ -76701,7 +77536,7 @@ function createReferenceFrameList(loci, genome, browserFlanking, minimumBases, v
76701
77536
  })
76702
77537
  }
76703
77538
 
76704
- const _version = "3.8.0";
77539
+ const _version = "3.8.2";
76705
77540
  function version() {
76706
77541
  return _version
76707
77542
  }
@@ -78328,11 +79163,11 @@ class ROIMenu {
78328
79163
 
78329
79164
  }
78330
79165
 
78331
- function createRegionKey$1(chr, start, end) {
79166
+ function createRegionKey(chr, start, end) {
78332
79167
  return `${chr}-${start}-${end}`
78333
79168
  }
78334
79169
 
78335
- function parseRegionKey$1(regionKey) {
79170
+ function parseRegionKey(regionKey) {
78336
79171
  let regionParts = regionKey.split('-');
78337
79172
  let ee = parseInt(regionParts.pop());
78338
79173
  let ss = parseInt(regionParts.pop());
@@ -78362,7 +79197,7 @@ class ROITable extends RegionTableBase {
78362
79197
  const dom = div({ class: 'igv-roi-table-row' });
78363
79198
 
78364
79199
  const { setName, feature } = record;
78365
- dom.dataset.region = createRegionKey$1(feature.chr, feature.start, feature.end);
79200
+ dom.dataset.region = createRegionKey(feature.chr, feature.start, feature.end);
78366
79201
 
78367
79202
  let strings =
78368
79203
  [
@@ -78434,7 +79269,7 @@ class ROITable extends RegionTableBase {
78434
79269
 
78435
79270
  const loci = [];
78436
79271
  for (let el of selected) {
78437
- const { locus } = parseRegionKey$1(el.dataset.region);
79272
+ const { locus } = parseRegionKey(el.dataset.region);
78438
79273
  loci.push(locus);
78439
79274
  }
78440
79275
 
@@ -78488,7 +79323,7 @@ class ROITable extends RegionTableBase {
78488
79323
  const selected = this.tableDOM.querySelectorAll('.igv-roi-table-row-selected');
78489
79324
 
78490
79325
  if (selected.length > 0 && selected.length < 2) {
78491
- const { locus } = parseRegionKey$1(selected[ 0 ].dataset.region);
79326
+ const { locus } = parseRegionKey(selected[ 0 ].dataset.region);
78492
79327
  const { chr, start, end } = parseLocusString(locus, this.browser.isSoftclipped());
78493
79328
  enableButton(this.copySequenceButton, (end - start) < 1e6);
78494
79329
  } else {
@@ -78537,7 +79372,7 @@ class ROITable extends RegionTableBase {
78537
79372
  const selected = this.tableDOM.querySelectorAll('.igv-roi-table-row-selected');
78538
79373
  const loci = [];
78539
79374
  for (let el of selected) {
78540
- const { locus } = parseRegionKey$1(el.dataset.region);
79375
+ const { locus } = parseRegionKey(el.dataset.region);
78541
79376
  loci.push(locus);
78542
79377
  }
78543
79378