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.js CHANGED
@@ -10612,24 +10612,65 @@
10612
10612
  return 1 === unique.length
10613
10613
  }
10614
10614
 
10615
- /*! @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 */
10615
+ /*! @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 */
10616
10616
 
10617
- const {
10618
- entries,
10619
- setPrototypeOf,
10620
- isFrozen,
10621
- getPrototypeOf,
10622
- getOwnPropertyDescriptor
10623
- } = Object;
10624
- let {
10625
- freeze,
10626
- seal,
10627
- create
10628
- } = Object; // eslint-disable-line import/no-mutable-exports
10629
- let {
10630
- apply,
10631
- construct
10632
- } = typeof Reflect !== 'undefined' && Reflect;
10617
+ function _arrayLikeToArray(r, a) {
10618
+ (null == a || a > r.length) && (a = r.length);
10619
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10620
+ return n;
10621
+ }
10622
+ function _arrayWithHoles(r) {
10623
+ if (Array.isArray(r)) return r;
10624
+ }
10625
+ function _iterableToArrayLimit(r, l) {
10626
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
10627
+ if (null != t) {
10628
+ var e,
10629
+ n,
10630
+ i,
10631
+ u,
10632
+ a = [],
10633
+ f = true,
10634
+ o = false;
10635
+ try {
10636
+ 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);
10637
+ } catch (r) {
10638
+ o = true, n = r;
10639
+ } finally {
10640
+ try {
10641
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
10642
+ } finally {
10643
+ if (o) throw n;
10644
+ }
10645
+ }
10646
+ return a;
10647
+ }
10648
+ }
10649
+ function _nonIterableRest() {
10650
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
10651
+ }
10652
+ function _slicedToArray(r, e) {
10653
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
10654
+ }
10655
+ function _unsupportedIterableToArray(r, a) {
10656
+ if (r) {
10657
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
10658
+ var t = {}.toString.call(r).slice(8, -1);
10659
+ 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;
10660
+ }
10661
+ }
10662
+
10663
+ const entries = Object.entries,
10664
+ setPrototypeOf = Object.setPrototypeOf,
10665
+ isFrozen = Object.isFrozen,
10666
+ getPrototypeOf = Object.getPrototypeOf,
10667
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
10668
+ let freeze = Object.freeze,
10669
+ seal = Object.seal,
10670
+ create = Object.create; // eslint-disable-line import/no-mutable-exports
10671
+ let _ref = typeof Reflect !== 'undefined' && Reflect,
10672
+ apply = _ref.apply,
10673
+ construct = _ref.construct;
10633
10674
  if (!freeze) {
10634
10675
  freeze = function freeze(x) {
10635
10676
  return x;
@@ -10661,13 +10702,19 @@
10661
10702
  const arrayPop = unapply(Array.prototype.pop);
10662
10703
  const arrayPush = unapply(Array.prototype.push);
10663
10704
  const arraySplice = unapply(Array.prototype.splice);
10705
+ const arrayIsArray = Array.isArray;
10664
10706
  const stringToLowerCase = unapply(String.prototype.toLowerCase);
10665
10707
  const stringToString = unapply(String.prototype.toString);
10666
10708
  const stringMatch = unapply(String.prototype.match);
10667
10709
  const stringReplace = unapply(String.prototype.replace);
10668
10710
  const stringIndexOf = unapply(String.prototype.indexOf);
10669
10711
  const stringTrim = unapply(String.prototype.trim);
10712
+ const numberToString = unapply(Number.prototype.toString);
10713
+ const booleanToString = unapply(Boolean.prototype.toString);
10714
+ const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
10715
+ const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
10670
10716
  const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
10717
+ const objectToString = unapply(Object.prototype.toString);
10671
10718
  const regExpTest = unapply(RegExp.prototype.test);
10672
10719
  const typeErrorCreate = unconstruct(TypeError);
10673
10720
  /**
@@ -10717,6 +10764,9 @@
10717
10764
  // Prevent prototype setters from intercepting set as a this value.
10718
10765
  setPrototypeOf(set, null);
10719
10766
  }
10767
+ if (!arrayIsArray(array)) {
10768
+ return set;
10769
+ }
10720
10770
  let l = array.length;
10721
10771
  while (l--) {
10722
10772
  let element = array[l];
@@ -10757,10 +10807,13 @@
10757
10807
  */
10758
10808
  function clone(object) {
10759
10809
  const newObject = create(null);
10760
- for (const [property, value] of entries(object)) {
10810
+ for (const _ref2 of entries(object)) {
10811
+ var _ref3 = _slicedToArray(_ref2, 2);
10812
+ const property = _ref3[0];
10813
+ const value = _ref3[1];
10761
10814
  const isPropertyExist = objectHasOwnProperty(object, property);
10762
10815
  if (isPropertyExist) {
10763
- if (Array.isArray(value)) {
10816
+ if (arrayIsArray(value)) {
10764
10817
  newObject[property] = cleanArray(value);
10765
10818
  } else if (value && typeof value === 'object' && value.constructor === Object) {
10766
10819
  newObject[property] = clone(value);
@@ -10771,6 +10824,58 @@
10771
10824
  }
10772
10825
  return newObject;
10773
10826
  }
10827
+ /**
10828
+ * Convert non-node values into strings without depending on direct property access.
10829
+ *
10830
+ * @param value - The value to stringify.
10831
+ * @returns A string representation of the provided value.
10832
+ */
10833
+ function stringifyValue(value) {
10834
+ switch (typeof value) {
10835
+ case 'string':
10836
+ {
10837
+ return value;
10838
+ }
10839
+ case 'number':
10840
+ {
10841
+ return numberToString(value);
10842
+ }
10843
+ case 'boolean':
10844
+ {
10845
+ return booleanToString(value);
10846
+ }
10847
+ case 'bigint':
10848
+ {
10849
+ return bigintToString ? bigintToString(value) : '0';
10850
+ }
10851
+ case 'symbol':
10852
+ {
10853
+ return symbolToString ? symbolToString(value) : 'Symbol()';
10854
+ }
10855
+ case 'undefined':
10856
+ {
10857
+ return objectToString(value);
10858
+ }
10859
+ case 'function':
10860
+ case 'object':
10861
+ {
10862
+ if (value === null) {
10863
+ return objectToString(value);
10864
+ }
10865
+ const valueAsRecord = value;
10866
+ const valueToString = lookupGetter(valueAsRecord, 'toString');
10867
+ if (typeof valueToString === 'function') {
10868
+ const stringified = valueToString(valueAsRecord);
10869
+ return typeof stringified === 'string' ? stringified : objectToString(stringified);
10870
+ }
10871
+ return objectToString(value);
10872
+ }
10873
+ default:
10874
+ {
10875
+ return objectToString(value);
10876
+ }
10877
+ }
10878
+ }
10774
10879
  /**
10775
10880
  * This method automatically checks if the prop is function or getter and behaves accordingly.
10776
10881
  *
@@ -10796,6 +10901,14 @@
10796
10901
  }
10797
10902
  return fallbackValue;
10798
10903
  }
10904
+ function isRegex(value) {
10905
+ try {
10906
+ regExpTest(value, '');
10907
+ return true;
10908
+ } catch (_unused) {
10909
+ return false;
10910
+ }
10911
+ }
10799
10912
 
10800
10913
  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']);
10801
10914
  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']);
@@ -10811,15 +10924,14 @@
10811
10924
  const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
10812
10925
  const text = freeze(['#text']);
10813
10926
 
10814
- 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']);
10927
+ 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']);
10815
10928
  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']);
10816
- 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']);
10929
+ 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']);
10817
10930
  const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
10818
10931
 
10819
- // eslint-disable-next-line unicorn/better-regex
10820
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
10821
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
10822
- const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
10932
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
10933
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
10934
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
10823
10935
  const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
10824
10936
  const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
10825
10937
  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
@@ -10829,20 +10941,13 @@
10829
10941
  );
10830
10942
  const DOCTYPE_NAME = seal(/^html$/i);
10831
10943
  const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
10832
-
10833
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
10834
- __proto__: null,
10835
- ARIA_ATTR: ARIA_ATTR,
10836
- ATTR_WHITESPACE: ATTR_WHITESPACE,
10837
- CUSTOM_ELEMENT: CUSTOM_ELEMENT,
10838
- DATA_ATTR: DATA_ATTR,
10839
- DOCTYPE_NAME: DOCTYPE_NAME,
10840
- ERB_EXPR: ERB_EXPR,
10841
- IS_ALLOWED_URI: IS_ALLOWED_URI,
10842
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
10843
- MUSTACHE_EXPR: MUSTACHE_EXPR,
10844
- TMPLIT_EXPR: TMPLIT_EXPR
10845
- });
10944
+ // Markup-significant character probes used by _sanitizeElements.
10945
+ // Shared module-level instances are safe despite the sticky /g flags:
10946
+ // unapply() resets lastIndex for RegExp receivers before every call.
10947
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
10948
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
10949
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
10950
+ const SELF_CLOSING_TAG = seal(/\/>/i);
10846
10951
 
10847
10952
  /* eslint-disable @typescript-eslint/indent */
10848
10953
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
@@ -10855,7 +10960,7 @@
10855
10960
  // Deprecated
10856
10961
  entityNode: 6,
10857
10962
  // Deprecated
10858
- progressingInstruction: 7,
10963
+ processingInstruction: 7,
10859
10964
  comment: 8,
10860
10965
  document: 9,
10861
10966
  documentType: 10,
@@ -10916,10 +11021,25 @@
10916
11021
  uponSanitizeShadowNode: []
10917
11022
  };
10918
11023
  };
11024
+ /**
11025
+ * Resolve a set-valued configuration option: a fresh set built from
11026
+ * cfg[key] when it is an own array property (seeded with a clone of
11027
+ * options.base when given, case-normalized via options.transform),
11028
+ * the fallback set otherwise.
11029
+ *
11030
+ * @param cfg the cloned, prototype-free configuration object
11031
+ * @param key the configuration property to read
11032
+ * @param fallback the set to use when the option is absent or not an array
11033
+ * @param options transform and optional base set to merge into
11034
+ * @returns the resolved set
11035
+ */
11036
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
11037
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
11038
+ };
10919
11039
  function createDOMPurify() {
10920
11040
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
10921
11041
  const DOMPurify = root => createDOMPurify(root);
10922
- DOMPurify.version = '3.3.3';
11042
+ DOMPurify.version = '3.4.10';
10923
11043
  DOMPurify.removed = [];
10924
11044
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
10925
11045
  // Not running in a browser, provide a factory function
@@ -10927,28 +11047,29 @@
10927
11047
  DOMPurify.isSupported = false;
10928
11048
  return DOMPurify;
10929
11049
  }
10930
- let {
10931
- document
10932
- } = window;
11050
+ let document = window.document;
10933
11051
  const originalDocument = document;
10934
11052
  const currentScript = originalDocument.currentScript;
10935
- const {
10936
- DocumentFragment,
10937
- HTMLTemplateElement,
10938
- Node,
10939
- Element,
10940
- NodeFilter,
10941
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
10942
- HTMLFormElement,
10943
- DOMParser,
10944
- trustedTypes
10945
- } = window;
11053
+ window.DocumentFragment;
11054
+ const HTMLTemplateElement = window.HTMLTemplateElement,
11055
+ Node = window.Node,
11056
+ Element = window.Element,
11057
+ NodeFilter = window.NodeFilter,
11058
+ _window$NamedNodeMap = window.NamedNodeMap;
11059
+ _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap;
11060
+ window.HTMLFormElement;
11061
+ const DOMParser = window.DOMParser,
11062
+ trustedTypes = window.trustedTypes;
10946
11063
  const ElementPrototype = Element.prototype;
10947
11064
  const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
10948
11065
  const remove = lookupGetter(ElementPrototype, 'remove');
10949
11066
  const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
10950
11067
  const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
10951
11068
  const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
11069
+ const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
11070
+ const getAttributes = lookupGetter(ElementPrototype, 'attributes');
11071
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
11072
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
10952
11073
  // As per issue #47, the web-components registry is inherited by a
10953
11074
  // new document created via createHTMLDocument. As per the spec
10954
11075
  // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
@@ -10963,33 +11084,74 @@
10963
11084
  }
10964
11085
  let trustedTypesPolicy;
10965
11086
  let emptyHTML = '';
10966
- const {
10967
- implementation,
10968
- createNodeIterator,
10969
- createDocumentFragment,
10970
- getElementsByTagName
10971
- } = document;
10972
- const {
10973
- importNode
10974
- } = originalDocument;
11087
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
11088
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
11089
+ // on duplicate policy names — and is the only policy allowed to persist
11090
+ // across configurations and survive `clearConfig()`.
11091
+ let defaultTrustedTypesPolicy;
11092
+ let defaultTrustedTypesPolicyResolved = false;
11093
+ // Tracks whether we are already inside a call to the configured Trusted Types
11094
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
11095
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
11096
+ // re-enter the policy and recurse until the stack overflows. We detect that
11097
+ // re-entry and throw a clear, actionable error instead. The guard is shared
11098
+ // across both callbacks, because either one re-entering `sanitize` triggers
11099
+ // the same unbounded recursion.
11100
+ let IN_TRUSTED_TYPES_POLICY = 0;
11101
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
11102
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
11103
+ 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.');
11104
+ }
11105
+ };
11106
+ const _createTrustedHTML = function _createTrustedHTML(html) {
11107
+ _assertNotInTrustedTypesPolicy();
11108
+ IN_TRUSTED_TYPES_POLICY++;
11109
+ try {
11110
+ return trustedTypesPolicy.createHTML(html);
11111
+ } finally {
11112
+ IN_TRUSTED_TYPES_POLICY--;
11113
+ }
11114
+ };
11115
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
11116
+ _assertNotInTrustedTypesPolicy();
11117
+ IN_TRUSTED_TYPES_POLICY++;
11118
+ try {
11119
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
11120
+ } finally {
11121
+ IN_TRUSTED_TYPES_POLICY--;
11122
+ }
11123
+ };
11124
+ // Lazily resolve (and cache) the instance's internal default policy.
11125
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
11126
+ // repeated (Trusted Types throws on duplicate names), and a failed or
11127
+ // unsupported attempt must not be retried on every parse.
11128
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
11129
+ if (!defaultTrustedTypesPolicyResolved) {
11130
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
11131
+ defaultTrustedTypesPolicyResolved = true;
11132
+ }
11133
+ return defaultTrustedTypesPolicy;
11134
+ };
11135
+ const _document = document,
11136
+ implementation = _document.implementation,
11137
+ createNodeIterator = _document.createNodeIterator,
11138
+ createDocumentFragment = _document.createDocumentFragment,
11139
+ getElementsByTagName = _document.getElementsByTagName;
11140
+ const importNode = originalDocument.importNode;
10975
11141
  let hooks = _createHooksMap();
10976
11142
  /**
10977
11143
  * Expose whether this browser supports running the full DOMPurify.
10978
11144
  */
10979
11145
  DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
10980
- const {
10981
- MUSTACHE_EXPR,
10982
- ERB_EXPR,
10983
- TMPLIT_EXPR,
10984
- DATA_ATTR,
10985
- ARIA_ATTR,
10986
- IS_SCRIPT_OR_DATA,
10987
- ATTR_WHITESPACE,
10988
- CUSTOM_ELEMENT
10989
- } = EXPRESSIONS;
10990
- let {
10991
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
10992
- } = EXPRESSIONS;
11146
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
11147
+ ERB_EXPR$1 = ERB_EXPR,
11148
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
11149
+ DATA_ATTR$1 = DATA_ATTR,
11150
+ ARIA_ATTR$1 = ARIA_ATTR,
11151
+ IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
11152
+ ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
11153
+ CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
11154
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
10993
11155
  /**
10994
11156
  * We consider the elements and attributes below to be safe. Ideally
10995
11157
  * don't add any new ones but feel free to remove unwanted ones.
@@ -11108,7 +11270,17 @@
11108
11270
  let USE_PROFILES = {};
11109
11271
  /* Tags to ignore content of when KEEP_CONTENT is true */
11110
11272
  let FORBID_CONTENTS = null;
11111
- 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']);
11273
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
11274
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
11275
+ // the UA (customizable <select>) — including any on* handlers — and the
11276
+ // engine re-mirrors synchronously whenever a removal changes which
11277
+ // option/selectedcontent is current, even inside DOMPurify's inert
11278
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
11279
+ // mirror target ahead of the walk, which the engine refills, looping
11280
+ // forever (DoS) and amplifying output. Dropping its content on removal
11281
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
11282
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
11283
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
11112
11284
  /* Tags that are safe for data: URIs */
11113
11285
  let DATA_URI_TAGS = null;
11114
11286
  const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
@@ -11124,8 +11296,10 @@
11124
11296
  /* Allowed XHTML+XML namespaces */
11125
11297
  let ALLOWED_NAMESPACES = null;
11126
11298
  const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
11127
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
11128
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
11299
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
11300
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
11301
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
11302
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
11129
11303
  // Certain elements are allowed in both SVG and HTML
11130
11304
  // namespace. We need to specify them explicitly
11131
11305
  // so that they don't get erroneously deleted from
@@ -11167,15 +11341,33 @@
11167
11341
  // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
11168
11342
  transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
11169
11343
  /* Set configuration parameters */
11170
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
11171
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
11172
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
11173
- 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;
11174
- 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;
11175
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
11176
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
11177
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
11178
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
11344
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
11345
+ transform: transformCaseFunc
11346
+ });
11347
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
11348
+ transform: transformCaseFunc
11349
+ });
11350
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
11351
+ transform: stringToString
11352
+ });
11353
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
11354
+ transform: transformCaseFunc,
11355
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
11356
+ });
11357
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
11358
+ transform: transformCaseFunc,
11359
+ base: DEFAULT_DATA_URI_TAGS
11360
+ });
11361
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
11362
+ transform: transformCaseFunc
11363
+ });
11364
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
11365
+ transform: transformCaseFunc
11366
+ });
11367
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
11368
+ transform: transformCaseFunc
11369
+ });
11370
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
11179
11371
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
11180
11372
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
11181
11373
  ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
@@ -11191,20 +11383,22 @@
11191
11383
  SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
11192
11384
  KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
11193
11385
  IN_PLACE = cfg.IN_PLACE || false; // Default false
11194
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
11195
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
11196
- MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
11197
- HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
11198
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
11199
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
11200
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
11201
- }
11202
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
11203
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
11204
- }
11205
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
11206
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
11207
- }
11386
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
11387
+ NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
11388
+ 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
11389
+ 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
11390
+ const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
11391
+ CUSTOM_ELEMENT_HANDLING = create(null);
11392
+ if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
11393
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
11394
+ }
11395
+ if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
11396
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
11397
+ }
11398
+ if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
11399
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
11400
+ }
11401
+ seal(CUSTOM_ELEMENT_HANDLING);
11208
11402
  if (SAFE_FOR_TEMPLATES) {
11209
11403
  ALLOW_DATA_ATTR = false;
11210
11404
  }
@@ -11235,44 +11429,41 @@
11235
11429
  addToSet(ALLOWED_ATTR, xml);
11236
11430
  }
11237
11431
  }
11238
- /* Prevent function-based ADD_ATTR / ADD_TAGS from leaking across calls */
11239
- if (!objectHasOwnProperty(cfg, 'ADD_TAGS')) {
11240
- EXTRA_ELEMENT_HANDLING.tagCheck = null;
11241
- }
11242
- if (!objectHasOwnProperty(cfg, 'ADD_ATTR')) {
11243
- EXTRA_ELEMENT_HANDLING.attributeCheck = null;
11244
- }
11432
+ /* Always reset function-based ADD_TAGS / ADD_ATTR checks to prevent
11433
+ * leaking across calls when switching from function to array config */
11434
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
11435
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
11245
11436
  /* Merge configuration parameters */
11246
- if (cfg.ADD_TAGS) {
11437
+ if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
11247
11438
  if (typeof cfg.ADD_TAGS === 'function') {
11248
11439
  EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
11249
- } else {
11440
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
11250
11441
  if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
11251
11442
  ALLOWED_TAGS = clone(ALLOWED_TAGS);
11252
11443
  }
11253
11444
  addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
11254
11445
  }
11255
11446
  }
11256
- if (cfg.ADD_ATTR) {
11447
+ if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
11257
11448
  if (typeof cfg.ADD_ATTR === 'function') {
11258
11449
  EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
11259
- } else {
11450
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
11260
11451
  if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
11261
11452
  ALLOWED_ATTR = clone(ALLOWED_ATTR);
11262
11453
  }
11263
11454
  addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
11264
11455
  }
11265
11456
  }
11266
- if (cfg.ADD_URI_SAFE_ATTR) {
11457
+ if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
11267
11458
  addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
11268
11459
  }
11269
- if (cfg.FORBID_CONTENTS) {
11460
+ if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
11270
11461
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
11271
11462
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
11272
11463
  }
11273
11464
  addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
11274
11465
  }
11275
- if (cfg.ADD_FORBID_CONTENTS) {
11466
+ if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
11276
11467
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
11277
11468
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
11278
11469
  }
@@ -11291,6 +11482,13 @@
11291
11482
  addToSet(ALLOWED_TAGS, ['tbody']);
11292
11483
  delete FORBID_TAGS.tbody;
11293
11484
  }
11485
+ // Re-derive the active Trusted Types policy from this configuration on
11486
+ // every parse. The active policy must never be sticky closure state that
11487
+ // outlives the config that set it: a caller-supplied policy left in place
11488
+ // after `clearConfig()` — or after a later call that supplied none, or
11489
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
11490
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
11491
+ // See GHSA-vxr8-fq34-vvx9.
11294
11492
  if (cfg.TRUSTED_TYPES_POLICY) {
11295
11493
  if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
11296
11494
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
@@ -11298,20 +11496,62 @@
11298
11496
  if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
11299
11497
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
11300
11498
  }
11301
- // Overwrite existing TrustedTypes policy.
11499
+ // A caller-supplied policy applies to this configuration only.
11500
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
11302
11501
  trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
11303
- // Sign local variables required by `sanitize`.
11304
- emptyHTML = trustedTypesPolicy.createHTML('');
11502
+ // Sign local variables required by `sanitize`. If the supplied policy's
11503
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
11504
+ // throws via the re-entrancy guard. Restore the previous policy first so
11505
+ // the instance is not left in a poisoned state. See #1422.
11506
+ try {
11507
+ emptyHTML = _createTrustedHTML('');
11508
+ } catch (error) {
11509
+ trustedTypesPolicy = previousTrustedTypesPolicy;
11510
+ throw error;
11511
+ }
11512
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
11513
+ // Explicit opt-out for this call: perform no Trusted Types signing and
11514
+ // create nothing (so a strict `trusted-types` CSP that disallows a
11515
+ // `dompurify` policy can still call `sanitize` from inside its own
11516
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
11517
+ // `null` also drops any previously retained caller policy, so it cannot
11518
+ // resurface on a later call, while still allowing the next config-less
11519
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
11520
+ trustedTypesPolicy = undefined;
11521
+ emptyHTML = '';
11305
11522
  } else {
11306
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
11523
+ // No policy supplied: keep the currently active policy if one is set — a
11524
+ // previously supplied policy is intentionally sticky across config-less
11525
+ // calls — otherwise fall back to the instance's own internal policy,
11526
+ // created at most once. (A policy supplied for a *single* call still
11527
+ // lingers by design; what must not linger is a policy whose configuration
11528
+ // has been torn down via `clearConfig()`, which restores the default.)
11307
11529
  if (trustedTypesPolicy === undefined) {
11308
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
11530
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
11309
11531
  }
11310
- // If creating the internal policy succeeded sign internal variables.
11311
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
11312
- emptyHTML = trustedTypesPolicy.createHTML('');
11532
+ // Sign internal variables only when a policy is active. A falsy policy
11533
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
11534
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
11535
+ // a non-policy and throw. See #1422.
11536
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
11537
+ emptyHTML = _createTrustedHTML('');
11313
11538
  }
11314
11539
  }
11540
+ /*
11541
+ * Mirror the clone-before-mutate pattern already applied above for
11542
+ * cfg.ADD_TAGS / cfg.ADD_ATTR: if any uponSanitize* hook is
11543
+ * registered AND the set still points at the default constant,
11544
+ * clone it. The hook then mutates the clone (in-call widening
11545
+ * still works exactly as documented) and the next default-cfg
11546
+ * call rebinds to the untouched original via the reassignment at
11547
+ * the top of this function.
11548
+ */
11549
+ if ((hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) && ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
11550
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
11551
+ }
11552
+ if (hooks.uponSanitizeAttribute.length > 0 && ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
11553
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
11554
+ }
11315
11555
  // Prevent further manipulation of configuration.
11316
11556
  // Not available in IE8, Safari 5, etc.
11317
11557
  if (freeze) {
@@ -11324,6 +11564,77 @@
11324
11564
  * correctly. */
11325
11565
  const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
11326
11566
  const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
11567
+ /**
11568
+ * Namespace rules for an element in the SVG namespace.
11569
+ *
11570
+ * @param tagName the element's lowercase tag name
11571
+ * @param parent the (possibly simulated) parent node
11572
+ * @param parentTagName the parent's lowercase tag name
11573
+ * @returns true if a spec-compliant parser could produce this element
11574
+ */
11575
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
11576
+ // The only way to switch from HTML namespace to SVG
11577
+ // is via <svg>. If it happens via any other tag, then
11578
+ // it should be killed.
11579
+ if (parent.namespaceURI === HTML_NAMESPACE) {
11580
+ return tagName === 'svg';
11581
+ }
11582
+ // The only way to switch from MathML to SVG is via <svg>
11583
+ // if the parent is either <annotation-xml> or a MathML
11584
+ // text integration point.
11585
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
11586
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
11587
+ }
11588
+ // We only allow elements that are defined in SVG
11589
+ // spec. All others are disallowed in SVG namespace.
11590
+ return Boolean(ALL_SVG_TAGS[tagName]);
11591
+ };
11592
+ /**
11593
+ * Namespace rules for an element in the MathML namespace.
11594
+ *
11595
+ * @param tagName the element's lowercase tag name
11596
+ * @param parent the (possibly simulated) parent node
11597
+ * @param parentTagName the parent's lowercase tag name
11598
+ * @returns true if a spec-compliant parser could produce this element
11599
+ */
11600
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
11601
+ // The only way to switch from HTML namespace to MathML
11602
+ // is via <math>. If it happens via any other tag, then
11603
+ // it should be killed.
11604
+ if (parent.namespaceURI === HTML_NAMESPACE) {
11605
+ return tagName === 'math';
11606
+ }
11607
+ // The only way to switch from SVG to MathML is via
11608
+ // <math> and HTML integration points
11609
+ if (parent.namespaceURI === SVG_NAMESPACE) {
11610
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
11611
+ }
11612
+ // We only allow elements that are defined in MathML
11613
+ // spec. All others are disallowed in MathML namespace.
11614
+ return Boolean(ALL_MATHML_TAGS[tagName]);
11615
+ };
11616
+ /**
11617
+ * Namespace rules for an element in the HTML namespace.
11618
+ *
11619
+ * @param tagName the element's lowercase tag name
11620
+ * @param parent the (possibly simulated) parent node
11621
+ * @param parentTagName the parent's lowercase tag name
11622
+ * @returns true if a spec-compliant parser could produce this element
11623
+ */
11624
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
11625
+ // The only way to switch from SVG to HTML is via
11626
+ // HTML integration points, and from MathML to HTML
11627
+ // is via MathML text integration points
11628
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
11629
+ return false;
11630
+ }
11631
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
11632
+ return false;
11633
+ }
11634
+ // We disallow tags that are specific for MathML
11635
+ // or SVG and should never appear in HTML namespace
11636
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
11637
+ };
11327
11638
  /**
11328
11639
  * @param element a DOM element whose namespace is being checked
11329
11640
  * @returns Return false if the element has a
@@ -11346,51 +11657,13 @@
11346
11657
  return false;
11347
11658
  }
11348
11659
  if (element.namespaceURI === SVG_NAMESPACE) {
11349
- // The only way to switch from HTML namespace to SVG
11350
- // is via <svg>. If it happens via any other tag, then
11351
- // it should be killed.
11352
- if (parent.namespaceURI === HTML_NAMESPACE) {
11353
- return tagName === 'svg';
11354
- }
11355
- // The only way to switch from MathML to SVG is via`
11356
- // svg if parent is either <annotation-xml> or MathML
11357
- // text integration points.
11358
- if (parent.namespaceURI === MATHML_NAMESPACE) {
11359
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
11360
- }
11361
- // We only allow elements that are defined in SVG
11362
- // spec. All others are disallowed in SVG namespace.
11363
- return Boolean(ALL_SVG_TAGS[tagName]);
11660
+ return _checkSvgNamespace(tagName, parent, parentTagName);
11364
11661
  }
11365
11662
  if (element.namespaceURI === MATHML_NAMESPACE) {
11366
- // The only way to switch from HTML namespace to MathML
11367
- // is via <math>. If it happens via any other tag, then
11368
- // it should be killed.
11369
- if (parent.namespaceURI === HTML_NAMESPACE) {
11370
- return tagName === 'math';
11371
- }
11372
- // The only way to switch from SVG to MathML is via
11373
- // <math> and HTML integration points
11374
- if (parent.namespaceURI === SVG_NAMESPACE) {
11375
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
11376
- }
11377
- // We only allow elements that are defined in MathML
11378
- // spec. All others are disallowed in MathML namespace.
11379
- return Boolean(ALL_MATHML_TAGS[tagName]);
11663
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
11380
11664
  }
11381
11665
  if (element.namespaceURI === HTML_NAMESPACE) {
11382
- // The only way to switch from SVG to HTML is via
11383
- // HTML integration points, and from MathML to HTML
11384
- // is via MathML text integration points
11385
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
11386
- return false;
11387
- }
11388
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
11389
- return false;
11390
- }
11391
- // We disallow tags that are specific for MathML
11392
- // or SVG and should never appear in HTML namespace
11393
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
11666
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
11394
11667
  }
11395
11668
  // For XHTML and XML documents that support custom namespaces
11396
11669
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
@@ -11415,7 +11688,74 @@
11415
11688
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
11416
11689
  getParentNode(node).removeChild(node);
11417
11690
  } catch (_) {
11691
+ /* The normal detach failed — this is reached for a parentless node
11692
+ (getParentNode() is null, so .removeChild throws). Element.prototype
11693
+ .remove() is itself a spec no-op on a parentless node, so a recorded
11694
+ "removal" would otherwise hand the caller back an intact,
11695
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
11696
+ the style-with-element-child rule decided to kill). Fail closed by
11697
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
11698
+ rather than trying to "neutralize" the node via its own methods.
11699
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
11700
+ on the node, both of which a <form> root can clobber via a named child
11701
+ (and _isClobbered does not even probe getAttributeNames), so the
11702
+ neutralize step could itself be silently defeated, leaving the payload
11703
+ intact. A throw touches only the cached, clobber-safe remove() and
11704
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
11705
+ to every root-kill reason. REPORT-3.
11706
+ This lives inside the catch, so it never fires for a normally-removed
11707
+ in-tree node: those have a parent, removeChild() succeeds, and the
11708
+ catch is not entered. Only a kept (parentless) root reaches here. */
11418
11709
  remove(node);
11710
+ if (!getParentNode(node)) {
11711
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
11712
+ }
11713
+ }
11714
+ };
11715
+ /**
11716
+ * _neutralizeRoot
11717
+ *
11718
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
11719
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
11720
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
11721
+ * parentless guard throws, or any other re-entrant engine mutation — would
11722
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
11723
+ * after the abort point still carrying its handlers. There is no safe way
11724
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
11725
+ * remove every child and every attribute, then let the caller's catch see
11726
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
11727
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
11728
+ *
11729
+ * @param root the in-place root to empty
11730
+ */
11731
+ const _neutralizeRoot = function _neutralizeRoot(root) {
11732
+ const childNodes = getChildNodes(root);
11733
+ if (childNodes) {
11734
+ const snapshot = [];
11735
+ arrayForEach(childNodes, child => {
11736
+ arrayPush(snapshot, child);
11737
+ });
11738
+ arrayForEach(snapshot, child => {
11739
+ try {
11740
+ remove(child);
11741
+ } catch (_) {
11742
+ /* Best-effort teardown; a still-attached child is handled below */
11743
+ }
11744
+ });
11745
+ }
11746
+ const attributes = getAttributes(root);
11747
+ if (attributes) {
11748
+ for (let i = attributes.length - 1; i >= 0; --i) {
11749
+ const attribute = attributes[i];
11750
+ const name = attribute && attribute.name;
11751
+ if (typeof name === 'string') {
11752
+ try {
11753
+ root.removeAttribute(name);
11754
+ } catch (_) {
11755
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
11756
+ }
11757
+ }
11758
+ }
11419
11759
  }
11420
11760
  };
11421
11761
  /**
@@ -11450,6 +11790,72 @@
11450
11790
  }
11451
11791
  }
11452
11792
  };
11793
+ /**
11794
+ * _stripDisallowedAttributes
11795
+ *
11796
+ * Removes every attribute the active configuration does not allow from a
11797
+ * single element, using the same allowlist as the main attribute pass (so
11798
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
11799
+ * neutralise nodes that are being discarded from an in-place tree.
11800
+ *
11801
+ * @param element the element to strip
11802
+ */
11803
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
11804
+ const attributes = getAttributes(element);
11805
+ if (!attributes) {
11806
+ return;
11807
+ }
11808
+ for (let i = attributes.length - 1; i >= 0; --i) {
11809
+ const attribute = attributes[i];
11810
+ const name = attribute && attribute.name;
11811
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
11812
+ continue;
11813
+ }
11814
+ try {
11815
+ element.removeAttribute(name);
11816
+ } catch (_) {
11817
+ /* Clobbered removeAttribute on a doomed node — ignore */
11818
+ }
11819
+ }
11820
+ };
11821
+ /**
11822
+ * _neutralizeSubtree
11823
+ *
11824
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
11825
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
11826
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
11827
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
11828
+ * those dropped nodes are detached from the caller's LIVE tree but a
11829
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
11830
+ * loading) keeps its queued resource event, which fires in page scope after
11831
+ * sanitize returns. This walks a removed subtree and strips every attribute
11832
+ * the active configuration does not allow — so `on*` handlers are cancelled
11833
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
11834
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
11835
+ * queued event can fire. Hook-free by design: these nodes leave the output,
11836
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
11837
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
11838
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
11839
+ * the `<img>`, are reached and scrubbed).
11840
+ *
11841
+ * @param root the root of a removed subtree to neutralise
11842
+ */
11843
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
11844
+ const stack = [root];
11845
+ while (stack.length > 0) {
11846
+ const node = stack.pop();
11847
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
11848
+ if (nodeType === NODE_TYPE.element) {
11849
+ _stripDisallowedAttributes(node);
11850
+ }
11851
+ const childNodes = getChildNodes(node);
11852
+ if (childNodes) {
11853
+ for (let i = childNodes.length - 1; i >= 0; --i) {
11854
+ stack.push(childNodes[i]);
11855
+ }
11856
+ }
11857
+ }
11858
+ };
11453
11859
  /**
11454
11860
  * _initDocument
11455
11861
  *
@@ -11471,7 +11877,7 @@
11471
11877
  // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
11472
11878
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
11473
11879
  }
11474
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
11880
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
11475
11881
  /*
11476
11882
  * Use the DOMParser API by default, fallback later if needs be
11477
11883
  * DOMParser not work for svg when has multiple root element.
@@ -11511,29 +11917,254 @@
11511
11917
  // eslint-disable-next-line no-bitwise
11512
11918
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
11513
11919
  };
11920
+ /**
11921
+ * Replace template expression syntax (mustache, ERB, template
11922
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
11923
+ * sites. Order matters: mustache, then ERB, then template literal.
11924
+ *
11925
+ * @param value the string to scrub
11926
+ * @returns the scrubbed string
11927
+ */
11928
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
11929
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
11930
+ value = stringReplace(value, ERB_EXPR$1, ' ');
11931
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
11932
+ return value;
11933
+ };
11934
+ /**
11935
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
11936
+ * character data of an element subtree. Used as the final safety net for
11937
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
11938
+ * which only form after text-node normalization (e.g. fragments split across
11939
+ * stripped elements) cannot survive into a template-evaluating framework.
11940
+ *
11941
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
11942
+ * in place rather than round-tripping through innerHTML. This preserves
11943
+ * descendant node references (important for IN_PLACE callers), avoids a
11944
+ * serialize/reparse cycle, and reads literal character data — which means
11945
+ * `<%...%>` in text content matches the ERB regex against its real bytes
11946
+ * instead of the HTML-entity-escaped form innerHTML would produce.
11947
+ *
11948
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
11949
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
11950
+ *
11951
+ * @param node The root element whose character data should be scrubbed.
11952
+ */
11953
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
11954
+ var _node$querySelectorAl;
11955
+ node.normalize();
11956
+ const walker = createNodeIterator.call(node.ownerDocument || node, node,
11957
+ // eslint-disable-next-line no-bitwise
11958
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
11959
+ let currentNode = walker.nextNode();
11960
+ while (currentNode) {
11961
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
11962
+ currentNode = walker.nextNode();
11963
+ }
11964
+ // NodeIterator does not descend into <template>.content per the DOM spec,
11965
+ // so we must explicitly recurse into each template's content fragment,
11966
+ // mirroring the approach used by _sanitizeShadowDOM.
11967
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
11968
+ if (templates) {
11969
+ arrayForEach(templates, tmpl => {
11970
+ if (_isDocumentFragment(tmpl.content)) {
11971
+ _scrubTemplateExpressions2(tmpl.content);
11972
+ }
11973
+ });
11974
+ }
11975
+ };
11514
11976
  /**
11515
11977
  * _isClobbered
11516
11978
  *
11979
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
11980
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
11981
+ * `name` attribute matching a prototype property shadows that property
11982
+ * on direct reads. We use this check at the IN_PLACE entry-point and
11983
+ * during attribute sanitization to refuse clobbered forms.
11984
+ *
11517
11985
  * @param element element to check for clobbering attacks
11518
11986
  * @return true if clobbered, false if safe
11519
11987
  */
11520
11988
  const _isClobbered = function _isClobbered(element) {
11521
- 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');
11989
+ // Realm-independent tag-name probe. If we can't determine the tag
11990
+ // name at all, we can't reason about clobbering — return false
11991
+ // (the caller's other defences still apply).
11992
+ const realTagName = getNodeName ? getNodeName(element) : null;
11993
+ if (typeof realTagName !== 'string') {
11994
+ return false;
11995
+ }
11996
+ if (transformCaseFunc(realTagName) !== 'form') {
11997
+ return false;
11998
+ }
11999
+ return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
12000
+ // Realm-safe NamedNodeMap detection: equality against the cached
12001
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
12002
+ // makes the direct read diverge from the cached read; a clean form
12003
+ // (same-realm OR foreign-realm) has both reads pointing at the same
12004
+ // canonical NamedNodeMap.
12005
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
12006
+ // NodeType clobbering probe. Cached Node.prototype.nodeType getter
12007
+ // returns the integer 1 for any Element regardless of realm; direct
12008
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
12009
+ // the named child element. Cheap addition — nodeType is read from
12010
+ // an internal slot, no serialization cost — and removes a residual
12011
+ // clobbering surface used by several mXSS / PI / comment branches
12012
+ // in _sanitizeElements that compare currentNode.nodeType directly.
12013
+ element.nodeType !== getNodeType(element) ||
12014
+ // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
12015
+ // "childNodes" shadows the prototype getter. Direct reads of
12016
+ // form.childNodes from a clobbered form return the named child
12017
+ // instead of the real NodeList, so any walk that reads it directly
12018
+ // skips the form's real children. Compare the direct read to the
12019
+ // cached Node.prototype getter — when the form's named-property
12020
+ // getter intercepts the read, the two values differ and we flag
12021
+ // the form. This catches every clobbering child type (input,
12022
+ // select, etc.) regardless of whether the named child happens to
12023
+ // carry a numeric .length, which a typeof-based probe would miss
12024
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
12025
+ element.childNodes !== getChildNodes(element);
11522
12026
  };
11523
12027
  /**
11524
- * Checks whether the given object is a DOM node.
12028
+ * Checks whether the given value is a DocumentFragment from any realm.
12029
+ *
12030
+ * The realm-independent replacement reads `nodeType` through the cached
12031
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
12032
+ * constant (11). nodeType is a numeric value resolved from the node's
12033
+ * internal slot, identical across realms for the same kind of node.
12034
+ *
12035
+ * @param value object to check
12036
+ * @return true if value is a DocumentFragment-shaped node from any realm
12037
+ */
12038
+ const _isDocumentFragment = function _isDocumentFragment(value) {
12039
+ if (!getNodeType || typeof value !== 'object' || value === null) {
12040
+ return false;
12041
+ }
12042
+ try {
12043
+ return getNodeType(value) === NODE_TYPE.documentFragment;
12044
+ } catch (_) {
12045
+ return false;
12046
+ }
12047
+ };
12048
+ /**
12049
+ * Checks whether the given object is a DOM node, including nodes that
12050
+ * originate from a different window/realm (e.g. an iframe's
12051
+ * contentDocument). The previous `value instanceof Node` check was
12052
+ * realm-bound: nodes from a different window failed it, causing
12053
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
12054
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
11525
12055
  *
11526
12056
  * @param value object to check whether it's a DOM node
11527
- * @return true is object is a DOM node
12057
+ * @return true if value is a DOM node from any realm
11528
12058
  */
11529
12059
  const _isNode = function _isNode(value) {
11530
- return typeof Node === 'function' && value instanceof Node;
12060
+ if (!getNodeType || typeof value !== 'object' || value === null) {
12061
+ return false;
12062
+ }
12063
+ try {
12064
+ return typeof getNodeType(value) === 'number';
12065
+ } catch (_) {
12066
+ return false;
12067
+ }
11531
12068
  };
11532
12069
  function _executeHooks(hooks, currentNode, data) {
12070
+ if (hooks.length === 0) {
12071
+ return;
12072
+ }
11533
12073
  arrayForEach(hooks, hook => {
11534
12074
  hook.call(DOMPurify, currentNode, data, CONFIG);
11535
12075
  });
11536
12076
  }
12077
+ /**
12078
+ * Structural-threat checks that condemn a node regardless of the
12079
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
12080
+ * processing instructions, markup-bearing comments. Pure predicate;
12081
+ * the caller removes. Check order is load-bearing.
12082
+ *
12083
+ * @param currentNode the node to inspect
12084
+ * @param tagName the node's transformCaseFunc'd tag name
12085
+ * @return true if the node must be removed
12086
+ */
12087
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
12088
+ /* Detect mXSS attempts abusing namespace confusion */
12089
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
12090
+ return true;
12091
+ }
12092
+ /* Remove risky CSS construction leading to mXSS */
12093
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
12094
+ return true;
12095
+ }
12096
+ /* Remove any occurrence of processing instructions */
12097
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
12098
+ return true;
12099
+ }
12100
+ /* Remove any kind of possibly harmful comments */
12101
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
12102
+ return true;
12103
+ }
12104
+ return false;
12105
+ };
12106
+ /**
12107
+ * Handle a node whose tag is forbidden or not allowlisted: keep
12108
+ * allowed custom elements (false return exits _sanitizeElements
12109
+ * early - namespace/fallback checks and the afterSanitizeElements
12110
+ * hook are intentionally skipped for kept custom elements), else
12111
+ * hoist content per KEEP_CONTENT and remove.
12112
+ *
12113
+ * @param currentNode the disallowed node
12114
+ * @param tagName the node's transformCaseFunc'd tag name
12115
+ * @return true if the node was removed, false if kept
12116
+ */
12117
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
12118
+ /* Check if we have a custom element to handle */
12119
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
12120
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
12121
+ return false;
12122
+ }
12123
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
12124
+ return false;
12125
+ }
12126
+ }
12127
+ /* Keep content except for bad-listed elements.
12128
+ Use the cached prototype getters exclusively — the previous code
12129
+ had `|| currentNode.parentNode` / `|| currentNode.childNodes`
12130
+ fallbacks, but the cached getters always return the canonical
12131
+ value (or null for a real parent-less node), so the fallback
12132
+ path was dead in safe cases and a clobbering surface in unsafe
12133
+ ones. Falsy cached results stay falsy; the `if (childNodes &&
12134
+ parentNode)` check already gates correctly. */
12135
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
12136
+ const parentNode = getParentNode(currentNode);
12137
+ const childNodes = getChildNodes(currentNode);
12138
+ if (childNodes && parentNode) {
12139
+ const childCount = childNodes.length;
12140
+ /* In-place: hoist the *original* children so the iterator visits
12141
+ and sanitises them through the same allowlist pass as every other
12142
+ node. The caller built the tree in the live document, so the
12143
+ originals carry already-queued resource events (`<img onerror>`,
12144
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
12145
+ those originals detached but still armed, firing in page scope
12146
+ while the returned tree looked clean. Moving is safe in-place: the
12147
+ root is pre-validated as an allowed tag and so is never the node
12148
+ being removed, which keeps `parentNode` inside the iterator root
12149
+ and the relocated child inside the serialised tree.
12150
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
12151
+ at — and the result serialised from — `body`, so a restrictive
12152
+ ALLOWED_TAGS that removes `body` itself must leave its content in
12153
+ place, which only cloning does; and those paths parse into an
12154
+ inert document, so their discarded originals never had a queued
12155
+ event to neutralise.
12156
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
12157
+ valid whether we move (drops the trailing entry) or clone (leaves
12158
+ the list intact). */
12159
+ for (let i = childCount - 1; i >= 0; --i) {
12160
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
12161
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
12162
+ }
12163
+ }
12164
+ }
12165
+ _forceRemove(currentNode);
12166
+ return true;
12167
+ };
11537
12168
  /**
11538
12169
  * _sanitizeElements
11539
12170
  *
@@ -11544,7 +12175,6 @@
11544
12175
  * @return true if node was killed, false if left alive
11545
12176
  */
11546
12177
  const _sanitizeElements = function _sanitizeElements(currentNode) {
11547
- let content = null;
11548
12178
  /* Execute a hook if present */
11549
12179
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
11550
12180
  /* Check if element is clobbered or can clobber */
@@ -11553,71 +12183,41 @@
11553
12183
  return true;
11554
12184
  }
11555
12185
  /* Now let's check the element's type and name */
11556
- const tagName = transformCaseFunc(currentNode.nodeName);
12186
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
11557
12187
  /* Execute a hook if present */
11558
12188
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
11559
12189
  tagName,
11560
12190
  allowedTags: ALLOWED_TAGS
11561
12191
  });
11562
- /* Detect mXSS attempts abusing namespace confusion */
11563
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
11564
- _forceRemove(currentNode);
11565
- return true;
11566
- }
11567
- /* Remove any occurrence of processing instructions */
11568
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
11569
- _forceRemove(currentNode);
11570
- return true;
11571
- }
11572
- /* Remove any kind of possibly harmful comments */
11573
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
12192
+ /* Remove mXSS vectors, processing instructions and risky comments */
12193
+ if (_isUnsafeNode(currentNode, tagName)) {
11574
12194
  _forceRemove(currentNode);
11575
12195
  return true;
11576
12196
  }
11577
12197
  /* Remove element if anything forbids its presence */
11578
- if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
11579
- /* Check if we have a custom element to handle */
11580
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
11581
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
11582
- return false;
11583
- }
11584
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
11585
- return false;
11586
- }
11587
- }
11588
- /* Keep content except for bad-listed elements */
11589
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
11590
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
11591
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
11592
- if (childNodes && parentNode) {
11593
- const childCount = childNodes.length;
11594
- for (let i = childCount - 1; i >= 0; --i) {
11595
- const childClone = cloneNode(childNodes[i], true);
11596
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
11597
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
11598
- }
11599
- }
11600
- }
11601
- _forceRemove(currentNode);
11602
- return true;
11603
- }
11604
- /* Check whether element has a valid namespace */
11605
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
12198
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
12199
+ return _sanitizeDisallowedNode(currentNode, tagName);
12200
+ }
12201
+ /* Check whether element has a valid namespace.
12202
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
12203
+ nodeType getter rather than `instanceof Element`, which is realm-
12204
+ bound and short-circuits to false for any node minted in a different
12205
+ realm — letting a foreign-realm element with a forbidden namespace
12206
+ slip past the namespace check entirely. */
12207
+ const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
12208
+ if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
11606
12209
  _forceRemove(currentNode);
11607
12210
  return true;
11608
12211
  }
11609
12212
  /* Make sure that older browsers don't get fallback-tag mXSS */
11610
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
12213
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
11611
12214
  _forceRemove(currentNode);
11612
12215
  return true;
11613
12216
  }
11614
12217
  /* Sanitize element content to be template-safe */
11615
12218
  if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
11616
12219
  /* Get the element's text content */
11617
- content = currentNode.textContent;
11618
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
11619
- content = stringReplace(content, expr, ' ');
11620
- });
12220
+ const content = _stripTemplateExpressions(currentNode.textContent);
11621
12221
  if (currentNode.textContent !== content) {
11622
12222
  arrayPush(DOMPurify.removed, {
11623
12223
  element: currentNode.cloneNode()
@@ -11647,11 +12247,12 @@
11647
12247
  if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
11648
12248
  return false;
11649
12249
  }
12250
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
11650
12251
  /* Allow valid data-* attributes: At least one character after "-"
11651
12252
  (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
11652
12253
  XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
11653
12254
  We don't need to check the value; it's always URI safe. */
11654
- 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]) {
12255
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
11655
12256
  if (
11656
12257
  // First condition does a very basic check if a) it's basically a valid custom element tagname AND
11657
12258
  // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
@@ -11663,11 +12264,15 @@
11663
12264
  return false;
11664
12265
  }
11665
12266
  /* Check value is safe. First, is attr inert? If so, is safe */
11666
- } 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) {
12267
+ } 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) {
11667
12268
  return false;
11668
12269
  } else ;
11669
12270
  return true;
11670
12271
  };
12272
+ /* Names the HTML spec reserves from valid-custom-element-name; these must
12273
+ * never be treated as basic custom elements even when a permissive
12274
+ * CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
12275
+ 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']);
11671
12276
  /**
11672
12277
  * _isBasicCustomElement
11673
12278
  * checks if at least one dash is included in tagName, and it's not the first char
@@ -11677,7 +12282,64 @@
11677
12282
  * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
11678
12283
  */
11679
12284
  const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
11680
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
12285
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
12286
+ };
12287
+ /**
12288
+ * Wrap an attribute value in the matching Trusted Types object when
12289
+ * the active policy requires it. Namespaced attributes pass through
12290
+ * unchanged (no TT support yet, see
12291
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
12292
+ *
12293
+ * @param lcTag lowercase tag name of the containing element
12294
+ * @param lcName lowercase attribute name
12295
+ * @param namespaceURI the attribute's namespace, if any
12296
+ * @param value the attribute value to wrap
12297
+ * @return the value, wrapped when Trusted Types demand it
12298
+ */
12299
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
12300
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
12301
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
12302
+ case 'TrustedHTML':
12303
+ {
12304
+ return _createTrustedHTML(value);
12305
+ }
12306
+ case 'TrustedScriptURL':
12307
+ {
12308
+ return _createTrustedScriptURL(value);
12309
+ }
12310
+ }
12311
+ }
12312
+ return value;
12313
+ };
12314
+ /**
12315
+ * Write a modified attribute value back onto the element. On
12316
+ * success, re-probe for clobbering introduced by the new value and
12317
+ * remove the element when found; otherwise pop the removal entry
12318
+ * recorded by the earlier _removeAttribute (long-standing pairing
12319
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
12320
+ * failure, remove the attribute instead.
12321
+ *
12322
+ * @param currentNode the element carrying the attribute
12323
+ * @param name the attribute name as present on the element
12324
+ * @param namespaceURI the attribute's namespace, if any
12325
+ * @param value the new attribute value
12326
+ */
12327
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
12328
+ try {
12329
+ if (namespaceURI) {
12330
+ currentNode.setAttributeNS(namespaceURI, name, value);
12331
+ } else {
12332
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
12333
+ currentNode.setAttribute(name, value);
12334
+ }
12335
+ if (_isClobbered(currentNode)) {
12336
+ _forceRemove(currentNode);
12337
+ } else {
12338
+ arrayPop(DOMPurify.removed);
12339
+ }
12340
+ } catch (_) {
12341
+ _removeAttribute(name, currentNode);
12342
+ }
11681
12343
  };
11682
12344
  /**
11683
12345
  * _sanitizeAttributes
@@ -11692,9 +12354,7 @@
11692
12354
  const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
11693
12355
  /* Execute a hook if present */
11694
12356
  _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
11695
- const {
11696
- attributes
11697
- } = currentNode;
12357
+ const attributes = currentNode.attributes;
11698
12358
  /* Check if we have attributes; if not we might have a text node */
11699
12359
  if (!attributes || _isClobbered(currentNode)) {
11700
12360
  return;
@@ -11707,14 +12367,13 @@
11707
12367
  forceKeepAttr: undefined
11708
12368
  };
11709
12369
  let l = attributes.length;
12370
+ const lcTag = transformCaseFunc(currentNode.nodeName);
11710
12371
  /* Go backwards over all attributes; safely remove bad ones */
11711
12372
  while (l--) {
11712
12373
  const attr = attributes[l];
11713
- const {
11714
- name,
11715
- namespaceURI,
11716
- value: attrValue
11717
- } = attr;
12374
+ const name = attr.name,
12375
+ namespaceURI = attr.namespaceURI,
12376
+ attrValue = attr.value;
11718
12377
  const lcName = transformCaseFunc(name);
11719
12378
  const initValue = attrValue;
11720
12379
  let value = name === 'value' ? initValue : stringTrim(initValue);
@@ -11728,12 +12387,14 @@
11728
12387
  /* Full DOM Clobbering protection via namespace isolation,
11729
12388
  * Prefix id and name attributes with `user-content-`
11730
12389
  */
11731
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
12390
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
11732
12391
  // Remove the attribute with this value
11733
12392
  _removeAttribute(name, currentNode);
11734
12393
  // Prefix the value and later re-create the attribute with the sanitized value
11735
12394
  value = SANITIZE_NAMED_PROPS_PREFIX + value;
11736
12395
  }
12396
+ // Else: already prefixed, leave the attribute alone — the prefix is
12397
+ // itself the clobbering protection, and re-applying it is incorrect.
11737
12398
  /* Work around a security issue with comments inside attributes */
11738
12399
  if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
11739
12400
  _removeAttribute(name, currentNode);
@@ -11744,7 +12405,7 @@
11744
12405
  _removeAttribute(name, currentNode);
11745
12406
  continue;
11746
12407
  }
11747
- /* Did the hooks approve of the attribute? */
12408
+ /* Did the hooks force-keep the attribute? */
11748
12409
  if (hookEvent.forceKeepAttr) {
11749
12410
  continue;
11750
12411
  }
@@ -11754,56 +12415,24 @@
11754
12415
  continue;
11755
12416
  }
11756
12417
  /* Work around a security issue in jQuery 3.0 */
11757
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
12418
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
11758
12419
  _removeAttribute(name, currentNode);
11759
12420
  continue;
11760
12421
  }
11761
12422
  /* Sanitize attribute content to be template-safe */
11762
12423
  if (SAFE_FOR_TEMPLATES) {
11763
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
11764
- value = stringReplace(value, expr, ' ');
11765
- });
12424
+ value = _stripTemplateExpressions(value);
11766
12425
  }
11767
12426
  /* Is `value` valid for this attribute? */
11768
- const lcTag = transformCaseFunc(currentNode.nodeName);
11769
12427
  if (!_isValidAttribute(lcTag, lcName, value)) {
11770
12428
  _removeAttribute(name, currentNode);
11771
12429
  continue;
11772
12430
  }
11773
12431
  /* Handle attributes that require Trusted Types */
11774
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
11775
- if (namespaceURI) ; else {
11776
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
11777
- case 'TrustedHTML':
11778
- {
11779
- value = trustedTypesPolicy.createHTML(value);
11780
- break;
11781
- }
11782
- case 'TrustedScriptURL':
11783
- {
11784
- value = trustedTypesPolicy.createScriptURL(value);
11785
- break;
11786
- }
11787
- }
11788
- }
11789
- }
12432
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
11790
12433
  /* Handle invalid data-* attribute set by try-catching it */
11791
12434
  if (value !== initValue) {
11792
- try {
11793
- if (namespaceURI) {
11794
- currentNode.setAttributeNS(namespaceURI, name, value);
11795
- } else {
11796
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
11797
- currentNode.setAttribute(name, value);
11798
- }
11799
- if (_isClobbered(currentNode)) {
11800
- _forceRemove(currentNode);
11801
- } else {
11802
- arrayPop(DOMPurify.removed);
11803
- }
11804
- } catch (_) {
11805
- _removeAttribute(name, currentNode);
11806
- }
12435
+ _setAttributeValue(currentNode, name, namespaceURI, value);
11807
12436
  }
11808
12437
  }
11809
12438
  /* Execute a hook if present */
@@ -11814,7 +12443,7 @@
11814
12443
  *
11815
12444
  * @param fragment to iterate over recursively
11816
12445
  */
11817
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
12446
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
11818
12447
  let shadowNode = null;
11819
12448
  const shadowIterator = _createNodeIterator(fragment);
11820
12449
  /* Execute a hook if present */
@@ -11826,14 +12455,133 @@
11826
12455
  _sanitizeElements(shadowNode);
11827
12456
  /* Check attributes next */
11828
12457
  _sanitizeAttributes(shadowNode);
11829
- /* Deep shadow DOM detected */
11830
- if (shadowNode.content instanceof DocumentFragment) {
11831
- _sanitizeShadowDOM(shadowNode.content);
12458
+ /* Deep shadow DOM detected.
12459
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
12460
+ DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
12461
+ recurse into <template>.content from foreign realms too. */
12462
+ if (_isDocumentFragment(shadowNode.content)) {
12463
+ _sanitizeShadowDOM2(shadowNode.content);
12464
+ }
12465
+ /* An element iterated here may itself host an attached
12466
+ shadow root. The default NodeIterator does not enter shadow
12467
+ trees, so a shadow root nested inside template.content was
12468
+ previously reached by no walk at all (the pre-pass at
12469
+ _sanitizeAttachedShadowRoots descends via childNodes, which
12470
+ doesn't enter template.content; the template-content recursion
12471
+ above iterates the content but never inspected shadowRoot).
12472
+ Walk it explicitly. The nodeType guard avoids reading
12473
+ shadowRoot off text / comment / CDATA / PI nodes that the
12474
+ iterator also surfaces. */
12475
+ const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
12476
+ if (shadowNodeType === NODE_TYPE.element) {
12477
+ const innerSr = getShadowRoot(shadowNode);
12478
+ if (_isDocumentFragment(innerSr)) {
12479
+ _sanitizeAttachedShadowRoots(innerSr);
12480
+ _sanitizeShadowDOM2(innerSr);
12481
+ }
11832
12482
  }
11833
12483
  }
11834
12484
  /* Execute a hook if present */
11835
12485
  _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
11836
12486
  };
12487
+ /**
12488
+ * _sanitizeAttachedShadowRoots
12489
+ *
12490
+ * Walks `root` and feeds every attached shadow root we encounter into
12491
+ * the existing _sanitizeShadowDOM pipeline. The default node iterator
12492
+ * does not descend into shadow trees, so nodes inside an attached
12493
+ * shadow root would otherwise be skipped entirely.
12494
+ *
12495
+ * Two real input paths put attached shadow roots in front of us:
12496
+ * 1. IN_PLACE on a DOM node that already has shadow roots attached.
12497
+ * 2. DOM-node input where importNode(dirty, true) deep-clones the
12498
+ * shadow root because it was created with `clonable: true`.
12499
+ *
12500
+ * This pass runs once, up front, so the main iteration loop (and the
12501
+ * existing _sanitizeShadowDOM template-content recursion) stay
12502
+ * untouched — string-input paths are not affected.
12503
+ *
12504
+ * @param root the subtree root to walk for attached shadow roots
12505
+ */
12506
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
12507
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
12508
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
12509
+ built straight into the DOM — the IN_PLACE surface) deeper than the JS
12510
+ call-stack budget would otherwise overflow native recursion here and
12511
+ throw at the IN_PLACE entry pre-pass, before a single node is
12512
+ sanitized, leaving the caller's live tree untouched (fail-open). See
12513
+ campaign-3 F4. A heap stack keeps depth off the call stack.
12514
+ Each work item is either a node to descend into, or a deferred
12515
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
12516
+ form preserves the original post-order discipline: a shadow root's
12517
+ nested shadow roots are discovered before the outer shadow is
12518
+ sanitized (which may remove hosts). Pushes are in reverse of the
12519
+ desired processing order (LIFO): template content, then children, then
12520
+ the shadow-sanitize, then the shadow walk — so the order matches the
12521
+ previous recursion exactly. */
12522
+ const stack = [{
12523
+ node: root,
12524
+ shadow: null
12525
+ }];
12526
+ while (stack.length > 0) {
12527
+ const item = stack.pop();
12528
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
12529
+ if (item.shadow) {
12530
+ _sanitizeShadowDOM2(item.shadow);
12531
+ continue;
12532
+ }
12533
+ const node = item.node;
12534
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
12535
+ const isElement = nodeType === NODE_TYPE.element;
12536
+ /* (pushed last → processed first) Children, snapshotted in reverse so
12537
+ the first child is processed first. Snapshotting matters because a
12538
+ hook may detach siblings mid-walk. */
12539
+ const childNodes = getChildNodes(node);
12540
+ if (childNodes) {
12541
+ for (let i = childNodes.length - 1; i >= 0; --i) {
12542
+ stack.push({
12543
+ node: childNodes[i],
12544
+ shadow: null
12545
+ });
12546
+ }
12547
+ }
12548
+ /* (pushed before children → processed after them, matching the old
12549
+ "template content last" order) When the node is a <template>,
12550
+ descend into its content. */
12551
+ if (isElement) {
12552
+ const rootName = getNodeName ? getNodeName(node) : null;
12553
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
12554
+ const content = node.content;
12555
+ if (_isDocumentFragment(content)) {
12556
+ stack.push({
12557
+ node: content,
12558
+ shadow: null
12559
+ });
12560
+ }
12561
+ }
12562
+ }
12563
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
12564
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
12565
+ rather than `instanceof DocumentFragment`, which is realm-bound and
12566
+ silently skipped foreign-realm shadow roots (e.g.
12567
+ iframe.contentDocument attachShadow). */
12568
+ if (isElement) {
12569
+ const sr = getShadowRoot(node);
12570
+ if (_isDocumentFragment(sr)) {
12571
+ /* Push the deferred sanitise first so it pops after the shadow
12572
+ walk we push next, i.e. nested shadow roots are discovered
12573
+ before this one is sanitised. */
12574
+ stack.push({
12575
+ node: null,
12576
+ shadow: sr
12577
+ }, {
12578
+ node: sr,
12579
+ shadow: null
12580
+ });
12581
+ }
12582
+ }
12583
+ }
12584
+ };
11837
12585
  // eslint-disable-next-line complexity
11838
12586
  DOMPurify.sanitize = function (dirty) {
11839
12587
  let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -11850,13 +12598,9 @@
11850
12598
  }
11851
12599
  /* Stringify, in case dirty is an object */
11852
12600
  if (typeof dirty !== 'string' && !_isNode(dirty)) {
11853
- if (typeof dirty.toString === 'function') {
11854
- dirty = dirty.toString();
11855
- if (typeof dirty !== 'string') {
11856
- throw typeErrorCreate('dirty is not a string, aborting');
11857
- }
11858
- } else {
11859
- throw typeErrorCreate('toString is not a function');
12601
+ dirty = stringifyValue(dirty);
12602
+ if (typeof dirty !== 'string') {
12603
+ throw typeErrorCreate('dirty is not a string, aborting');
11860
12604
  }
11861
12605
  }
11862
12606
  /* Return dirty HTML if DOMPurify cannot run */
@@ -11869,19 +12613,51 @@
11869
12613
  }
11870
12614
  /* Clean up removed elements */
11871
12615
  DOMPurify.removed = [];
11872
- /* Check if dirty is correctly typed for IN_PLACE */
11873
- if (typeof dirty === 'string') {
11874
- IN_PLACE = false;
11875
- }
11876
- if (IN_PLACE) {
11877
- /* Do some early pre-sanitization to avoid unsafe root nodes */
11878
- if (dirty.nodeName) {
11879
- const tagName = transformCaseFunc(dirty.nodeName);
12616
+ /* Resolve IN_PLACE for this call without mutating persistent config.
12617
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
12618
+ where _parseConfig is skipped on later calls: a single string call would
12619
+ disable in-place mode for every subsequent node call, returning a
12620
+ sanitized copy while leaving the caller's node — which in-place callers
12621
+ keep using and whose return value they ignore unsanitized. REPORT-2. */
12622
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
12623
+ if (inPlace) {
12624
+ /* Do some early pre-sanitization to avoid unsafe root nodes.
12625
+ Read nodeName through the cached prototype getter — a clobbering
12626
+ child named "nodeName" on the form root would otherwise shadow
12627
+ the property and let this check skip the root-allowlist
12628
+ validation entirely. */
12629
+ const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
12630
+ if (typeof nn === 'string') {
12631
+ const tagName = transformCaseFunc(nn);
11880
12632
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
11881
12633
  throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
11882
12634
  }
11883
12635
  }
11884
- } else if (dirty instanceof Node) {
12636
+ /* Pre-flight the root through _isClobbered. The iterator-driven
12637
+ removal path can not detach a parent-less root: _forceRemove
12638
+ falls through to Element.prototype.remove(), which per spec
12639
+ is a no-op on a node with no parent. A clobbered root would
12640
+ then survive the main loop with its attributes uninspected,
12641
+ because _sanitizeAttributes early-returns on _isClobbered. The
12642
+ result would be an attacker-controlled form, complete with any
12643
+ event-handler attributes the caller passed in, handed back to
12644
+ the application unsanitized. Refuse to sanitize such a root
12645
+ the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
12646
+ if (_isClobbered(dirty)) {
12647
+ throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
12648
+ }
12649
+ /* Sanitize attached shadow roots before the main iterator runs.
12650
+ The iterator does not descend into shadow trees. Same fail-closed
12651
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
12652
+ inside a shadow root could abort this pre-pass before the walk runs,
12653
+ which would otherwise leave the entire live tree unsanitized. */
12654
+ try {
12655
+ _sanitizeAttachedShadowRoots(dirty);
12656
+ } catch (error) {
12657
+ _neutralizeRoot(dirty);
12658
+ throw error;
12659
+ }
12660
+ } else if (_isNode(dirty)) {
11885
12661
  /* If dirty is a DOM element, append to an empty document to avoid
11886
12662
  elements being stripped by the parser */
11887
12663
  body = _initDocument('<!---->');
@@ -11895,12 +12671,18 @@
11895
12671
  // eslint-disable-next-line unicorn/prefer-dom-node-append
11896
12672
  body.appendChild(importedNode);
11897
12673
  }
12674
+ /* Clonable shadow roots are deep-cloned by importNode(); sanitize
12675
+ them before the main iterator runs, since the iterator does not
12676
+ descend into shadow trees. The walk routes every read through a
12677
+ cached prototype getter so clobbering descendants on a form root
12678
+ cannot hide a shadow host from this pass. */
12679
+ _sanitizeAttachedShadowRoots(importedNode);
11898
12680
  } else {
11899
12681
  /* Exit directly if we have nothing to do */
11900
12682
  if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
11901
12683
  // eslint-disable-next-line unicorn/prefer-includes
11902
12684
  dirty.indexOf('<') === -1) {
11903
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
12685
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
11904
12686
  }
11905
12687
  /* Initialize the document to work on */
11906
12688
  body = _initDocument(dirty);
@@ -11914,24 +12696,60 @@
11914
12696
  _forceRemove(body.firstChild);
11915
12697
  }
11916
12698
  /* Get node iterator */
11917
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
11918
- /* Now start iterating over the created document */
11919
- while (currentNode = nodeIterator.nextNode()) {
11920
- /* Sanitize tags and elements */
11921
- _sanitizeElements(currentNode);
11922
- /* Check attributes next */
11923
- _sanitizeAttributes(currentNode);
11924
- /* Shadow DOM detected, sanitize it */
11925
- if (currentNode.content instanceof DocumentFragment) {
11926
- _sanitizeShadowDOM(currentNode.content);
12699
+ const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
12700
+ /* Now start iterating over the created document.
12701
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
12702
+ engine/custom-element mutation can detach a node mid-walk so
12703
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
12704
+ barrier the caller's in-place tree would be left half-sanitized with the
12705
+ unvisited tail still armed. On any throw we fail closed — strip the
12706
+ in-place root bare then rethrow so the existing throw contract is
12707
+ preserved. (String/DOM-copy paths never return the partial body, so the
12708
+ propagating throw is already fail-closed there.) */
12709
+ try {
12710
+ while (currentNode = nodeIterator.nextNode()) {
12711
+ /* Sanitize tags and elements */
12712
+ _sanitizeElements(currentNode);
12713
+ /* Check attributes next */
12714
+ _sanitizeAttributes(currentNode);
12715
+ /* Shadow DOM detected, sanitize it.
12716
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
12717
+ instead of instanceof, so foreign-realm <template>.content is
12718
+ walked correctly. */
12719
+ if (_isDocumentFragment(currentNode.content)) {
12720
+ _sanitizeShadowDOM2(currentNode.content);
12721
+ }
11927
12722
  }
12723
+ } catch (error) {
12724
+ if (inPlace) {
12725
+ _neutralizeRoot(dirty);
12726
+ }
12727
+ throw error;
11928
12728
  }
11929
12729
  /* If we sanitized `dirty` in-place, return it. */
11930
- if (IN_PLACE) {
12730
+ if (inPlace) {
12731
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
12732
+ the caller's live tree is detached but may still hold a queued
12733
+ resource-event handler that fires in page scope after we return. The
12734
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
12735
+ non-allow-listed attributes off every other removed subtree (clobber,
12736
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
12737
+ cancelled before any event can fire. Runs synchronously, pre-return. */
12738
+ arrayForEach(DOMPurify.removed, entry => {
12739
+ if (entry.element) {
12740
+ _neutralizeSubtree(entry.element);
12741
+ }
12742
+ });
12743
+ if (SAFE_FOR_TEMPLATES) {
12744
+ _scrubTemplateExpressions2(dirty);
12745
+ }
11931
12746
  return dirty;
11932
12747
  }
11933
12748
  /* Return sanitized string or DOM */
11934
12749
  if (RETURN_DOM) {
12750
+ if (SAFE_FOR_TEMPLATES) {
12751
+ _scrubTemplateExpressions2(body);
12752
+ }
11935
12753
  if (RETURN_DOM_FRAGMENT) {
11936
12754
  returnNode = createDocumentFragment.call(body.ownerDocument);
11937
12755
  while (body.firstChild) {
@@ -11960,11 +12778,9 @@
11960
12778
  }
11961
12779
  /* Sanitize final string template-safe */
11962
12780
  if (SAFE_FOR_TEMPLATES) {
11963
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
11964
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
11965
- });
12781
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
11966
12782
  }
11967
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
12783
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
11968
12784
  };
11969
12785
  DOMPurify.setConfig = function () {
11970
12786
  let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -11974,6 +12790,12 @@
11974
12790
  DOMPurify.clearConfig = function () {
11975
12791
  CONFIG = null;
11976
12792
  SET_CONFIG = false;
12793
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
12794
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
12795
+ // never recreated — Trusted Types throws on duplicate names) is restored by
12796
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
12797
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
12798
+ emptyHTML = '';
11977
12799
  };
11978
12800
  DOMPurify.isValidAttribute = function (tag, attr, value) {
11979
12801
  /* Initialize shared config vars if necessary. */
@@ -46232,6 +47054,7 @@
46232
47054
  logScale: false,
46233
47055
  windowFunction: 'mean',
46234
47056
  graphType: 'bar',
47057
+ lineWidth: 2,
46235
47058
  normalize: undefined,
46236
47059
  scaleFactor: undefined,
46237
47060
  overflowColor: `rgb(255, 32, 255)`,
@@ -46283,6 +47106,8 @@
46283
47106
  if ("heatmap" === config.graphType && !config.height) {
46284
47107
  this.height = 20;
46285
47108
  }
47109
+
47110
+ this.lineWidth = config.lineWidth || WigTrack.defaults.lineWidth; // Set lineWidth from config
46286
47111
  }
46287
47112
 
46288
47113
  async postInit() {
@@ -46504,11 +47329,11 @@
46504
47329
  const color = options.alpha ? IGVColor.addAlpha(this.getColorForFeature(f), options.alpha) : this.getColorForFeature(f);
46505
47330
 
46506
47331
  if (this.graphType === "line") {
47332
+ const lineWidth = this.lineWidth;
47333
+ const properties = {"fillStyle": color, "strokeStyle": color, "lineWidth": lineWidth};
47334
+
46507
47335
  if (lastY !== undefined) {
46508
- IGVGraphics.strokeLine(ctx, lastPixelEnd, lastY, x, y, {
46509
- "fillStyle": color,
46510
- "strokeStyle": color
46511
- });
47336
+ IGVGraphics.strokeLine(ctx, lastPixelEnd, lastY, x, y, properties);
46512
47337
  }
46513
47338
  IGVGraphics.strokeLine(ctx, x, y, x + width, y, {"fillStyle": color, "strokeStyle": color});
46514
47339
  } else if (this.graphType === "points") {
@@ -76309,6 +77134,9 @@ ${indent}columns: ${matrix.columns}
76309
77134
  indexURL: r.getAttribute("index"),
76310
77135
  order: idx
76311
77136
  };
77137
+ if (r.hasAttribute("format")) {
77138
+ config.format = r.getAttribute("format");
77139
+ }
76312
77140
  resourceMap.set(config.url, config);
76313
77141
  if (!hasTrackElements) {
76314
77142
  tracks.push(config);
@@ -76396,6 +77224,13 @@ ${indent}columns: ${matrix.columns}
76396
77224
 
76397
77225
  config.name = track.getAttribute("name");
76398
77226
 
77227
+ if(track.hasAttribute("type")) {
77228
+ config.type = track.getAttribute("type");
77229
+ }
77230
+ if(track.hasAttribute("format")) {
77231
+ config.format = track.getAttribute("format");
77232
+ }
77233
+
76399
77234
  const color = track.getAttribute("color");
76400
77235
  if (color) {
76401
77236
  config.color = "rgb(" + color + ")";
@@ -76707,7 +77542,7 @@ ${indent}columns: ${matrix.columns}
76707
77542
  })
76708
77543
  }
76709
77544
 
76710
- const _version = "3.8.0";
77545
+ const _version = "3.8.2";
76711
77546
  function version() {
76712
77547
  return _version
76713
77548
  }
@@ -78334,11 +79169,11 @@ ${indent}columns: ${matrix.columns}
78334
79169
 
78335
79170
  }
78336
79171
 
78337
- function createRegionKey$1(chr, start, end) {
79172
+ function createRegionKey(chr, start, end) {
78338
79173
  return `${chr}-${start}-${end}`
78339
79174
  }
78340
79175
 
78341
- function parseRegionKey$1(regionKey) {
79176
+ function parseRegionKey(regionKey) {
78342
79177
  let regionParts = regionKey.split('-');
78343
79178
  let ee = parseInt(regionParts.pop());
78344
79179
  let ss = parseInt(regionParts.pop());
@@ -78368,7 +79203,7 @@ ${indent}columns: ${matrix.columns}
78368
79203
  const dom = div({ class: 'igv-roi-table-row' });
78369
79204
 
78370
79205
  const { setName, feature } = record;
78371
- dom.dataset.region = createRegionKey$1(feature.chr, feature.start, feature.end);
79206
+ dom.dataset.region = createRegionKey(feature.chr, feature.start, feature.end);
78372
79207
 
78373
79208
  let strings =
78374
79209
  [
@@ -78440,7 +79275,7 @@ ${indent}columns: ${matrix.columns}
78440
79275
 
78441
79276
  const loci = [];
78442
79277
  for (let el of selected) {
78443
- const { locus } = parseRegionKey$1(el.dataset.region);
79278
+ const { locus } = parseRegionKey(el.dataset.region);
78444
79279
  loci.push(locus);
78445
79280
  }
78446
79281
 
@@ -78494,7 +79329,7 @@ ${indent}columns: ${matrix.columns}
78494
79329
  const selected = this.tableDOM.querySelectorAll('.igv-roi-table-row-selected');
78495
79330
 
78496
79331
  if (selected.length > 0 && selected.length < 2) {
78497
- const { locus } = parseRegionKey$1(selected[ 0 ].dataset.region);
79332
+ const { locus } = parseRegionKey(selected[ 0 ].dataset.region);
78498
79333
  const { chr, start, end } = parseLocusString(locus, this.browser.isSoftclipped());
78499
79334
  enableButton(this.copySequenceButton, (end - start) < 1e6);
78500
79335
  } else {
@@ -78543,7 +79378,7 @@ ${indent}columns: ${matrix.columns}
78543
79378
  const selected = this.tableDOM.querySelectorAll('.igv-roi-table-row-selected');
78544
79379
  const loci = [];
78545
79380
  for (let el of selected) {
78546
- const { locus } = parseRegionKey$1(el.dataset.region);
79381
+ const { locus } = parseRegionKey(el.dataset.region);
78547
79382
  loci.push(locus);
78548
79383
  }
78549
79384