@ukic/web-components 3.28.0 → 3.29.0

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.
Files changed (85) hide show
  1. package/components/ic-breadcrumb-group.js +16 -12
  2. package/components/ic-breadcrumb-group.js.map +1 -1
  3. package/components/ic-menu-item2.js +7 -2
  4. package/components/ic-menu-item2.js.map +1 -1
  5. package/components/ic-menu2.js +1153 -306
  6. package/components/ic-menu2.js.map +1 -1
  7. package/components/ic-pagination-item2.js.map +1 -1
  8. package/components/ic-pagination2.js.map +1 -1
  9. package/components/ic-popover-menu.js +17 -5
  10. package/components/ic-popover-menu.js.map +1 -1
  11. package/components/ic-radio-group.js.map +1 -1
  12. package/components/ic-switch.js.map +1 -1
  13. package/dist/cjs/core.cjs.js +1 -1
  14. package/dist/cjs/ic-breadcrumb-group.cjs.entry.js +16 -12
  15. package/dist/cjs/ic-breadcrumb-group.cjs.entry.js.map +1 -1
  16. package/dist/cjs/ic-button_3.cjs.entry.js.map +1 -1
  17. package/dist/cjs/ic-input-component-container_3.cjs.entry.js +1153 -306
  18. package/dist/cjs/ic-input-component-container_3.cjs.entry.js.map +1 -1
  19. package/dist/cjs/ic-menu-item.cjs.entry.js +5 -1
  20. package/dist/cjs/ic-menu-item.cjs.entry.js.map +1 -1
  21. package/dist/cjs/ic-popover-menu.cjs.entry.js +16 -5
  22. package/dist/cjs/ic-popover-menu.cjs.entry.js.map +1 -1
  23. package/dist/cjs/ic-section-container.cjs.entry.js.map +1 -1
  24. package/dist/cjs/loader.cjs.js +1 -1
  25. package/dist/collection/components/ic-breadcrumb-group/ic-breadcrumb-group.js +17 -13
  26. package/dist/collection/components/ic-breadcrumb-group/ic-breadcrumb-group.js.map +1 -1
  27. package/dist/collection/components/ic-menu-item/ic-menu-item.css +9 -14
  28. package/dist/collection/components/ic-menu-item/ic-menu-item.js +24 -0
  29. package/dist/collection/components/ic-menu-item/ic-menu-item.js.map +1 -1
  30. package/dist/collection/components/ic-popover-menu/ic-popover-menu.js +36 -5
  31. package/dist/collection/components/ic-popover-menu/ic-popover-menu.js.map +1 -1
  32. package/dist/collection/components/ic-popover-menu/ic-popover-menu.stories.js +169 -1
  33. package/dist/components/ic-breadcrumb-group.js +16 -12
  34. package/dist/components/ic-breadcrumb-group.js.map +1 -1
  35. package/dist/components/ic-hero.js.map +1 -1
  36. package/dist/components/ic-menu-item2.js +7 -2
  37. package/dist/components/ic-menu-item2.js.map +1 -1
  38. package/dist/components/ic-menu2.js +1153 -306
  39. package/dist/components/ic-menu2.js.map +1 -1
  40. package/dist/components/ic-pagination-bar.js.map +1 -1
  41. package/dist/components/ic-popover-menu.js +17 -5
  42. package/dist/components/ic-popover-menu.js.map +1 -1
  43. package/dist/components/ic-search-bar.js.map +1 -1
  44. package/dist/components/ic-side-navigation.js.map +1 -1
  45. package/dist/components/ic-switch.js.map +1 -1
  46. package/dist/core/core.esm.js +1 -1
  47. package/dist/core/core.esm.js.map +1 -1
  48. package/dist/core/p-305d9639.entry.js +3 -0
  49. package/dist/core/p-305d9639.entry.js.map +1 -0
  50. package/dist/core/p-98dee727.entry.js.map +1 -1
  51. package/dist/core/p-a8d98164.entry.js.map +1 -1
  52. package/dist/core/p-be8bbed8.entry.js +2 -0
  53. package/dist/core/p-be8bbed8.entry.js.map +1 -0
  54. package/dist/core/p-ef289935.entry.js +2 -0
  55. package/dist/core/p-ef289935.entry.js.map +1 -0
  56. package/dist/core/p-f8aa89ff.entry.js +2 -0
  57. package/dist/core/p-f8aa89ff.entry.js.map +1 -0
  58. package/dist/esm/core.js +1 -1
  59. package/dist/esm/ic-breadcrumb-group.entry.js +16 -12
  60. package/dist/esm/ic-breadcrumb-group.entry.js.map +1 -1
  61. package/dist/esm/ic-button_3.entry.js.map +1 -1
  62. package/dist/esm/ic-input-component-container_3.entry.js +1153 -306
  63. package/dist/esm/ic-input-component-container_3.entry.js.map +1 -1
  64. package/dist/esm/ic-menu-item.entry.js +5 -1
  65. package/dist/esm/ic-menu-item.entry.js.map +1 -1
  66. package/dist/esm/ic-popover-menu.entry.js +16 -5
  67. package/dist/esm/ic-popover-menu.entry.js.map +1 -1
  68. package/dist/esm/ic-section-container.entry.js.map +1 -1
  69. package/dist/esm/loader.js +1 -1
  70. package/dist/types/components/ic-breadcrumb-group/ic-breadcrumb-group.d.ts +6 -1
  71. package/dist/types/components/ic-menu-item/ic-menu-item.d.ts +4 -0
  72. package/dist/types/components/ic-popover-menu/ic-popover-menu.d.ts +4 -0
  73. package/dist/types/components.d.ts +18 -2
  74. package/hydrate/index.js +1193 -325
  75. package/hydrate/index.mjs +1193 -325
  76. package/package.json +10 -6
  77. package/vscode-data.json +20 -1
  78. package/dist/core/p-2b1ce5b7.entry.js +0 -2
  79. package/dist/core/p-2b1ce5b7.entry.js.map +0 -1
  80. package/dist/core/p-56ab6fb7.entry.js +0 -2
  81. package/dist/core/p-56ab6fb7.entry.js.map +0 -1
  82. package/dist/core/p-d5fcd4f9.entry.js +0 -2
  83. package/dist/core/p-d5fcd4f9.entry.js.map +0 -1
  84. package/dist/core/p-fdc4376e.entry.js +0 -3
  85. package/dist/core/p-fdc4376e.entry.js.map +0 -1
@@ -11,28 +11,69 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof win
11
11
 
12
12
  var purify = {exports: {}};
13
13
 
14
- /*! @license DOMPurify 3.4.0 | (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.0/LICENSE */
14
+ /*! @license DOMPurify 3.4.11 | (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.11/LICENSE */
15
15
 
16
16
  (function (module, exports) {
17
17
  (function (global, factory) {
18
18
  module.exports = factory() ;
19
19
  })(commonjsGlobal, (function () {
20
- const {
21
- entries,
22
- setPrototypeOf,
23
- isFrozen,
24
- getPrototypeOf,
25
- getOwnPropertyDescriptor
26
- } = Object;
27
- let {
28
- freeze,
29
- seal,
30
- create
31
- } = Object; // eslint-disable-line import/no-mutable-exports
32
- let {
33
- apply,
34
- construct
35
- } = typeof Reflect !== 'undefined' && Reflect;
20
+ function _arrayLikeToArray(r, a) {
21
+ (null == a || a > r.length) && (a = r.length);
22
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
23
+ return n;
24
+ }
25
+ function _arrayWithHoles(r) {
26
+ if (Array.isArray(r)) return r;
27
+ }
28
+ function _iterableToArrayLimit(r, l) {
29
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
30
+ if (null != t) {
31
+ var e,
32
+ n,
33
+ i,
34
+ u,
35
+ a = [],
36
+ f = true,
37
+ o = false;
38
+ try {
39
+ 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);
40
+ } catch (r) {
41
+ o = true, n = r;
42
+ } finally {
43
+ try {
44
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
45
+ } finally {
46
+ if (o) throw n;
47
+ }
48
+ }
49
+ return a;
50
+ }
51
+ }
52
+ function _nonIterableRest() {
53
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
54
+ }
55
+ function _slicedToArray(r, e) {
56
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
57
+ }
58
+ function _unsupportedIterableToArray(r, a) {
59
+ if (r) {
60
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
61
+ var t = {}.toString.call(r).slice(8, -1);
62
+ 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;
63
+ }
64
+ }
65
+
66
+ const entries = Object.entries,
67
+ setPrototypeOf = Object.setPrototypeOf,
68
+ isFrozen = Object.isFrozen,
69
+ getPrototypeOf = Object.getPrototypeOf,
70
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
71
+ let freeze = Object.freeze,
72
+ seal = Object.seal,
73
+ create = Object.create; // eslint-disable-line import/no-mutable-exports
74
+ let _ref = typeof Reflect !== 'undefined' && Reflect,
75
+ apply = _ref.apply,
76
+ construct = _ref.construct;
36
77
  if (!freeze) {
37
78
  freeze = function freeze(x) {
38
79
  return x;
@@ -64,13 +105,19 @@ var purify = {exports: {}};
64
105
  const arrayPop = unapply(Array.prototype.pop);
65
106
  const arrayPush = unapply(Array.prototype.push);
66
107
  const arraySplice = unapply(Array.prototype.splice);
108
+ const arrayIsArray = Array.isArray;
67
109
  const stringToLowerCase = unapply(String.prototype.toLowerCase);
68
110
  const stringToString = unapply(String.prototype.toString);
69
111
  const stringMatch = unapply(String.prototype.match);
70
112
  const stringReplace = unapply(String.prototype.replace);
71
113
  const stringIndexOf = unapply(String.prototype.indexOf);
72
114
  const stringTrim = unapply(String.prototype.trim);
115
+ const numberToString = unapply(Number.prototype.toString);
116
+ const booleanToString = unapply(Boolean.prototype.toString);
117
+ const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
118
+ const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
73
119
  const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
120
+ const objectToString = unapply(Object.prototype.toString);
74
121
  const regExpTest = unapply(RegExp.prototype.test);
75
122
  const typeErrorCreate = unconstruct(TypeError);
76
123
  /**
@@ -120,6 +167,9 @@ var purify = {exports: {}};
120
167
  // Prevent prototype setters from intercepting set as a this value.
121
168
  setPrototypeOf(set, null);
122
169
  }
170
+ if (!arrayIsArray(array)) {
171
+ return set;
172
+ }
123
173
  let l = array.length;
124
174
  while (l--) {
125
175
  let element = array[l];
@@ -160,10 +210,13 @@ var purify = {exports: {}};
160
210
  */
161
211
  function clone(object) {
162
212
  const newObject = create(null);
163
- for (const [property, value] of entries(object)) {
213
+ for (const _ref2 of entries(object)) {
214
+ var _ref3 = _slicedToArray(_ref2, 2);
215
+ const property = _ref3[0];
216
+ const value = _ref3[1];
164
217
  const isPropertyExist = objectHasOwnProperty(object, property);
165
218
  if (isPropertyExist) {
166
- if (Array.isArray(value)) {
219
+ if (arrayIsArray(value)) {
167
220
  newObject[property] = cleanArray(value);
168
221
  } else if (value && typeof value === 'object' && value.constructor === Object) {
169
222
  newObject[property] = clone(value);
@@ -174,6 +227,58 @@ var purify = {exports: {}};
174
227
  }
175
228
  return newObject;
176
229
  }
230
+ /**
231
+ * Convert non-node values into strings without depending on direct property access.
232
+ *
233
+ * @param value - The value to stringify.
234
+ * @returns A string representation of the provided value.
235
+ */
236
+ function stringifyValue(value) {
237
+ switch (typeof value) {
238
+ case 'string':
239
+ {
240
+ return value;
241
+ }
242
+ case 'number':
243
+ {
244
+ return numberToString(value);
245
+ }
246
+ case 'boolean':
247
+ {
248
+ return booleanToString(value);
249
+ }
250
+ case 'bigint':
251
+ {
252
+ return bigintToString ? bigintToString(value) : '0';
253
+ }
254
+ case 'symbol':
255
+ {
256
+ return symbolToString ? symbolToString(value) : 'Symbol()';
257
+ }
258
+ case 'undefined':
259
+ {
260
+ return objectToString(value);
261
+ }
262
+ case 'function':
263
+ case 'object':
264
+ {
265
+ if (value === null) {
266
+ return objectToString(value);
267
+ }
268
+ const valueAsRecord = value;
269
+ const valueToString = lookupGetter(valueAsRecord, 'toString');
270
+ if (typeof valueToString === 'function') {
271
+ const stringified = valueToString(valueAsRecord);
272
+ return typeof stringified === 'string' ? stringified : objectToString(stringified);
273
+ }
274
+ return objectToString(value);
275
+ }
276
+ default:
277
+ {
278
+ return objectToString(value);
279
+ }
280
+ }
281
+ }
177
282
  /**
178
283
  * This method automatically checks if the prop is function or getter and behaves accordingly.
179
284
  *
@@ -199,6 +304,14 @@ var purify = {exports: {}};
199
304
  }
200
305
  return fallbackValue;
201
306
  }
307
+ function isRegex(value) {
308
+ try {
309
+ regExpTest(value, '');
310
+ return true;
311
+ } catch (_unused) {
312
+ return false;
313
+ }
314
+ }
202
315
 
203
316
  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']);
204
317
  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']);
@@ -214,15 +327,14 @@ var purify = {exports: {}};
214
327
  const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
215
328
  const text = freeze(['#text']);
216
329
 
217
- 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']);
330
+ 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']);
218
331
  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']);
219
332
  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']);
220
333
  const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
221
334
 
222
- // eslint-disable-next-line unicorn/better-regex
223
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
224
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
225
- const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
335
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
336
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
337
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
226
338
  const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
227
339
  const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
228
340
  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
@@ -232,30 +344,31 @@ var purify = {exports: {}};
232
344
  );
233
345
  const DOCTYPE_NAME = seal(/^html$/i);
234
346
  const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
347
+ // Markup-significant character probes used by _sanitizeElements.
348
+ // Shared module-level instances are safe despite the sticky /g flags:
349
+ // unapply() resets lastIndex for RegExp receivers before every call.
350
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
351
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
352
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
353
+ const SELF_CLOSING_TAG = seal(/\/>/i);
235
354
 
236
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
237
- __proto__: null,
238
- ARIA_ATTR: ARIA_ATTR,
239
- ATTR_WHITESPACE: ATTR_WHITESPACE,
240
- CUSTOM_ELEMENT: CUSTOM_ELEMENT,
241
- DATA_ATTR: DATA_ATTR,
242
- DOCTYPE_NAME: DOCTYPE_NAME,
243
- ERB_EXPR: ERB_EXPR,
244
- IS_ALLOWED_URI: IS_ALLOWED_URI,
245
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
246
- MUSTACHE_EXPR: MUSTACHE_EXPR,
247
- TMPLIT_EXPR: TMPLIT_EXPR
248
- });
249
-
250
- /* eslint-disable @typescript-eslint/indent */
251
355
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
252
356
  const NODE_TYPE = {
253
357
  element: 1,
358
+ attribute: 2,
254
359
  text: 3,
360
+ cdataSection: 4,
361
+ entityReference: 5,
255
362
  // Deprecated
256
- progressingInstruction: 7,
363
+ entityNode: 6,
364
+ // Deprecated
365
+ processingInstruction: 7,
257
366
  comment: 8,
258
- document: 9};
367
+ document: 9,
368
+ documentType: 10,
369
+ documentFragment: 11,
370
+ notation: 12 // Deprecated
371
+ };
259
372
  const getGlobal = function getGlobal() {
260
373
  return typeof window === 'undefined' ? null : window;
261
374
  };
@@ -310,10 +423,25 @@ var purify = {exports: {}};
310
423
  uponSanitizeShadowNode: []
311
424
  };
312
425
  };
426
+ /**
427
+ * Resolve a set-valued configuration option: a fresh set built from
428
+ * cfg[key] when it is an own array property (seeded with a clone of
429
+ * options.base when given, case-normalized via options.transform),
430
+ * the fallback set otherwise.
431
+ *
432
+ * @param cfg the cloned, prototype-free configuration object
433
+ * @param key the configuration property to read
434
+ * @param fallback the set to use when the option is absent or not an array
435
+ * @param options transform and optional base set to merge into
436
+ * @returns the resolved set
437
+ */
438
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
439
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
440
+ };
313
441
  function createDOMPurify() {
314
442
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
315
443
  const DOMPurify = root => createDOMPurify(root);
316
- DOMPurify.version = '3.4.0';
444
+ DOMPurify.version = '3.4.11';
317
445
  DOMPurify.removed = [];
318
446
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
319
447
  // Not running in a browser, provide a factory function
@@ -321,28 +449,25 @@ var purify = {exports: {}};
321
449
  DOMPurify.isSupported = false;
322
450
  return DOMPurify;
323
451
  }
324
- let {
325
- document
326
- } = window;
452
+ let document = window.document;
327
453
  const originalDocument = document;
328
454
  const currentScript = originalDocument.currentScript;
329
- const {
330
- DocumentFragment,
331
- HTMLTemplateElement,
332
- Node,
333
- Element,
334
- NodeFilter,
335
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
336
- HTMLFormElement,
337
- DOMParser,
338
- trustedTypes
339
- } = window;
455
+ const HTMLTemplateElement = window.HTMLTemplateElement,
456
+ Node = window.Node,
457
+ Element = window.Element,
458
+ NodeFilter = window.NodeFilter;
459
+ const DOMParser = window.DOMParser,
460
+ trustedTypes = window.trustedTypes;
340
461
  const ElementPrototype = Element.prototype;
341
462
  const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
342
463
  const remove = lookupGetter(ElementPrototype, 'remove');
343
464
  const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
344
465
  const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
345
466
  const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
467
+ const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
468
+ const getAttributes = lookupGetter(ElementPrototype, 'attributes');
469
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
470
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
346
471
  // As per issue #47, the web-components registry is inherited by a
347
472
  // new document created via createHTMLDocument. As per the spec
348
473
  // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
@@ -357,33 +482,74 @@ var purify = {exports: {}};
357
482
  }
358
483
  let trustedTypesPolicy;
359
484
  let emptyHTML = '';
360
- const {
361
- implementation,
362
- createNodeIterator,
363
- createDocumentFragment,
364
- getElementsByTagName
365
- } = document;
366
- const {
367
- importNode
368
- } = originalDocument;
485
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
486
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
487
+ // on duplicate policy names — and is the only policy allowed to persist
488
+ // across configurations and survive `clearConfig()`.
489
+ let defaultTrustedTypesPolicy;
490
+ let defaultTrustedTypesPolicyResolved = false;
491
+ // Tracks whether we are already inside a call to the configured Trusted Types
492
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
493
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
494
+ // re-enter the policy and recurse until the stack overflows. We detect that
495
+ // re-entry and throw a clear, actionable error instead. The guard is shared
496
+ // across both callbacks, because either one re-entering `sanitize` triggers
497
+ // the same unbounded recursion.
498
+ let IN_TRUSTED_TYPES_POLICY = 0;
499
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
500
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
501
+ 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.');
502
+ }
503
+ };
504
+ const _createTrustedHTML = function _createTrustedHTML(html) {
505
+ _assertNotInTrustedTypesPolicy();
506
+ IN_TRUSTED_TYPES_POLICY++;
507
+ try {
508
+ return trustedTypesPolicy.createHTML(html);
509
+ } finally {
510
+ IN_TRUSTED_TYPES_POLICY--;
511
+ }
512
+ };
513
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
514
+ _assertNotInTrustedTypesPolicy();
515
+ IN_TRUSTED_TYPES_POLICY++;
516
+ try {
517
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
518
+ } finally {
519
+ IN_TRUSTED_TYPES_POLICY--;
520
+ }
521
+ };
522
+ // Lazily resolve (and cache) the instance's internal default policy.
523
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
524
+ // repeated (Trusted Types throws on duplicate names), and a failed or
525
+ // unsupported attempt must not be retried on every parse.
526
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
527
+ if (!defaultTrustedTypesPolicyResolved) {
528
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
529
+ defaultTrustedTypesPolicyResolved = true;
530
+ }
531
+ return defaultTrustedTypesPolicy;
532
+ };
533
+ const _document = document,
534
+ implementation = _document.implementation,
535
+ createNodeIterator = _document.createNodeIterator,
536
+ createDocumentFragment = _document.createDocumentFragment,
537
+ getElementsByTagName = _document.getElementsByTagName;
538
+ const importNode = originalDocument.importNode;
369
539
  let hooks = _createHooksMap();
370
540
  /**
371
541
  * Expose whether this browser supports running the full DOMPurify.
372
542
  */
373
543
  DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
374
- const {
375
- MUSTACHE_EXPR,
376
- ERB_EXPR,
377
- TMPLIT_EXPR,
378
- DATA_ATTR,
379
- ARIA_ATTR,
380
- IS_SCRIPT_OR_DATA,
381
- ATTR_WHITESPACE,
382
- CUSTOM_ELEMENT
383
- } = EXPRESSIONS;
384
- let {
385
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
386
- } = EXPRESSIONS;
544
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
545
+ ERB_EXPR$1 = ERB_EXPR,
546
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
547
+ DATA_ATTR$1 = DATA_ATTR,
548
+ ARIA_ATTR$1 = ARIA_ATTR,
549
+ IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
550
+ ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
551
+ CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
552
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
387
553
  /**
388
554
  * We consider the elements and attributes below to be safe. Ideally
389
555
  * don't add any new ones but feel free to remove unwanted ones.
@@ -460,6 +626,13 @@ var purify = {exports: {}};
460
626
  let WHOLE_DOCUMENT = false;
461
627
  /* Track whether config is already set on this instance of DOMPurify. */
462
628
  let SET_CONFIG = false;
629
+ /* Pristine allowlist bindings captured at setConfig() time. On the
630
+ * persistent-config path sanitize() restores the sets from these before
631
+ * the per-walk hook clone-guard, so a hook's in-call widening cannot
632
+ * carry across calls. Null until setConfig() is called; reset by
633
+ * clearConfig(). */
634
+ let SET_CONFIG_ALLOWED_TAGS = null;
635
+ let SET_CONFIG_ALLOWED_ATTR = null;
463
636
  /* Decide if all elements (e.g. style, script) must be children of
464
637
  * document.body. By default, browsers might move them to document.head */
465
638
  let FORCE_BODY = false;
@@ -502,7 +675,17 @@ var purify = {exports: {}};
502
675
  let USE_PROFILES = {};
503
676
  /* Tags to ignore content of when KEEP_CONTENT is true */
504
677
  let FORBID_CONTENTS = null;
505
- 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']);
678
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
679
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
680
+ // the UA (customizable <select>) — including any on* handlers — and the
681
+ // engine re-mirrors synchronously whenever a removal changes which
682
+ // option/selectedcontent is current, even inside DOMPurify's inert
683
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
684
+ // mirror target ahead of the walk, which the engine refills, looping
685
+ // forever (DoS) and amplifying output. Dropping its content on removal
686
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
687
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
688
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
506
689
  /* Tags that are safe for data: URIs */
507
690
  let DATA_URI_TAGS = null;
508
691
  const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
@@ -518,8 +701,10 @@ var purify = {exports: {}};
518
701
  /* Allowed XHTML+XML namespaces */
519
702
  let ALLOWED_NAMESPACES = null;
520
703
  const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
521
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
522
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
704
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
705
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
706
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
707
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
523
708
  // Certain elements are allowed in both SVG and HTML
524
709
  // namespace. We need to specify them explicitly
525
710
  // so that they don't get erroneously deleted from
@@ -561,15 +746,33 @@ var purify = {exports: {}};
561
746
  // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
562
747
  transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
563
748
  /* Set configuration parameters */
564
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
565
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
566
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
567
- 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;
568
- 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;
569
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
570
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
571
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
572
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
749
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
750
+ transform: transformCaseFunc
751
+ });
752
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
753
+ transform: transformCaseFunc
754
+ });
755
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
756
+ transform: stringToString
757
+ });
758
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
759
+ transform: transformCaseFunc,
760
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
761
+ });
762
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
763
+ transform: transformCaseFunc,
764
+ base: DEFAULT_DATA_URI_TAGS
765
+ });
766
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
767
+ transform: transformCaseFunc
768
+ });
769
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
770
+ transform: transformCaseFunc
771
+ });
772
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
773
+ transform: transformCaseFunc
774
+ });
775
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
573
776
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
574
777
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
575
778
  ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
@@ -585,20 +788,22 @@ var purify = {exports: {}};
585
788
  SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
586
789
  KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
587
790
  IN_PLACE = cfg.IN_PLACE || false; // Default false
588
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
589
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
590
- MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
591
- HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
592
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || create(null);
593
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
594
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
595
- }
596
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
597
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
598
- }
599
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
600
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
601
- }
791
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
792
+ NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
793
+ 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
794
+ 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
795
+ const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
796
+ CUSTOM_ELEMENT_HANDLING = create(null);
797
+ if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
798
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
799
+ }
800
+ if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
801
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
802
+ }
803
+ if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
804
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
805
+ }
806
+ seal(CUSTOM_ELEMENT_HANDLING);
602
807
  if (SAFE_FOR_TEMPLATES) {
603
808
  ALLOW_DATA_ATTR = false;
604
809
  }
@@ -634,36 +839,36 @@ var purify = {exports: {}};
634
839
  EXTRA_ELEMENT_HANDLING.tagCheck = null;
635
840
  EXTRA_ELEMENT_HANDLING.attributeCheck = null;
636
841
  /* Merge configuration parameters */
637
- if (cfg.ADD_TAGS) {
842
+ if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
638
843
  if (typeof cfg.ADD_TAGS === 'function') {
639
844
  EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
640
- } else {
845
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
641
846
  if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
642
847
  ALLOWED_TAGS = clone(ALLOWED_TAGS);
643
848
  }
644
849
  addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
645
850
  }
646
851
  }
647
- if (cfg.ADD_ATTR) {
852
+ if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
648
853
  if (typeof cfg.ADD_ATTR === 'function') {
649
854
  EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
650
- } else {
855
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
651
856
  if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
652
857
  ALLOWED_ATTR = clone(ALLOWED_ATTR);
653
858
  }
654
859
  addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
655
860
  }
656
861
  }
657
- if (cfg.ADD_URI_SAFE_ATTR) {
862
+ if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
658
863
  addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
659
864
  }
660
- if (cfg.FORBID_CONTENTS) {
865
+ if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
661
866
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
662
867
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
663
868
  }
664
869
  addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
665
870
  }
666
- if (cfg.ADD_FORBID_CONTENTS) {
871
+ if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
667
872
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
668
873
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
669
874
  }
@@ -682,6 +887,13 @@ var purify = {exports: {}};
682
887
  addToSet(ALLOWED_TAGS, ['tbody']);
683
888
  delete FORBID_TAGS.tbody;
684
889
  }
890
+ // Re-derive the active Trusted Types policy from this configuration on
891
+ // every parse. The active policy must never be sticky closure state that
892
+ // outlives the config that set it: a caller-supplied policy left in place
893
+ // after `clearConfig()` — or after a later call that supplied none, or
894
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
895
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
896
+ // See GHSA-vxr8-fq34-vvx9.
685
897
  if (cfg.TRUSTED_TYPES_POLICY) {
686
898
  if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
687
899
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
@@ -689,18 +901,45 @@ var purify = {exports: {}};
689
901
  if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
690
902
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
691
903
  }
692
- // Overwrite existing TrustedTypes policy.
904
+ // A caller-supplied policy applies to this configuration only.
905
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
693
906
  trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
694
- // Sign local variables required by `sanitize`.
695
- emptyHTML = trustedTypesPolicy.createHTML('');
907
+ // Sign local variables required by `sanitize`. If the supplied policy's
908
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
909
+ // throws via the re-entrancy guard. Restore the previous policy first so
910
+ // the instance is not left in a poisoned state. See #1422.
911
+ try {
912
+ emptyHTML = _createTrustedHTML('');
913
+ } catch (error) {
914
+ trustedTypesPolicy = previousTrustedTypesPolicy;
915
+ throw error;
916
+ }
917
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
918
+ // Explicit opt-out for this call: perform no Trusted Types signing and
919
+ // create nothing (so a strict `trusted-types` CSP that disallows a
920
+ // `dompurify` policy can still call `sanitize` from inside its own
921
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
922
+ // `null` also drops any previously retained caller policy, so it cannot
923
+ // resurface on a later call, while still allowing the next config-less
924
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
925
+ trustedTypesPolicy = undefined;
926
+ emptyHTML = '';
696
927
  } else {
697
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
928
+ // No policy supplied: keep the currently active policy if one is set — a
929
+ // previously supplied policy is intentionally sticky across config-less
930
+ // calls — otherwise fall back to the instance's own internal policy,
931
+ // created at most once. (A policy supplied for a *single* call still
932
+ // lingers by design; what must not linger is a policy whose configuration
933
+ // has been torn down via `clearConfig()`, which restores the default.)
698
934
  if (trustedTypesPolicy === undefined) {
699
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
935
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
700
936
  }
701
- // If creating the internal policy succeeded sign internal variables.
702
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
703
- emptyHTML = trustedTypesPolicy.createHTML('');
937
+ // Sign internal variables only when a policy is active. A falsy policy
938
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
939
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
940
+ // a non-policy and throw. See #1422.
941
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
942
+ emptyHTML = _createTrustedHTML('');
704
943
  }
705
944
  }
706
945
  // Prevent further manipulation of configuration.
@@ -715,6 +954,77 @@ var purify = {exports: {}};
715
954
  * correctly. */
716
955
  const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
717
956
  const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
957
+ /**
958
+ * Namespace rules for an element in the SVG namespace.
959
+ *
960
+ * @param tagName the element's lowercase tag name
961
+ * @param parent the (possibly simulated) parent node
962
+ * @param parentTagName the parent's lowercase tag name
963
+ * @returns true if a spec-compliant parser could produce this element
964
+ */
965
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
966
+ // The only way to switch from HTML namespace to SVG
967
+ // is via <svg>. If it happens via any other tag, then
968
+ // it should be killed.
969
+ if (parent.namespaceURI === HTML_NAMESPACE) {
970
+ return tagName === 'svg';
971
+ }
972
+ // The only way to switch from MathML to SVG is via <svg>
973
+ // if the parent is either <annotation-xml> or a MathML
974
+ // text integration point.
975
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
976
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
977
+ }
978
+ // We only allow elements that are defined in SVG
979
+ // spec. All others are disallowed in SVG namespace.
980
+ return Boolean(ALL_SVG_TAGS[tagName]);
981
+ };
982
+ /**
983
+ * Namespace rules for an element in the MathML namespace.
984
+ *
985
+ * @param tagName the element's lowercase tag name
986
+ * @param parent the (possibly simulated) parent node
987
+ * @param parentTagName the parent's lowercase tag name
988
+ * @returns true if a spec-compliant parser could produce this element
989
+ */
990
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
991
+ // The only way to switch from HTML namespace to MathML
992
+ // is via <math>. If it happens via any other tag, then
993
+ // it should be killed.
994
+ if (parent.namespaceURI === HTML_NAMESPACE) {
995
+ return tagName === 'math';
996
+ }
997
+ // The only way to switch from SVG to MathML is via
998
+ // <math> and HTML integration points
999
+ if (parent.namespaceURI === SVG_NAMESPACE) {
1000
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
1001
+ }
1002
+ // We only allow elements that are defined in MathML
1003
+ // spec. All others are disallowed in MathML namespace.
1004
+ return Boolean(ALL_MATHML_TAGS[tagName]);
1005
+ };
1006
+ /**
1007
+ * Namespace rules for an element in the HTML namespace.
1008
+ *
1009
+ * @param tagName the element's lowercase tag name
1010
+ * @param parent the (possibly simulated) parent node
1011
+ * @param parentTagName the parent's lowercase tag name
1012
+ * @returns true if a spec-compliant parser could produce this element
1013
+ */
1014
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
1015
+ // The only way to switch from SVG to HTML is via
1016
+ // HTML integration points, and from MathML to HTML
1017
+ // is via MathML text integration points
1018
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
1019
+ return false;
1020
+ }
1021
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
1022
+ return false;
1023
+ }
1024
+ // We disallow tags that are specific for MathML
1025
+ // or SVG and should never appear in HTML namespace
1026
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1027
+ };
718
1028
  /**
719
1029
  * @param element a DOM element whose namespace is being checked
720
1030
  * @returns Return false if the element has a
@@ -737,51 +1047,13 @@ var purify = {exports: {}};
737
1047
  return false;
738
1048
  }
739
1049
  if (element.namespaceURI === SVG_NAMESPACE) {
740
- // The only way to switch from HTML namespace to SVG
741
- // is via <svg>. If it happens via any other tag, then
742
- // it should be killed.
743
- if (parent.namespaceURI === HTML_NAMESPACE) {
744
- return tagName === 'svg';
745
- }
746
- // The only way to switch from MathML to SVG is via`
747
- // svg if parent is either <annotation-xml> or MathML
748
- // text integration points.
749
- if (parent.namespaceURI === MATHML_NAMESPACE) {
750
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
751
- }
752
- // We only allow elements that are defined in SVG
753
- // spec. All others are disallowed in SVG namespace.
754
- return Boolean(ALL_SVG_TAGS[tagName]);
1050
+ return _checkSvgNamespace(tagName, parent, parentTagName);
755
1051
  }
756
1052
  if (element.namespaceURI === MATHML_NAMESPACE) {
757
- // The only way to switch from HTML namespace to MathML
758
- // is via <math>. If it happens via any other tag, then
759
- // it should be killed.
760
- if (parent.namespaceURI === HTML_NAMESPACE) {
761
- return tagName === 'math';
762
- }
763
- // The only way to switch from SVG to MathML is via
764
- // <math> and HTML integration points
765
- if (parent.namespaceURI === SVG_NAMESPACE) {
766
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
767
- }
768
- // We only allow elements that are defined in MathML
769
- // spec. All others are disallowed in MathML namespace.
770
- return Boolean(ALL_MATHML_TAGS[tagName]);
1053
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
771
1054
  }
772
1055
  if (element.namespaceURI === HTML_NAMESPACE) {
773
- // The only way to switch from SVG to HTML is via
774
- // HTML integration points, and from MathML to HTML
775
- // is via MathML text integration points
776
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
777
- return false;
778
- }
779
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
780
- return false;
781
- }
782
- // We disallow tags that are specific for MathML
783
- // or SVG and should never appear in HTML namespace
784
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1056
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
785
1057
  }
786
1058
  // For XHTML and XML documents that support custom namespaces
787
1059
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
@@ -806,7 +1078,74 @@ var purify = {exports: {}};
806
1078
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
807
1079
  getParentNode(node).removeChild(node);
808
1080
  } catch (_) {
1081
+ /* The normal detach failed — this is reached for a parentless node
1082
+ (getParentNode() is null, so .removeChild throws). Element.prototype
1083
+ .remove() is itself a spec no-op on a parentless node, so a recorded
1084
+ "removal" would otherwise hand the caller back an intact,
1085
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
1086
+ the style-with-element-child rule decided to kill). Fail closed by
1087
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
1088
+ rather than trying to "neutralize" the node via its own methods.
1089
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
1090
+ on the node, both of which a <form> root can clobber via a named child
1091
+ (and _isClobbered does not even probe getAttributeNames), so the
1092
+ neutralize step could itself be silently defeated, leaving the payload
1093
+ intact. A throw touches only the cached, clobber-safe remove() and
1094
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
1095
+ to every root-kill reason. REPORT-3.
1096
+ This lives inside the catch, so it never fires for a normally-removed
1097
+ in-tree node: those have a parent, removeChild() succeeds, and the
1098
+ catch is not entered. Only a kept (parentless) root reaches here. */
809
1099
  remove(node);
1100
+ if (!getParentNode(node)) {
1101
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
1102
+ }
1103
+ }
1104
+ };
1105
+ /**
1106
+ * _neutralizeRoot
1107
+ *
1108
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
1109
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
1110
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
1111
+ * parentless guard throws, or any other re-entrant engine mutation — would
1112
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
1113
+ * after the abort point still carrying its handlers. There is no safe way
1114
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
1115
+ * remove every child and every attribute, then let the caller's catch see
1116
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
1117
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
1118
+ *
1119
+ * @param root the in-place root to empty
1120
+ */
1121
+ const _neutralizeRoot = function _neutralizeRoot(root) {
1122
+ const childNodes = getChildNodes(root);
1123
+ if (childNodes) {
1124
+ const snapshot = [];
1125
+ arrayForEach(childNodes, child => {
1126
+ arrayPush(snapshot, child);
1127
+ });
1128
+ arrayForEach(snapshot, child => {
1129
+ try {
1130
+ remove(child);
1131
+ } catch (_) {
1132
+ /* Best-effort teardown; a still-attached child is handled below */
1133
+ }
1134
+ });
1135
+ }
1136
+ const attributes = getAttributes(root);
1137
+ if (attributes) {
1138
+ for (let i = attributes.length - 1; i >= 0; --i) {
1139
+ const attribute = attributes[i];
1140
+ const name = attribute && attribute.name;
1141
+ if (typeof name === 'string') {
1142
+ try {
1143
+ root.removeAttribute(name);
1144
+ } catch (_) {
1145
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
1146
+ }
1147
+ }
1148
+ }
810
1149
  }
811
1150
  };
812
1151
  /**
@@ -841,6 +1180,72 @@ var purify = {exports: {}};
841
1180
  }
842
1181
  }
843
1182
  };
1183
+ /**
1184
+ * _stripDisallowedAttributes
1185
+ *
1186
+ * Removes every attribute the active configuration does not allow from a
1187
+ * single element, using the same allowlist as the main attribute pass (so
1188
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
1189
+ * neutralise nodes that are being discarded from an in-place tree.
1190
+ *
1191
+ * @param element the element to strip
1192
+ */
1193
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
1194
+ const attributes = getAttributes(element);
1195
+ if (!attributes) {
1196
+ return;
1197
+ }
1198
+ for (let i = attributes.length - 1; i >= 0; --i) {
1199
+ const attribute = attributes[i];
1200
+ const name = attribute && attribute.name;
1201
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
1202
+ continue;
1203
+ }
1204
+ try {
1205
+ element.removeAttribute(name);
1206
+ } catch (_) {
1207
+ /* Clobbered removeAttribute on a doomed node — ignore */
1208
+ }
1209
+ }
1210
+ };
1211
+ /**
1212
+ * _neutralizeSubtree
1213
+ *
1214
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
1215
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
1216
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
1217
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
1218
+ * those dropped nodes are detached from the caller's LIVE tree but a
1219
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
1220
+ * loading) keeps its queued resource event, which fires in page scope after
1221
+ * sanitize returns. This walks a removed subtree and strips every attribute
1222
+ * the active configuration does not allow — so `on*` handlers are cancelled
1223
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
1224
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
1225
+ * queued event can fire. Hook-free by design: these nodes leave the output,
1226
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
1227
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
1228
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
1229
+ * the `<img>`, are reached and scrubbed).
1230
+ *
1231
+ * @param root the root of a removed subtree to neutralise
1232
+ */
1233
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
1234
+ const stack = [root];
1235
+ while (stack.length > 0) {
1236
+ const node = stack.pop();
1237
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1238
+ if (nodeType === NODE_TYPE.element) {
1239
+ _stripDisallowedAttributes(node);
1240
+ }
1241
+ const childNodes = getChildNodes(node);
1242
+ if (childNodes) {
1243
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1244
+ stack.push(childNodes[i]);
1245
+ }
1246
+ }
1247
+ }
1248
+ };
844
1249
  /**
845
1250
  * _initDocument
846
1251
  *
@@ -862,7 +1267,7 @@ var purify = {exports: {}};
862
1267
  // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
863
1268
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
864
1269
  }
865
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
1270
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
866
1271
  /*
867
1272
  * Use the DOMParser API by default, fallback later if needs be
868
1273
  * DOMParser not work for svg when has multiple root element.
@@ -902,29 +1307,254 @@ var purify = {exports: {}};
902
1307
  // eslint-disable-next-line no-bitwise
903
1308
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
904
1309
  };
1310
+ /**
1311
+ * Replace template expression syntax (mustache, ERB, template
1312
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
1313
+ * sites. Order matters: mustache, then ERB, then template literal.
1314
+ *
1315
+ * @param value the string to scrub
1316
+ * @returns the scrubbed string
1317
+ */
1318
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
1319
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
1320
+ value = stringReplace(value, ERB_EXPR$1, ' ');
1321
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
1322
+ return value;
1323
+ };
1324
+ /**
1325
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
1326
+ * character data of an element subtree. Used as the final safety net for
1327
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
1328
+ * which only form after text-node normalization (e.g. fragments split across
1329
+ * stripped elements) cannot survive into a template-evaluating framework.
1330
+ *
1331
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
1332
+ * in place rather than round-tripping through innerHTML. This preserves
1333
+ * descendant node references (important for IN_PLACE callers), avoids a
1334
+ * serialize/reparse cycle, and reads literal character data — which means
1335
+ * `<%...%>` in text content matches the ERB regex against its real bytes
1336
+ * instead of the HTML-entity-escaped form innerHTML would produce.
1337
+ *
1338
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
1339
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
1340
+ *
1341
+ * @param node The root element whose character data should be scrubbed.
1342
+ */
1343
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
1344
+ var _node$querySelectorAl;
1345
+ node.normalize();
1346
+ const walker = createNodeIterator.call(node.ownerDocument || node, node,
1347
+ // eslint-disable-next-line no-bitwise
1348
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
1349
+ let currentNode = walker.nextNode();
1350
+ while (currentNode) {
1351
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
1352
+ currentNode = walker.nextNode();
1353
+ }
1354
+ // NodeIterator does not descend into <template>.content per the DOM spec,
1355
+ // so we must explicitly recurse into each template's content fragment,
1356
+ // mirroring the approach used by _sanitizeShadowDOM.
1357
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
1358
+ if (templates) {
1359
+ arrayForEach(templates, tmpl => {
1360
+ if (_isDocumentFragment(tmpl.content)) {
1361
+ _scrubTemplateExpressions2(tmpl.content);
1362
+ }
1363
+ });
1364
+ }
1365
+ };
905
1366
  /**
906
1367
  * _isClobbered
907
1368
  *
1369
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
1370
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
1371
+ * `name` attribute matching a prototype property shadows that property
1372
+ * on direct reads. We use this check at the IN_PLACE entry-point and
1373
+ * during attribute sanitization to refuse clobbered forms.
1374
+ *
908
1375
  * @param element element to check for clobbering attacks
909
1376
  * @return true if clobbered, false if safe
910
1377
  */
911
1378
  const _isClobbered = function _isClobbered(element) {
912
- 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');
1379
+ // Realm-independent tag-name probe. If we can't determine the tag
1380
+ // name at all, we can't reason about clobbering — return false
1381
+ // (the caller's other defences still apply).
1382
+ const realTagName = getNodeName ? getNodeName(element) : null;
1383
+ if (typeof realTagName !== 'string') {
1384
+ return false;
1385
+ }
1386
+ if (transformCaseFunc(realTagName) !== 'form') {
1387
+ return false;
1388
+ }
1389
+ return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
1390
+ // Realm-safe NamedNodeMap detection: equality against the cached
1391
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
1392
+ // makes the direct read diverge from the cached read; a clean form
1393
+ // (same-realm OR foreign-realm) has both reads pointing at the same
1394
+ // canonical NamedNodeMap.
1395
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
1396
+ // NodeType clobbering probe. Cached Node.prototype.nodeType getter
1397
+ // returns the integer 1 for any Element regardless of realm; direct
1398
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
1399
+ // the named child element. Cheap addition — nodeType is read from
1400
+ // an internal slot, no serialization cost — and removes a residual
1401
+ // clobbering surface used by several mXSS / PI / comment branches
1402
+ // in _sanitizeElements that compare currentNode.nodeType directly.
1403
+ element.nodeType !== getNodeType(element) ||
1404
+ // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
1405
+ // "childNodes" shadows the prototype getter. Direct reads of
1406
+ // form.childNodes from a clobbered form return the named child
1407
+ // instead of the real NodeList, so any walk that reads it directly
1408
+ // skips the form's real children. Compare the direct read to the
1409
+ // cached Node.prototype getter — when the form's named-property
1410
+ // getter intercepts the read, the two values differ and we flag
1411
+ // the form. This catches every clobbering child type (input,
1412
+ // select, etc.) regardless of whether the named child happens to
1413
+ // carry a numeric .length, which a typeof-based probe would miss
1414
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
1415
+ element.childNodes !== getChildNodes(element);
913
1416
  };
914
1417
  /**
915
- * Checks whether the given object is a DOM node.
1418
+ * Checks whether the given value is a DocumentFragment from any realm.
1419
+ *
1420
+ * The realm-independent replacement reads `nodeType` through the cached
1421
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
1422
+ * constant (11). nodeType is a numeric value resolved from the node's
1423
+ * internal slot, identical across realms for the same kind of node.
1424
+ *
1425
+ * @param value object to check
1426
+ * @return true if value is a DocumentFragment-shaped node from any realm
1427
+ */
1428
+ const _isDocumentFragment = function _isDocumentFragment(value) {
1429
+ if (!getNodeType || typeof value !== 'object' || value === null) {
1430
+ return false;
1431
+ }
1432
+ try {
1433
+ return getNodeType(value) === NODE_TYPE.documentFragment;
1434
+ } catch (_) {
1435
+ return false;
1436
+ }
1437
+ };
1438
+ /**
1439
+ * Checks whether the given object is a DOM node, including nodes that
1440
+ * originate from a different window/realm (e.g. an iframe's
1441
+ * contentDocument). The previous `value instanceof Node` check was
1442
+ * realm-bound: nodes from a different window failed it, causing
1443
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
1444
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
916
1445
  *
917
1446
  * @param value object to check whether it's a DOM node
918
- * @return true is object is a DOM node
1447
+ * @return true if value is a DOM node from any realm
919
1448
  */
920
1449
  const _isNode = function _isNode(value) {
921
- return typeof Node === 'function' && value instanceof Node;
1450
+ if (!getNodeType || typeof value !== 'object' || value === null) {
1451
+ return false;
1452
+ }
1453
+ try {
1454
+ return typeof getNodeType(value) === 'number';
1455
+ } catch (_) {
1456
+ return false;
1457
+ }
922
1458
  };
923
1459
  function _executeHooks(hooks, currentNode, data) {
1460
+ if (hooks.length === 0) {
1461
+ return;
1462
+ }
924
1463
  arrayForEach(hooks, hook => {
925
1464
  hook.call(DOMPurify, currentNode, data, CONFIG);
926
1465
  });
927
1466
  }
1467
+ /**
1468
+ * Structural-threat checks that condemn a node regardless of the
1469
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
1470
+ * processing instructions, markup-bearing comments. Pure predicate;
1471
+ * the caller removes. Check order is load-bearing.
1472
+ *
1473
+ * @param currentNode the node to inspect
1474
+ * @param tagName the node's transformCaseFunc'd tag name
1475
+ * @return true if the node must be removed
1476
+ */
1477
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
1478
+ /* Detect mXSS attempts abusing namespace confusion */
1479
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
1480
+ return true;
1481
+ }
1482
+ /* Remove risky CSS construction leading to mXSS */
1483
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
1484
+ return true;
1485
+ }
1486
+ /* Remove any occurrence of processing instructions */
1487
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
1488
+ return true;
1489
+ }
1490
+ /* Remove any kind of possibly harmful comments */
1491
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
1492
+ return true;
1493
+ }
1494
+ return false;
1495
+ };
1496
+ /**
1497
+ * Handle a node whose tag is forbidden or not allowlisted: keep
1498
+ * allowed custom elements (false return exits _sanitizeElements
1499
+ * early - namespace/fallback checks and the afterSanitizeElements
1500
+ * hook are intentionally skipped for kept custom elements), else
1501
+ * hoist content per KEEP_CONTENT and remove.
1502
+ *
1503
+ * @param currentNode the disallowed node
1504
+ * @param tagName the node's transformCaseFunc'd tag name
1505
+ * @return true if the node was removed, false if kept
1506
+ */
1507
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
1508
+ /* Check if we have a custom element to handle */
1509
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
1510
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1511
+ return false;
1512
+ }
1513
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
1514
+ return false;
1515
+ }
1516
+ }
1517
+ /* Keep content except for bad-listed elements.
1518
+ Use the cached prototype getters exclusively — the previous code
1519
+ had `|| currentNode.parentNode` / `|| currentNode.childNodes`
1520
+ fallbacks, but the cached getters always return the canonical
1521
+ value (or null for a real parent-less node), so the fallback
1522
+ path was dead in safe cases and a clobbering surface in unsafe
1523
+ ones. Falsy cached results stay falsy; the `if (childNodes &&
1524
+ parentNode)` check already gates correctly. */
1525
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1526
+ const parentNode = getParentNode(currentNode);
1527
+ const childNodes = getChildNodes(currentNode);
1528
+ if (childNodes && parentNode) {
1529
+ const childCount = childNodes.length;
1530
+ /* In-place: hoist the *original* children so the iterator visits
1531
+ and sanitises them through the same allowlist pass as every other
1532
+ node. The caller built the tree in the live document, so the
1533
+ originals carry already-queued resource events (`<img onerror>`,
1534
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
1535
+ those originals detached but still armed, firing in page scope
1536
+ while the returned tree looked clean. Moving is safe in-place: the
1537
+ root is pre-validated as an allowed tag and so is never the node
1538
+ being removed, which keeps `parentNode` inside the iterator root
1539
+ and the relocated child inside the serialised tree.
1540
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
1541
+ at — and the result serialised from — `body`, so a restrictive
1542
+ ALLOWED_TAGS that removes `body` itself must leave its content in
1543
+ place, which only cloning does; and those paths parse into an
1544
+ inert document, so their discarded originals never had a queued
1545
+ event to neutralise.
1546
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
1547
+ valid whether we move (drops the trailing entry) or clone (leaves
1548
+ the list intact). */
1549
+ for (let i = childCount - 1; i >= 0; --i) {
1550
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
1551
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
1552
+ }
1553
+ }
1554
+ }
1555
+ _forceRemove(currentNode);
1556
+ return true;
1557
+ };
928
1558
  /**
929
1559
  * _sanitizeElements
930
1560
  *
@@ -935,7 +1565,6 @@ var purify = {exports: {}};
935
1565
  * @return true if node was killed, false if left alive
936
1566
  */
937
1567
  const _sanitizeElements = function _sanitizeElements(currentNode) {
938
- let content = null;
939
1568
  /* Execute a hook if present */
940
1569
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
941
1570
  /* Check if element is clobbered or can clobber */
@@ -944,76 +1573,41 @@ var purify = {exports: {}};
944
1573
  return true;
945
1574
  }
946
1575
  /* Now let's check the element's type and name */
947
- const tagName = transformCaseFunc(currentNode.nodeName);
1576
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
948
1577
  /* Execute a hook if present */
949
1578
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
950
1579
  tagName,
951
1580
  allowedTags: ALLOWED_TAGS
952
1581
  });
953
- /* Detect mXSS attempts abusing namespace confusion */
954
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
955
- _forceRemove(currentNode);
956
- return true;
957
- }
958
- /* Remove risky CSS construction leading to mXSS */
959
- if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
960
- _forceRemove(currentNode);
961
- return true;
962
- }
963
- /* Remove any occurrence of processing instructions */
964
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
965
- _forceRemove(currentNode);
966
- return true;
967
- }
968
- /* Remove any kind of possibly harmful comments */
969
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
1582
+ /* Remove mXSS vectors, processing instructions and risky comments */
1583
+ if (_isUnsafeNode(currentNode, tagName)) {
970
1584
  _forceRemove(currentNode);
971
1585
  return true;
972
1586
  }
973
1587
  /* Remove element if anything forbids its presence */
974
1588
  if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
975
- /* Check if we have a custom element to handle */
976
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
977
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
978
- return false;
979
- }
980
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
981
- return false;
982
- }
983
- }
984
- /* Keep content except for bad-listed elements */
985
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
986
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
987
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
988
- if (childNodes && parentNode) {
989
- const childCount = childNodes.length;
990
- for (let i = childCount - 1; i >= 0; --i) {
991
- const childClone = cloneNode(childNodes[i], true);
992
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
993
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
994
- }
995
- }
996
- }
997
- _forceRemove(currentNode);
998
- return true;
999
- }
1000
- /* Check whether element has a valid namespace */
1001
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1589
+ return _sanitizeDisallowedNode(currentNode, tagName);
1590
+ }
1591
+ /* Check whether element has a valid namespace.
1592
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
1593
+ nodeType getter rather than `instanceof Element`, which is realm-
1594
+ bound and short-circuits to false for any node minted in a different
1595
+ realm — letting a foreign-realm element with a forbidden namespace
1596
+ slip past the namespace check entirely. */
1597
+ const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
1598
+ if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
1002
1599
  _forceRemove(currentNode);
1003
1600
  return true;
1004
1601
  }
1005
1602
  /* Make sure that older browsers don't get fallback-tag mXSS */
1006
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
1603
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
1007
1604
  _forceRemove(currentNode);
1008
1605
  return true;
1009
1606
  }
1010
1607
  /* Sanitize element content to be template-safe */
1011
1608
  if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1012
1609
  /* Get the element's text content */
1013
- content = currentNode.textContent;
1014
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1015
- content = stringReplace(content, expr, ' ');
1016
- });
1610
+ const content = _stripTemplateExpressions(currentNode.textContent);
1017
1611
  if (currentNode.textContent !== content) {
1018
1612
  arrayPush(DOMPurify.removed, {
1019
1613
  element: currentNode.cloneNode()
@@ -1043,11 +1637,12 @@ var purify = {exports: {}};
1043
1637
  if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1044
1638
  return false;
1045
1639
  }
1640
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
1046
1641
  /* Allow valid data-* attributes: At least one character after "-"
1047
1642
  (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1048
1643
  XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1049
1644
  We don't need to check the value; it's always URI safe. */
1050
- 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]) {
1645
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
1051
1646
  if (
1052
1647
  // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1053
1648
  // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
@@ -1059,11 +1654,15 @@ var purify = {exports: {}};
1059
1654
  return false;
1060
1655
  }
1061
1656
  /* Check value is safe. First, is attr inert? If so, is safe */
1062
- } 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) {
1657
+ } 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) {
1063
1658
  return false;
1064
1659
  } else ;
1065
1660
  return true;
1066
1661
  };
1662
+ /* Names the HTML spec reserves from valid-custom-element-name; these must
1663
+ * never be treated as basic custom elements even when a permissive
1664
+ * CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
1665
+ 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']);
1067
1666
  /**
1068
1667
  * _isBasicCustomElement
1069
1668
  * checks if at least one dash is included in tagName, and it's not the first char
@@ -1073,7 +1672,64 @@ var purify = {exports: {}};
1073
1672
  * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1074
1673
  */
1075
1674
  const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1076
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1675
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
1676
+ };
1677
+ /**
1678
+ * Wrap an attribute value in the matching Trusted Types object when
1679
+ * the active policy requires it. Namespaced attributes pass through
1680
+ * unchanged (no TT support yet, see
1681
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
1682
+ *
1683
+ * @param lcTag lowercase tag name of the containing element
1684
+ * @param lcName lowercase attribute name
1685
+ * @param namespaceURI the attribute's namespace, if any
1686
+ * @param value the attribute value to wrap
1687
+ * @return the value, wrapped when Trusted Types demand it
1688
+ */
1689
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
1690
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
1691
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1692
+ case 'TrustedHTML':
1693
+ {
1694
+ return _createTrustedHTML(value);
1695
+ }
1696
+ case 'TrustedScriptURL':
1697
+ {
1698
+ return _createTrustedScriptURL(value);
1699
+ }
1700
+ }
1701
+ }
1702
+ return value;
1703
+ };
1704
+ /**
1705
+ * Write a modified attribute value back onto the element. On
1706
+ * success, re-probe for clobbering introduced by the new value and
1707
+ * remove the element when found; otherwise pop the removal entry
1708
+ * recorded by the earlier _removeAttribute (long-standing pairing
1709
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
1710
+ * failure, remove the attribute instead.
1711
+ *
1712
+ * @param currentNode the element carrying the attribute
1713
+ * @param name the attribute name as present on the element
1714
+ * @param namespaceURI the attribute's namespace, if any
1715
+ * @param value the new attribute value
1716
+ */
1717
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
1718
+ try {
1719
+ if (namespaceURI) {
1720
+ currentNode.setAttributeNS(namespaceURI, name, value);
1721
+ } else {
1722
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1723
+ currentNode.setAttribute(name, value);
1724
+ }
1725
+ if (_isClobbered(currentNode)) {
1726
+ _forceRemove(currentNode);
1727
+ } else {
1728
+ arrayPop(DOMPurify.removed);
1729
+ }
1730
+ } catch (_) {
1731
+ _removeAttribute(name, currentNode);
1732
+ }
1077
1733
  };
1078
1734
  /**
1079
1735
  * _sanitizeAttributes
@@ -1088,9 +1744,7 @@ var purify = {exports: {}};
1088
1744
  const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1089
1745
  /* Execute a hook if present */
1090
1746
  _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1091
- const {
1092
- attributes
1093
- } = currentNode;
1747
+ const attributes = currentNode.attributes;
1094
1748
  /* Check if we have attributes; if not we might have a text node */
1095
1749
  if (!attributes || _isClobbered(currentNode)) {
1096
1750
  return;
@@ -1103,14 +1757,13 @@ var purify = {exports: {}};
1103
1757
  forceKeepAttr: undefined
1104
1758
  };
1105
1759
  let l = attributes.length;
1760
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1106
1761
  /* Go backwards over all attributes; safely remove bad ones */
1107
1762
  while (l--) {
1108
1763
  const attr = attributes[l];
1109
- const {
1110
- name,
1111
- namespaceURI,
1112
- value: attrValue
1113
- } = attr;
1764
+ const name = attr.name,
1765
+ namespaceURI = attr.namespaceURI,
1766
+ attrValue = attr.value;
1114
1767
  const lcName = transformCaseFunc(name);
1115
1768
  const initValue = attrValue;
1116
1769
  let value = name === 'value' ? initValue : stringTrim(initValue);
@@ -1124,12 +1777,14 @@ var purify = {exports: {}};
1124
1777
  /* Full DOM Clobbering protection via namespace isolation,
1125
1778
  * Prefix id and name attributes with `user-content-`
1126
1779
  */
1127
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1780
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
1128
1781
  // Remove the attribute with this value
1129
1782
  _removeAttribute(name, currentNode);
1130
1783
  // Prefix the value and later re-create the attribute with the sanitized value
1131
1784
  value = SANITIZE_NAMED_PROPS_PREFIX + value;
1132
1785
  }
1786
+ // Else: already prefixed, leave the attribute alone — the prefix is
1787
+ // itself the clobbering protection, and re-applying it is incorrect.
1133
1788
  /* Work around a security issue with comments inside attributes */
1134
1789
  if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
1135
1790
  _removeAttribute(name, currentNode);
@@ -1140,7 +1795,7 @@ var purify = {exports: {}};
1140
1795
  _removeAttribute(name, currentNode);
1141
1796
  continue;
1142
1797
  }
1143
- /* Did the hooks approve of the attribute? */
1798
+ /* Did the hooks force-keep the attribute? */
1144
1799
  if (hookEvent.forceKeepAttr) {
1145
1800
  continue;
1146
1801
  }
@@ -1150,56 +1805,24 @@ var purify = {exports: {}};
1150
1805
  continue;
1151
1806
  }
1152
1807
  /* Work around a security issue in jQuery 3.0 */
1153
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1808
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
1154
1809
  _removeAttribute(name, currentNode);
1155
1810
  continue;
1156
1811
  }
1157
1812
  /* Sanitize attribute content to be template-safe */
1158
1813
  if (SAFE_FOR_TEMPLATES) {
1159
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1160
- value = stringReplace(value, expr, ' ');
1161
- });
1814
+ value = _stripTemplateExpressions(value);
1162
1815
  }
1163
1816
  /* Is `value` valid for this attribute? */
1164
- const lcTag = transformCaseFunc(currentNode.nodeName);
1165
1817
  if (!_isValidAttribute(lcTag, lcName, value)) {
1166
1818
  _removeAttribute(name, currentNode);
1167
1819
  continue;
1168
1820
  }
1169
1821
  /* Handle attributes that require Trusted Types */
1170
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1171
- if (namespaceURI) ; else {
1172
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1173
- case 'TrustedHTML':
1174
- {
1175
- value = trustedTypesPolicy.createHTML(value);
1176
- break;
1177
- }
1178
- case 'TrustedScriptURL':
1179
- {
1180
- value = trustedTypesPolicy.createScriptURL(value);
1181
- break;
1182
- }
1183
- }
1184
- }
1185
- }
1822
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
1186
1823
  /* Handle invalid data-* attribute set by try-catching it */
1187
1824
  if (value !== initValue) {
1188
- try {
1189
- if (namespaceURI) {
1190
- currentNode.setAttributeNS(namespaceURI, name, value);
1191
- } else {
1192
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1193
- currentNode.setAttribute(name, value);
1194
- }
1195
- if (_isClobbered(currentNode)) {
1196
- _forceRemove(currentNode);
1197
- } else {
1198
- arrayPop(DOMPurify.removed);
1199
- }
1200
- } catch (_) {
1201
- _removeAttribute(name, currentNode);
1202
- }
1825
+ _setAttributeValue(currentNode, name, namespaceURI, value);
1203
1826
  }
1204
1827
  }
1205
1828
  /* Execute a hook if present */
@@ -1222,14 +1845,133 @@ var purify = {exports: {}};
1222
1845
  _sanitizeElements(shadowNode);
1223
1846
  /* Check attributes next */
1224
1847
  _sanitizeAttributes(shadowNode);
1225
- /* Deep shadow DOM detected */
1226
- if (shadowNode.content instanceof DocumentFragment) {
1848
+ /* Deep shadow DOM detected.
1849
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
1850
+ DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
1851
+ recurse into <template>.content from foreign realms too. */
1852
+ if (_isDocumentFragment(shadowNode.content)) {
1227
1853
  _sanitizeShadowDOM2(shadowNode.content);
1228
1854
  }
1855
+ /* An element iterated here may itself host an attached
1856
+ shadow root. The default NodeIterator does not enter shadow
1857
+ trees, so a shadow root nested inside template.content was
1858
+ previously reached by no walk at all (the pre-pass at
1859
+ _sanitizeAttachedShadowRoots descends via childNodes, which
1860
+ doesn't enter template.content; the template-content recursion
1861
+ above iterates the content but never inspected shadowRoot).
1862
+ Walk it explicitly. The nodeType guard avoids reading
1863
+ shadowRoot off text / comment / CDATA / PI nodes that the
1864
+ iterator also surfaces. */
1865
+ const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
1866
+ if (shadowNodeType === NODE_TYPE.element) {
1867
+ const innerSr = getShadowRoot(shadowNode);
1868
+ if (_isDocumentFragment(innerSr)) {
1869
+ _sanitizeAttachedShadowRoots(innerSr);
1870
+ _sanitizeShadowDOM2(innerSr);
1871
+ }
1872
+ }
1229
1873
  }
1230
1874
  /* Execute a hook if present */
1231
1875
  _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1232
1876
  };
1877
+ /**
1878
+ * _sanitizeAttachedShadowRoots
1879
+ *
1880
+ * Walks `root` and feeds every attached shadow root we encounter into
1881
+ * the existing _sanitizeShadowDOM pipeline. The default node iterator
1882
+ * does not descend into shadow trees, so nodes inside an attached
1883
+ * shadow root would otherwise be skipped entirely.
1884
+ *
1885
+ * Two real input paths put attached shadow roots in front of us:
1886
+ * 1. IN_PLACE on a DOM node that already has shadow roots attached.
1887
+ * 2. DOM-node input where importNode(dirty, true) deep-clones the
1888
+ * shadow root because it was created with `clonable: true`.
1889
+ *
1890
+ * This pass runs once, up front, so the main iteration loop (and the
1891
+ * existing _sanitizeShadowDOM template-content recursion) stay
1892
+ * untouched — string-input paths are not affected.
1893
+ *
1894
+ * @param root the subtree root to walk for attached shadow roots
1895
+ */
1896
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
1897
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
1898
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
1899
+ built straight into the DOM — the IN_PLACE surface) deeper than the JS
1900
+ call-stack budget would otherwise overflow native recursion here and
1901
+ throw at the IN_PLACE entry pre-pass, before a single node is
1902
+ sanitized, leaving the caller's live tree untouched (fail-open). See
1903
+ campaign-3 F4. A heap stack keeps depth off the call stack.
1904
+ Each work item is either a node to descend into, or a deferred
1905
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
1906
+ form preserves the original post-order discipline: a shadow root's
1907
+ nested shadow roots are discovered before the outer shadow is
1908
+ sanitized (which may remove hosts). Pushes are in reverse of the
1909
+ desired processing order (LIFO): template content, then children, then
1910
+ the shadow-sanitize, then the shadow walk — so the order matches the
1911
+ previous recursion exactly. */
1912
+ const stack = [{
1913
+ node: root,
1914
+ shadow: null
1915
+ }];
1916
+ while (stack.length > 0) {
1917
+ const item = stack.pop();
1918
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
1919
+ if (item.shadow) {
1920
+ _sanitizeShadowDOM2(item.shadow);
1921
+ continue;
1922
+ }
1923
+ const node = item.node;
1924
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1925
+ const isElement = nodeType === NODE_TYPE.element;
1926
+ /* (pushed last → processed first) Children, snapshotted in reverse so
1927
+ the first child is processed first. Snapshotting matters because a
1928
+ hook may detach siblings mid-walk. */
1929
+ const childNodes = getChildNodes(node);
1930
+ if (childNodes) {
1931
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1932
+ stack.push({
1933
+ node: childNodes[i],
1934
+ shadow: null
1935
+ });
1936
+ }
1937
+ }
1938
+ /* (pushed before children → processed after them, matching the old
1939
+ "template content last" order) When the node is a <template>,
1940
+ descend into its content. */
1941
+ if (isElement) {
1942
+ const rootName = getNodeName ? getNodeName(node) : null;
1943
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
1944
+ const content = node.content;
1945
+ if (_isDocumentFragment(content)) {
1946
+ stack.push({
1947
+ node: content,
1948
+ shadow: null
1949
+ });
1950
+ }
1951
+ }
1952
+ }
1953
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
1954
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
1955
+ rather than `instanceof DocumentFragment`, which is realm-bound and
1956
+ silently skipped foreign-realm shadow roots (e.g.
1957
+ iframe.contentDocument attachShadow). */
1958
+ if (isElement) {
1959
+ const sr = getShadowRoot(node);
1960
+ if (_isDocumentFragment(sr)) {
1961
+ /* Push the deferred sanitise first so it pops after the shadow
1962
+ walk we push next, i.e. nested shadow roots are discovered
1963
+ before this one is sanitised. */
1964
+ stack.push({
1965
+ node: null,
1966
+ shadow: sr
1967
+ }, {
1968
+ node: sr,
1969
+ shadow: null
1970
+ });
1971
+ }
1972
+ }
1973
+ }
1974
+ };
1233
1975
  // eslint-disable-next-line complexity
1234
1976
  DOMPurify.sanitize = function (dirty) {
1235
1977
  let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -1246,13 +1988,9 @@ var purify = {exports: {}};
1246
1988
  }
1247
1989
  /* Stringify, in case dirty is an object */
1248
1990
  if (typeof dirty !== 'string' && !_isNode(dirty)) {
1249
- if (typeof dirty.toString === 'function') {
1250
- dirty = dirty.toString();
1251
- if (typeof dirty !== 'string') {
1252
- throw typeErrorCreate('dirty is not a string, aborting');
1253
- }
1254
- } else {
1255
- throw typeErrorCreate('toString is not a function');
1991
+ dirty = stringifyValue(dirty);
1992
+ if (typeof dirty !== 'string') {
1993
+ throw typeErrorCreate('dirty is not a string, aborting');
1256
1994
  }
1257
1995
  }
1258
1996
  /* Return dirty HTML if DOMPurify cannot run */
@@ -1260,24 +1998,78 @@ var purify = {exports: {}};
1260
1998
  return dirty;
1261
1999
  }
1262
2000
  /* Assign config vars */
1263
- if (!SET_CONFIG) {
2001
+ if (SET_CONFIG) {
2002
+ /* Persistent setConfig() path: _parseConfig is skipped, so the sets are
2003
+ * not re-derived per call. Restore them from the pristine bindings
2004
+ * captured at setConfig() time so a previous call's hook clone (mutated
2005
+ * below) does not carry over. */
2006
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
2007
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
2008
+ } else {
1264
2009
  _parseConfig(cfg);
1265
2010
  }
2011
+ /* Clone the hook-mutable allowlists before the walk whenever an
2012
+ * uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
2013
+ * and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
2014
+ * a hook that widens them would otherwise mutate the shared set
2015
+ * permanently: across later calls and across every element. Cloning per
2016
+ * walk keeps documented in-call widening working while scoping it to the
2017
+ * call. A single guard for both config paths - the per-call path rebinds
2018
+ * the sets in _parseConfig each call, the persistent path restores them
2019
+ * from the captured bindings just above - so the two cannot diverge. */
2020
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
2021
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
2022
+ }
2023
+ if (hooks.uponSanitizeAttribute.length > 0) {
2024
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
2025
+ }
1266
2026
  /* Clean up removed elements */
1267
2027
  DOMPurify.removed = [];
1268
- /* Check if dirty is correctly typed for IN_PLACE */
1269
- if (typeof dirty === 'string') {
1270
- IN_PLACE = false;
1271
- }
1272
- if (IN_PLACE) {
1273
- /* Do some early pre-sanitization to avoid unsafe root nodes */
1274
- if (dirty.nodeName) {
1275
- const tagName = transformCaseFunc(dirty.nodeName);
2028
+ /* Resolve IN_PLACE for this call without mutating persistent config.
2029
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
2030
+ where _parseConfig is skipped on later calls: a single string call would
2031
+ disable in-place mode for every subsequent node call, returning a
2032
+ sanitized copy while leaving the caller's node — which in-place callers
2033
+ keep using and whose return value they ignore unsanitized. REPORT-2. */
2034
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
2035
+ if (inPlace) {
2036
+ /* Do some early pre-sanitization to avoid unsafe root nodes.
2037
+ Read nodeName through the cached prototype getter — a clobbering
2038
+ child named "nodeName" on the form root would otherwise shadow
2039
+ the property and let this check skip the root-allowlist
2040
+ validation entirely. */
2041
+ const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
2042
+ if (typeof nn === 'string') {
2043
+ const tagName = transformCaseFunc(nn);
1276
2044
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1277
2045
  throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1278
2046
  }
1279
2047
  }
1280
- } else if (dirty instanceof Node) {
2048
+ /* Pre-flight the root through _isClobbered. The iterator-driven
2049
+ removal path can not detach a parent-less root: _forceRemove
2050
+ falls through to Element.prototype.remove(), which per spec
2051
+ is a no-op on a node with no parent. A clobbered root would
2052
+ then survive the main loop with its attributes uninspected,
2053
+ because _sanitizeAttributes early-returns on _isClobbered. The
2054
+ result would be an attacker-controlled form, complete with any
2055
+ event-handler attributes the caller passed in, handed back to
2056
+ the application unsanitized. Refuse to sanitize such a root
2057
+ the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
2058
+ if (_isClobbered(dirty)) {
2059
+ throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
2060
+ }
2061
+ /* Sanitize attached shadow roots before the main iterator runs.
2062
+ The iterator does not descend into shadow trees. Same fail-closed
2063
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
2064
+ inside a shadow root could abort this pre-pass before the walk runs,
2065
+ which would otherwise leave the entire live tree unsanitized. */
2066
+ try {
2067
+ _sanitizeAttachedShadowRoots(dirty);
2068
+ } catch (error) {
2069
+ _neutralizeRoot(dirty);
2070
+ throw error;
2071
+ }
2072
+ } else if (_isNode(dirty)) {
1281
2073
  /* If dirty is a DOM element, append to an empty document to avoid
1282
2074
  elements being stripped by the parser */
1283
2075
  body = _initDocument('<!---->');
@@ -1291,12 +2083,18 @@ var purify = {exports: {}};
1291
2083
  // eslint-disable-next-line unicorn/prefer-dom-node-append
1292
2084
  body.appendChild(importedNode);
1293
2085
  }
2086
+ /* Clonable shadow roots are deep-cloned by importNode(); sanitize
2087
+ them before the main iterator runs, since the iterator does not
2088
+ descend into shadow trees. The walk routes every read through a
2089
+ cached prototype getter so clobbering descendants on a form root
2090
+ cannot hide a shadow host from this pass. */
2091
+ _sanitizeAttachedShadowRoots(importedNode);
1294
2092
  } else {
1295
2093
  /* Exit directly if we have nothing to do */
1296
2094
  if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1297
2095
  // eslint-disable-next-line unicorn/prefer-includes
1298
2096
  dirty.indexOf('<') === -1) {
1299
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
2097
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
1300
2098
  }
1301
2099
  /* Initialize the document to work on */
1302
2100
  body = _initDocument(dirty);
@@ -1310,31 +2108,59 @@ var purify = {exports: {}};
1310
2108
  _forceRemove(body.firstChild);
1311
2109
  }
1312
2110
  /* Get node iterator */
1313
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1314
- /* Now start iterating over the created document */
1315
- while (currentNode = nodeIterator.nextNode()) {
1316
- /* Sanitize tags and elements */
1317
- _sanitizeElements(currentNode);
1318
- /* Check attributes next */
1319
- _sanitizeAttributes(currentNode);
1320
- /* Shadow DOM detected, sanitize it */
1321
- if (currentNode.content instanceof DocumentFragment) {
1322
- _sanitizeShadowDOM2(currentNode.content);
2111
+ const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
2112
+ /* Now start iterating over the created document.
2113
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
2114
+ engine/custom-element mutation can detach a node mid-walk so
2115
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
2116
+ barrier the caller's in-place tree would be left half-sanitized with the
2117
+ unvisited tail still armed. On any throw we fail closed — strip the
2118
+ in-place root bare then rethrow so the existing throw contract is
2119
+ preserved. (String/DOM-copy paths never return the partial body, so the
2120
+ propagating throw is already fail-closed there.) */
2121
+ try {
2122
+ while (currentNode = nodeIterator.nextNode()) {
2123
+ /* Sanitize tags and elements */
2124
+ _sanitizeElements(currentNode);
2125
+ /* Check attributes next */
2126
+ _sanitizeAttributes(currentNode);
2127
+ /* Shadow DOM detected, sanitize it.
2128
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
2129
+ instead of instanceof, so foreign-realm <template>.content is
2130
+ walked correctly. */
2131
+ if (_isDocumentFragment(currentNode.content)) {
2132
+ _sanitizeShadowDOM2(currentNode.content);
2133
+ }
2134
+ }
2135
+ } catch (error) {
2136
+ if (inPlace) {
2137
+ _neutralizeRoot(dirty);
1323
2138
  }
2139
+ throw error;
1324
2140
  }
1325
2141
  /* If we sanitized `dirty` in-place, return it. */
1326
- if (IN_PLACE) {
2142
+ if (inPlace) {
2143
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
2144
+ the caller's live tree is detached but may still hold a queued
2145
+ resource-event handler that fires in page scope after we return. The
2146
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
2147
+ non-allow-listed attributes off every other removed subtree (clobber,
2148
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
2149
+ cancelled before any event can fire. Runs synchronously, pre-return. */
2150
+ arrayForEach(DOMPurify.removed, entry => {
2151
+ if (entry.element) {
2152
+ _neutralizeSubtree(entry.element);
2153
+ }
2154
+ });
2155
+ if (SAFE_FOR_TEMPLATES) {
2156
+ _scrubTemplateExpressions2(dirty);
2157
+ }
1327
2158
  return dirty;
1328
2159
  }
1329
2160
  /* Return sanitized string or DOM */
1330
2161
  if (RETURN_DOM) {
1331
2162
  if (SAFE_FOR_TEMPLATES) {
1332
- body.normalize();
1333
- let html = body.innerHTML;
1334
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1335
- html = stringReplace(html, expr, ' ');
1336
- });
1337
- body.innerHTML = html;
2163
+ _scrubTemplateExpressions2(body);
1338
2164
  }
1339
2165
  if (RETURN_DOM_FRAGMENT) {
1340
2166
  returnNode = createDocumentFragment.call(body.ownerDocument);
@@ -1364,20 +2190,28 @@ var purify = {exports: {}};
1364
2190
  }
1365
2191
  /* Sanitize final string template-safe */
1366
2192
  if (SAFE_FOR_TEMPLATES) {
1367
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1368
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
1369
- });
2193
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
1370
2194
  }
1371
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
2195
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
1372
2196
  };
1373
2197
  DOMPurify.setConfig = function () {
1374
2198
  let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1375
2199
  _parseConfig(cfg);
1376
2200
  SET_CONFIG = true;
2201
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
2202
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
1377
2203
  };
1378
2204
  DOMPurify.clearConfig = function () {
1379
2205
  CONFIG = null;
1380
2206
  SET_CONFIG = false;
2207
+ SET_CONFIG_ALLOWED_TAGS = null;
2208
+ SET_CONFIG_ALLOWED_ATTR = null;
2209
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
2210
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
2211
+ // never recreated — Trusted Types throws on duplicate names) is restored by
2212
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
2213
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
2214
+ emptyHTML = '';
1381
2215
  };
1382
2216
  DOMPurify.isValidAttribute = function (tag, attr, value) {
1383
2217
  /* Initialize shared config vars if necessary. */
@@ -1392,9 +2226,19 @@ var purify = {exports: {}};
1392
2226
  if (typeof hookFunction !== 'function') {
1393
2227
  return;
1394
2228
  }
2229
+ /* Reject unknown entry points. Without this, a non-hook key (e.g.
2230
+ * '__proto__') indexes off the prototype chain rather than a real
2231
+ * hook array, and arrayPush then writes to Object.prototype. Guard
2232
+ * with an own-property check against the known hook names. */
2233
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2234
+ return;
2235
+ }
1395
2236
  arrayPush(hooks[entryPoint], hookFunction);
1396
2237
  };
1397
2238
  DOMPurify.removeHook = function (entryPoint, hookFunction) {
2239
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2240
+ return undefined;
2241
+ }
1398
2242
  if (hookFunction !== undefined) {
1399
2243
  const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1400
2244
  return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
@@ -1402,6 +2246,9 @@ var purify = {exports: {}};
1402
2246
  return arrayPop(hooks[entryPoint]);
1403
2247
  };
1404
2248
  DOMPurify.removeHooks = function (entryPoint) {
2249
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2250
+ return;
2251
+ }
1405
2252
  hooks[entryPoint] = [];
1406
2253
  };
1407
2254
  DOMPurify.removeAllHooks = function () {