@baloise/ds-core 19.9.5 → 19.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/components/bal-steps.js +2 -2
  2. package/components/index.js +12 -11
  3. package/components/svg.js +2231 -1593
  4. package/components/tokens.esm.js +1 -1
  5. package/dist/baloise-design-system/baloise-design-system.esm.js +1 -1
  6. package/dist/baloise-design-system/baloise-design-system.js +1 -1
  7. package/dist/baloise-design-system/index.esm.js +1 -1
  8. package/dist/baloise-design-system/p--_h4j4q-.js +1 -0
  9. package/dist/baloise-design-system/{p-79d0e94ea1.entry.js → p-0cc81e6629.entry.js} +1 -1
  10. package/dist/baloise-design-system/p-0ff7f61cfb.entry.js +1 -0
  11. package/dist/baloise-design-system/{p-d21134a60b.system.entry.js → p-1499fb8b1e.system.entry.js} +1 -1
  12. package/dist/baloise-design-system/{p-607125007c.system.entry.js → p-1a6ba1626a.system.entry.js} +1 -1
  13. package/dist/baloise-design-system/{p-8268d61dd6.entry.js → p-208cbbcb1d.entry.js} +1 -1
  14. package/dist/baloise-design-system/{p-e6f03ecdd0.entry.js → p-24ccaeba21.entry.js} +1 -1
  15. package/dist/baloise-design-system/{p-fc8024a9d7.system.entry.js → p-31175f4af8.system.entry.js} +1 -1
  16. package/dist/baloise-design-system/{p-d5bd821ab7.system.entry.js → p-3376a1e651.system.entry.js} +1 -1
  17. package/dist/baloise-design-system/{p-02323ca1fe.entry.js → p-429bb32975.entry.js} +1 -1
  18. package/dist/baloise-design-system/{p-bbeeefc31a.system.entry.js → p-42d463fd3f.system.entry.js} +1 -1
  19. package/dist/baloise-design-system/{p-c31dc8146b.entry.js → p-52f625a5f7.entry.js} +1 -1
  20. package/dist/baloise-design-system/{p-fa728470a3.system.entry.js → p-609d2320b1.system.entry.js} +1 -1
  21. package/dist/baloise-design-system/{p-6c3d087d59.system.entry.js → p-64e141077d.system.entry.js} +1 -1
  22. package/dist/baloise-design-system/{p-64d45da025.system.entry.js → p-6fc739276a.system.entry.js} +1 -1
  23. package/dist/baloise-design-system/p-88ea8830b6.system.entry.js +1 -0
  24. package/dist/baloise-design-system/{p-68baccfba9.system.entry.js → p-8927f351fd.system.entry.js} +1 -1
  25. package/dist/baloise-design-system/p-91a2e98786.entry.js +1 -0
  26. package/dist/baloise-design-system/{p-1bb5b8696e.entry.js → p-9be648ffe8.entry.js} +1 -1
  27. package/dist/baloise-design-system/{p-3850595dd0.entry.js → p-9dfd29490a.entry.js} +1 -1
  28. package/dist/baloise-design-system/p-BTgSDGRr.js +2 -0
  29. package/dist/baloise-design-system/p-Bo8qDNOG.system.js +1 -0
  30. package/dist/baloise-design-system/{p-Oz8SBVmc.js → p-BqpLZmeG.js} +1 -1
  31. package/dist/baloise-design-system/{p-DxnFuP0T.system.js → p-CFjc7N6P.system.js} +1 -1
  32. package/dist/baloise-design-system/{p-5GEK9UQy.js → p-CTkFlT9_.js} +1 -1
  33. package/dist/baloise-design-system/{p-DvLv1IDC.js → p-CUqH3xVz.js} +1 -1
  34. package/dist/baloise-design-system/p-CVYynfS9.system.js +3 -0
  35. package/dist/baloise-design-system/p-CrCMAe2F.system.js +1 -0
  36. package/dist/baloise-design-system/{p-CPHPFMUC.system.js → p-CyZzYmE8.system.js} +1 -1
  37. package/dist/baloise-design-system/{p-Bk7UdnZ5.system.js → p-DeyNn-78.system.js} +1 -1
  38. package/dist/baloise-design-system/p-DsFHglk4.js +1 -0
  39. package/dist/baloise-design-system/{p-af05694fd5.entry.js → p-a117ce237f.entry.js} +1 -1
  40. package/dist/baloise-design-system/p-b0b968a148.system.entry.js +1 -0
  41. package/dist/baloise-design-system/{p-c8b853074f.entry.js → p-ba76da9a32.entry.js} +1 -1
  42. package/dist/baloise-design-system/p-brhkUB1V.system.js +1 -0
  43. package/dist/baloise-design-system/p-cd15fc8c69.entry.js +1 -0
  44. package/dist/baloise-design-system/{p-c4a244b558.system.entry.js → p-daf87a6be6.system.entry.js} +1 -1
  45. package/dist/baloise-design-system/{p-bac3d30df3.entry.js → p-dcd76bb03e.entry.js} +1 -1
  46. package/dist/baloise-design-system/{p-d41ca5c096.system.entry.js → p-eb1125dab4.system.entry.js} +1 -1
  47. package/dist/baloise-design-system/{p-477359bbf9.entry.js → p-ebfcd6a4b0.entry.js} +1 -1
  48. package/dist/baloise-design-system/{p-8e3412d465.entry.js → p-efc57cd356.entry.js} +1 -1
  49. package/dist/baloise-design-system/{p-eb2f5b22de.system.entry.js → p-f3199b24c8.system.entry.js} +1 -1
  50. package/dist/baloise-design-system/p-fac5fa4bcc.system.entry.js +1 -0
  51. package/dist/baloise-design-system/{p-DLLNm5Gs.system.js → p-tkZtpw7B.system.js} +1 -1
  52. package/dist/cjs/{app-globals-D4xKyILL.js → app-globals-BYXuaBq8.js} +1 -1
  53. package/dist/cjs/bal-carousel_2.cjs.entry.js +4 -5
  54. package/dist/cjs/bal-field_5.cjs.entry.js +3 -3
  55. package/dist/cjs/bal-footer.cjs.entry.js +1 -1
  56. package/dist/cjs/bal-hint_5.cjs.entry.js +3 -3
  57. package/dist/cjs/bal-icon.cjs.entry.js +1 -1
  58. package/dist/cjs/bal-list_8.cjs.entry.js +3 -3
  59. package/dist/cjs/bal-logo.cjs.entry.js +3 -3
  60. package/dist/cjs/bal-nav_8.cjs.entry.js +4 -5
  61. package/dist/cjs/bal-navbar_5.cjs.entry.js +3 -3
  62. package/dist/cjs/bal-pagination.cjs.entry.js +3 -3
  63. package/dist/cjs/bal-progress-bar.cjs.entry.js +4 -4
  64. package/dist/cjs/bal-segment_2.cjs.entry.js +4 -4
  65. package/dist/cjs/bal-shape.cjs.entry.js +1 -1
  66. package/dist/cjs/bal-steps.cjs.entry.js +5 -5
  67. package/dist/cjs/bal-tab-item_2.cjs.entry.js +3 -3
  68. package/dist/cjs/baloise-design-system.cjs.js +2 -2
  69. package/dist/cjs/{breakpoints.decorator-DPrGtqtk.js → breakpoints.decorator-Dh3Bo-Yu.js} +1 -1
  70. package/dist/cjs/{breakpoints.subject-C1p-ePFH.js → breakpoints.subject-CzZMSmUO.js} +1 -1
  71. package/dist/cjs/index.cjs.js +3 -3
  72. package/dist/cjs/{initialize-BzrcZo6Y.js → initialize-7J6n8lOv.js} +12 -11
  73. package/dist/cjs/loader.cjs.js +2 -2
  74. package/dist/cjs/svg-DqzoyBUW.js +2245 -0
  75. package/dist/cjs/{tokens.esm-BWWYqtq4.js → tokens.esm-DI0zgU1M.js} +1 -1
  76. package/dist/cjs/{window-resize.decorator-DRN0wiUR.js → window-resize.decorator-CBrnxH3J.js} +1 -1
  77. package/dist/collection/components/bal-steps/components/step-button.js +2 -2
  78. package/dist/collection/utils/config/config.js +11 -10
  79. package/dist/collection/utils/constants/version.constant.js +1 -1
  80. package/dist/esm/{app-globals-Blx--ecs.js → app-globals-ZlH5sXFc.js} +1 -1
  81. package/dist/esm/bal-carousel_2.entry.js +4 -5
  82. package/dist/esm/bal-field_5.entry.js +3 -3
  83. package/dist/esm/bal-footer.entry.js +1 -1
  84. package/dist/esm/bal-hint_5.entry.js +3 -3
  85. package/dist/esm/bal-icon.entry.js +1 -1
  86. package/dist/esm/bal-list_8.entry.js +3 -3
  87. package/dist/esm/bal-logo.entry.js +3 -3
  88. package/dist/esm/bal-nav_8.entry.js +4 -5
  89. package/dist/esm/bal-navbar_5.entry.js +3 -3
  90. package/dist/esm/bal-pagination.entry.js +3 -3
  91. package/dist/esm/bal-progress-bar.entry.js +4 -4
  92. package/dist/esm/bal-segment_2.entry.js +4 -4
  93. package/dist/esm/bal-shape.entry.js +1 -1
  94. package/dist/esm/bal-steps.entry.js +5 -5
  95. package/dist/esm/bal-tab-item_2.entry.js +3 -3
  96. package/dist/esm/baloise-design-system.js +2 -2
  97. package/dist/esm/{breakpoints.decorator-DwhK_t2m.js → breakpoints.decorator-BvzrUw7f.js} +1 -1
  98. package/dist/esm/{breakpoints.subject-PxavGndB.js → breakpoints.subject-BugBexTF.js} +1 -1
  99. package/dist/esm/index.js +4 -4
  100. package/dist/esm/{initialize-W3od-FM9.js → initialize-BS5FhjDS.js} +12 -11
  101. package/dist/esm/loader.js +2 -2
  102. package/dist/esm/svg-BTgSDGRr.js +2243 -0
  103. package/dist/esm/{tokens.esm-Dk6PruGq.js → tokens.esm-B32RYUT0.js} +1 -1
  104. package/dist/esm/{window-resize.decorator-DiNYHJee.js → window-resize.decorator-DK5kMpPN.js} +1 -1
  105. package/dist/esm-es5/app-globals-ZlH5sXFc.js +1 -0
  106. package/dist/esm-es5/bal-carousel_2.entry.js +1 -1
  107. package/dist/esm-es5/bal-field_5.entry.js +1 -1
  108. package/dist/esm-es5/bal-footer.entry.js +1 -1
  109. package/dist/esm-es5/bal-hint_5.entry.js +1 -1
  110. package/dist/esm-es5/bal-icon.entry.js +1 -1
  111. package/dist/esm-es5/bal-list_8.entry.js +1 -1
  112. package/dist/esm-es5/bal-logo.entry.js +1 -1
  113. package/dist/esm-es5/bal-nav_8.entry.js +1 -1
  114. package/dist/esm-es5/bal-navbar_5.entry.js +1 -1
  115. package/dist/esm-es5/bal-pagination.entry.js +1 -1
  116. package/dist/esm-es5/bal-progress-bar.entry.js +1 -1
  117. package/dist/esm-es5/bal-segment_2.entry.js +1 -1
  118. package/dist/esm-es5/bal-shape.entry.js +1 -1
  119. package/dist/esm-es5/bal-steps.entry.js +1 -1
  120. package/dist/esm-es5/bal-tab-item_2.entry.js +1 -1
  121. package/dist/esm-es5/baloise-design-system.js +1 -1
  122. package/dist/esm-es5/breakpoints.decorator-BvzrUw7f.js +1 -0
  123. package/dist/esm-es5/{breakpoints.subject-PxavGndB.js → breakpoints.subject-BugBexTF.js} +1 -1
  124. package/dist/esm-es5/index.js +1 -1
  125. package/dist/esm-es5/initialize-BS5FhjDS.js +1 -0
  126. package/dist/esm-es5/loader.js +1 -1
  127. package/dist/esm-es5/svg-BTgSDGRr.js +2 -0
  128. package/dist/esm-es5/{window-resize.decorator-DiNYHJee.js → window-resize.decorator-DK5kMpPN.js} +1 -1
  129. package/dist/types/utils/config/config.d.ts +2 -2
  130. package/dist/types/utils/mask/__test__/mask-component.mock.d.ts +6 -6
  131. package/dist/types/utils/mask/__test__/mask.mock.d.ts +9 -9
  132. package/dist/types/utils/svg.d.ts +1 -1
  133. package/package.json +7 -10
  134. package/dist/baloise-design-system/p-43dd693355.system.entry.js +0 -1
  135. package/dist/baloise-design-system/p-59129fb1d1.system.entry.js +0 -1
  136. package/dist/baloise-design-system/p-68f77714ab.entry.js +0 -1
  137. package/dist/baloise-design-system/p-BFRjY4w3.js +0 -1
  138. package/dist/baloise-design-system/p-BRAmUyPx.system.js +0 -1
  139. package/dist/baloise-design-system/p-CKN3W8qn.js +0 -1
  140. package/dist/baloise-design-system/p-Ck7YRry-.system.js +0 -2
  141. package/dist/baloise-design-system/p-CsPrCX4f.system.js +0 -1
  142. package/dist/baloise-design-system/p-DojUs2K8.js +0 -2
  143. package/dist/baloise-design-system/p-aDM_iThE.system.js +0 -1
  144. package/dist/baloise-design-system/p-b670d9cae9.entry.js +0 -1
  145. package/dist/baloise-design-system/p-c5ae87f18e.entry.js +0 -1
  146. package/dist/baloise-design-system/p-f2435a528c.system.entry.js +0 -1
  147. package/dist/cjs/svg-qEvvK3mS.js +0 -1607
  148. package/dist/esm/svg-DhNz-XmR.js +0 -1605
  149. package/dist/esm-es5/app-globals-Blx--ecs.js +0 -1
  150. package/dist/esm-es5/breakpoints.decorator-DwhK_t2m.js +0 -1
  151. package/dist/esm-es5/initialize-W3od-FM9.js +0 -1
  152. package/dist/esm-es5/svg-DhNz-XmR.js +0 -2
  153. /package/dist/baloise-design-system/{p-Dk6PruGq.js → p-B32RYUT0.js} +0 -0
  154. /package/dist/baloise-design-system/{p-Nqmo3uHl.system.js → p-D0HQAsaT.system.js} +0 -0
  155. /package/dist/esm-es5/{tokens.esm-Dk6PruGq.js → tokens.esm-B32RYUT0.js} +0 -0
@@ -0,0 +1,2243 @@
1
+ /*! @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 */
2
+
3
+ function _arrayLikeToArray(r, a) {
4
+ (null == a || a > r.length) && (a = r.length);
5
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
6
+ return n;
7
+ }
8
+ function _arrayWithHoles(r) {
9
+ if (Array.isArray(r)) return r;
10
+ }
11
+ function _iterableToArrayLimit(r, l) {
12
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
13
+ if (null != t) {
14
+ var e,
15
+ n,
16
+ i,
17
+ u,
18
+ a = [],
19
+ f = true,
20
+ o = false;
21
+ try {
22
+ 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 = true);
23
+ } catch (r) {
24
+ o = true, n = r;
25
+ } finally {
26
+ try {
27
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
28
+ } finally {
29
+ if (o) throw n;
30
+ }
31
+ }
32
+ return a;
33
+ }
34
+ }
35
+ function _nonIterableRest() {
36
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
37
+ }
38
+ function _slicedToArray(r, e) {
39
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
40
+ }
41
+ function _unsupportedIterableToArray(r, a) {
42
+ if (r) {
43
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
44
+ var t = {}.toString.call(r).slice(8, -1);
45
+ 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;
46
+ }
47
+ }
48
+
49
+ const entries = Object.entries,
50
+ setPrototypeOf = Object.setPrototypeOf,
51
+ isFrozen = Object.isFrozen,
52
+ getPrototypeOf = Object.getPrototypeOf,
53
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
54
+ let freeze = Object.freeze,
55
+ seal = Object.seal,
56
+ create = Object.create; // eslint-disable-line import/no-mutable-exports
57
+ let _ref = typeof Reflect !== 'undefined' && Reflect,
58
+ apply = _ref.apply,
59
+ construct = _ref.construct;
60
+ if (!freeze) {
61
+ freeze = function freeze(x) {
62
+ return x;
63
+ };
64
+ }
65
+ if (!seal) {
66
+ seal = function seal(x) {
67
+ return x;
68
+ };
69
+ }
70
+ if (!apply) {
71
+ apply = function apply(func, thisArg) {
72
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
73
+ args[_key - 2] = arguments[_key];
74
+ }
75
+ return func.apply(thisArg, args);
76
+ };
77
+ }
78
+ if (!construct) {
79
+ construct = function construct(Func) {
80
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
81
+ args[_key2 - 1] = arguments[_key2];
82
+ }
83
+ return new Func(...args);
84
+ };
85
+ }
86
+ const arrayForEach = unapply(Array.prototype.forEach);
87
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
88
+ const arrayPop = unapply(Array.prototype.pop);
89
+ const arrayPush = unapply(Array.prototype.push);
90
+ const arraySplice = unapply(Array.prototype.splice);
91
+ const arrayIsArray = Array.isArray;
92
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
93
+ const stringToString = unapply(String.prototype.toString);
94
+ const stringMatch = unapply(String.prototype.match);
95
+ const stringReplace = unapply(String.prototype.replace);
96
+ const stringIndexOf = unapply(String.prototype.indexOf);
97
+ const stringTrim = unapply(String.prototype.trim);
98
+ const numberToString = unapply(Number.prototype.toString);
99
+ const booleanToString = unapply(Boolean.prototype.toString);
100
+ const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
101
+ const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
102
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
103
+ const objectToString = unapply(Object.prototype.toString);
104
+ const regExpTest = unapply(RegExp.prototype.test);
105
+ const typeErrorCreate = unconstruct(TypeError);
106
+ /**
107
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
108
+ *
109
+ * @param func - The function to be wrapped and called.
110
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
111
+ */
112
+ function unapply(func) {
113
+ return function (thisArg) {
114
+ if (thisArg instanceof RegExp) {
115
+ thisArg.lastIndex = 0;
116
+ }
117
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
118
+ args[_key3 - 1] = arguments[_key3];
119
+ }
120
+ return apply(func, thisArg, args);
121
+ };
122
+ }
123
+ /**
124
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
125
+ *
126
+ * @param func - The constructor function to be wrapped and called.
127
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
128
+ */
129
+ function unconstruct(Func) {
130
+ return function () {
131
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
132
+ args[_key4] = arguments[_key4];
133
+ }
134
+ return construct(Func, args);
135
+ };
136
+ }
137
+ /**
138
+ * Add properties to a lookup table
139
+ *
140
+ * @param set - The set to which elements will be added.
141
+ * @param array - The array containing elements to be added to the set.
142
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
143
+ * @returns The modified set with added elements.
144
+ */
145
+ function addToSet(set, array) {
146
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
147
+ if (setPrototypeOf) {
148
+ // Make 'in' and truthy checks like Boolean(set.constructor)
149
+ // independent of any properties defined on Object.prototype.
150
+ // Prevent prototype setters from intercepting set as a this value.
151
+ setPrototypeOf(set, null);
152
+ }
153
+ if (!arrayIsArray(array)) {
154
+ return set;
155
+ }
156
+ let l = array.length;
157
+ while (l--) {
158
+ let element = array[l];
159
+ if (typeof element === 'string') {
160
+ const lcElement = transformCaseFunc(element);
161
+ if (lcElement !== element) {
162
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
163
+ if (!isFrozen(array)) {
164
+ array[l] = lcElement;
165
+ }
166
+ element = lcElement;
167
+ }
168
+ }
169
+ set[element] = true;
170
+ }
171
+ return set;
172
+ }
173
+ /**
174
+ * Clean up an array to harden against CSPP
175
+ *
176
+ * @param array - The array to be cleaned.
177
+ * @returns The cleaned version of the array
178
+ */
179
+ function cleanArray(array) {
180
+ for (let index = 0; index < array.length; index++) {
181
+ const isPropertyExist = objectHasOwnProperty(array, index);
182
+ if (!isPropertyExist) {
183
+ array[index] = null;
184
+ }
185
+ }
186
+ return array;
187
+ }
188
+ /**
189
+ * Shallow clone an object
190
+ *
191
+ * @param object - The object to be cloned.
192
+ * @returns A new object that copies the original.
193
+ */
194
+ function clone(object) {
195
+ const newObject = create(null);
196
+ for (const _ref2 of entries(object)) {
197
+ var _ref3 = _slicedToArray(_ref2, 2);
198
+ const property = _ref3[0];
199
+ const value = _ref3[1];
200
+ const isPropertyExist = objectHasOwnProperty(object, property);
201
+ if (isPropertyExist) {
202
+ if (arrayIsArray(value)) {
203
+ newObject[property] = cleanArray(value);
204
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
205
+ newObject[property] = clone(value);
206
+ } else {
207
+ newObject[property] = value;
208
+ }
209
+ }
210
+ }
211
+ return newObject;
212
+ }
213
+ /**
214
+ * Convert non-node values into strings without depending on direct property access.
215
+ *
216
+ * @param value - The value to stringify.
217
+ * @returns A string representation of the provided value.
218
+ */
219
+ function stringifyValue(value) {
220
+ switch (typeof value) {
221
+ case 'string':
222
+ {
223
+ return value;
224
+ }
225
+ case 'number':
226
+ {
227
+ return numberToString(value);
228
+ }
229
+ case 'boolean':
230
+ {
231
+ return booleanToString(value);
232
+ }
233
+ case 'bigint':
234
+ {
235
+ return bigintToString ? bigintToString(value) : '0';
236
+ }
237
+ case 'symbol':
238
+ {
239
+ return symbolToString ? symbolToString(value) : 'Symbol()';
240
+ }
241
+ case 'undefined':
242
+ {
243
+ return objectToString(value);
244
+ }
245
+ case 'function':
246
+ case 'object':
247
+ {
248
+ if (value === null) {
249
+ return objectToString(value);
250
+ }
251
+ const valueAsRecord = value;
252
+ const valueToString = lookupGetter(valueAsRecord, 'toString');
253
+ if (typeof valueToString === 'function') {
254
+ const stringified = valueToString(valueAsRecord);
255
+ return typeof stringified === 'string' ? stringified : objectToString(stringified);
256
+ }
257
+ return objectToString(value);
258
+ }
259
+ default:
260
+ {
261
+ return objectToString(value);
262
+ }
263
+ }
264
+ }
265
+ /**
266
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
267
+ *
268
+ * @param object - The object to look up the getter function in its prototype chain.
269
+ * @param prop - The property name for which to find the getter function.
270
+ * @returns The getter function found in the prototype chain or a fallback function.
271
+ */
272
+ function lookupGetter(object, prop) {
273
+ while (object !== null) {
274
+ const desc = getOwnPropertyDescriptor(object, prop);
275
+ if (desc) {
276
+ if (desc.get) {
277
+ return unapply(desc.get);
278
+ }
279
+ if (typeof desc.value === 'function') {
280
+ return unapply(desc.value);
281
+ }
282
+ }
283
+ object = getPrototypeOf(object);
284
+ }
285
+ function fallbackValue() {
286
+ return null;
287
+ }
288
+ return fallbackValue;
289
+ }
290
+ function isRegex(value) {
291
+ try {
292
+ regExpTest(value, '');
293
+ return true;
294
+ } catch (_unused) {
295
+ return false;
296
+ }
297
+ }
298
+
299
+ 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']);
300
+ 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']);
301
+ const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
302
+ // List of SVG elements that are disallowed by default.
303
+ // We still need to know them so that we can do namespace
304
+ // checks properly in case one wants to add them to
305
+ // allow-list.
306
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
307
+ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
308
+ // Similarly to SVG, we want to know all MathML elements,
309
+ // even those that we disallow by default.
310
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
311
+ const text = freeze(['#text']);
312
+
313
+ 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']);
314
+ 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']);
315
+ 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']);
316
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
317
+
318
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
319
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
320
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
321
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
322
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
323
+ 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
324
+ );
325
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
326
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
327
+ );
328
+ const DOCTYPE_NAME = seal(/^html$/i);
329
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
330
+ // Markup-significant character probes used by _sanitizeElements.
331
+ // Shared module-level instances are safe despite the sticky /g flags:
332
+ // unapply() resets lastIndex for RegExp receivers before every call.
333
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
334
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
335
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
336
+ const SELF_CLOSING_TAG = seal(/\/>/i);
337
+
338
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
339
+ const NODE_TYPE = {
340
+ element: 1,
341
+ text: 3,
342
+ // Deprecated
343
+ processingInstruction: 7,
344
+ comment: 8,
345
+ document: 9,
346
+ documentFragment: 11};
347
+ const getGlobal = function getGlobal() {
348
+ return typeof window === 'undefined' ? null : window;
349
+ };
350
+ /**
351
+ * Creates a no-op policy for internal use only.
352
+ * Don't export this function outside this module!
353
+ * @param trustedTypes The policy factory.
354
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
355
+ * @return The policy created (or null, if Trusted Types
356
+ * are not supported or creating the policy failed).
357
+ */
358
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
359
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
360
+ return null;
361
+ }
362
+ // Allow the callers to control the unique policy name
363
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
364
+ // Policy creation with duplicate names throws in Trusted Types.
365
+ let suffix = null;
366
+ const ATTR_NAME = 'data-tt-policy-suffix';
367
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
368
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
369
+ }
370
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
371
+ try {
372
+ return trustedTypes.createPolicy(policyName, {
373
+ createHTML(html) {
374
+ return html;
375
+ },
376
+ createScriptURL(scriptUrl) {
377
+ return scriptUrl;
378
+ }
379
+ });
380
+ } catch (_) {
381
+ // Policy creation failed (most likely another DOMPurify script has
382
+ // already run). Skip creating the policy, as this will only cause errors
383
+ // if TT are enforced.
384
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
385
+ return null;
386
+ }
387
+ };
388
+ const _createHooksMap = function _createHooksMap() {
389
+ return {
390
+ afterSanitizeAttributes: [],
391
+ afterSanitizeElements: [],
392
+ afterSanitizeShadowDOM: [],
393
+ beforeSanitizeAttributes: [],
394
+ beforeSanitizeElements: [],
395
+ beforeSanitizeShadowDOM: [],
396
+ uponSanitizeAttribute: [],
397
+ uponSanitizeElement: [],
398
+ uponSanitizeShadowNode: []
399
+ };
400
+ };
401
+ /**
402
+ * Resolve a set-valued configuration option: a fresh set built from
403
+ * cfg[key] when it is an own array property (seeded with a clone of
404
+ * options.base when given, case-normalized via options.transform),
405
+ * the fallback set otherwise.
406
+ *
407
+ * @param cfg the cloned, prototype-free configuration object
408
+ * @param key the configuration property to read
409
+ * @param fallback the set to use when the option is absent or not an array
410
+ * @param options transform and optional base set to merge into
411
+ * @returns the resolved set
412
+ */
413
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
414
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
415
+ };
416
+ function createDOMPurify() {
417
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
418
+ const DOMPurify = root => createDOMPurify(root);
419
+ DOMPurify.version = '3.4.11';
420
+ DOMPurify.removed = [];
421
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
422
+ // Not running in a browser, provide a factory function
423
+ // so that you can pass your own Window
424
+ DOMPurify.isSupported = false;
425
+ return DOMPurify;
426
+ }
427
+ let document = window.document;
428
+ const originalDocument = document;
429
+ const currentScript = originalDocument.currentScript;
430
+ const HTMLTemplateElement = window.HTMLTemplateElement,
431
+ Node = window.Node,
432
+ Element = window.Element,
433
+ NodeFilter = window.NodeFilter;
434
+ const DOMParser = window.DOMParser,
435
+ trustedTypes = window.trustedTypes;
436
+ const ElementPrototype = Element.prototype;
437
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
438
+ const remove = lookupGetter(ElementPrototype, 'remove');
439
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
440
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
441
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
442
+ const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
443
+ const getAttributes = lookupGetter(ElementPrototype, 'attributes');
444
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
445
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
446
+ // As per issue #47, the web-components registry is inherited by a
447
+ // new document created via createHTMLDocument. As per the spec
448
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
449
+ // a new empty registry is used when creating a template contents owner
450
+ // document, so we use that as our parent document to ensure nothing
451
+ // is inherited.
452
+ if (typeof HTMLTemplateElement === 'function') {
453
+ const template = document.createElement('template');
454
+ if (template.content && template.content.ownerDocument) {
455
+ document = template.content.ownerDocument;
456
+ }
457
+ }
458
+ let trustedTypesPolicy;
459
+ let emptyHTML = '';
460
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
461
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
462
+ // on duplicate policy names — and is the only policy allowed to persist
463
+ // across configurations and survive `clearConfig()`.
464
+ let defaultTrustedTypesPolicy;
465
+ let defaultTrustedTypesPolicyResolved = false;
466
+ // Tracks whether we are already inside a call to the configured Trusted Types
467
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
468
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
469
+ // re-enter the policy and recurse until the stack overflows. We detect that
470
+ // re-entry and throw a clear, actionable error instead. The guard is shared
471
+ // across both callbacks, because either one re-entering `sanitize` triggers
472
+ // the same unbounded recursion.
473
+ let IN_TRUSTED_TYPES_POLICY = 0;
474
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
475
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
476
+ 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.');
477
+ }
478
+ };
479
+ const _createTrustedHTML = function _createTrustedHTML(html) {
480
+ _assertNotInTrustedTypesPolicy();
481
+ IN_TRUSTED_TYPES_POLICY++;
482
+ try {
483
+ return trustedTypesPolicy.createHTML(html);
484
+ } finally {
485
+ IN_TRUSTED_TYPES_POLICY--;
486
+ }
487
+ };
488
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
489
+ _assertNotInTrustedTypesPolicy();
490
+ IN_TRUSTED_TYPES_POLICY++;
491
+ try {
492
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
493
+ } finally {
494
+ IN_TRUSTED_TYPES_POLICY--;
495
+ }
496
+ };
497
+ // Lazily resolve (and cache) the instance's internal default policy.
498
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
499
+ // repeated (Trusted Types throws on duplicate names), and a failed or
500
+ // unsupported attempt must not be retried on every parse.
501
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
502
+ if (!defaultTrustedTypesPolicyResolved) {
503
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
504
+ defaultTrustedTypesPolicyResolved = true;
505
+ }
506
+ return defaultTrustedTypesPolicy;
507
+ };
508
+ const _document = document,
509
+ implementation = _document.implementation,
510
+ createNodeIterator = _document.createNodeIterator,
511
+ createDocumentFragment = _document.createDocumentFragment,
512
+ getElementsByTagName = _document.getElementsByTagName;
513
+ const importNode = originalDocument.importNode;
514
+ let hooks = _createHooksMap();
515
+ /**
516
+ * Expose whether this browser supports running the full DOMPurify.
517
+ */
518
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
519
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
520
+ ERB_EXPR$1 = ERB_EXPR,
521
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
522
+ DATA_ATTR$1 = DATA_ATTR,
523
+ ARIA_ATTR$1 = ARIA_ATTR,
524
+ IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
525
+ ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
526
+ CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
527
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
528
+ /**
529
+ * We consider the elements and attributes below to be safe. Ideally
530
+ * don't add any new ones but feel free to remove unwanted ones.
531
+ */
532
+ /* allowed element names */
533
+ let ALLOWED_TAGS = null;
534
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
535
+ /* Allowed attribute names */
536
+ let ALLOWED_ATTR = null;
537
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
538
+ /*
539
+ * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
540
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
541
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
542
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
543
+ */
544
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
545
+ tagNameCheck: {
546
+ writable: true,
547
+ configurable: false,
548
+ enumerable: true,
549
+ value: null
550
+ },
551
+ attributeNameCheck: {
552
+ writable: true,
553
+ configurable: false,
554
+ enumerable: true,
555
+ value: null
556
+ },
557
+ allowCustomizedBuiltInElements: {
558
+ writable: true,
559
+ configurable: false,
560
+ enumerable: true,
561
+ value: false
562
+ }
563
+ }));
564
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
565
+ let FORBID_TAGS = null;
566
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
567
+ let FORBID_ATTR = null;
568
+ /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
569
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
570
+ tagCheck: {
571
+ writable: true,
572
+ configurable: false,
573
+ enumerable: true,
574
+ value: null
575
+ },
576
+ attributeCheck: {
577
+ writable: true,
578
+ configurable: false,
579
+ enumerable: true,
580
+ value: null
581
+ }
582
+ }));
583
+ /* Decide if ARIA attributes are okay */
584
+ let ALLOW_ARIA_ATTR = true;
585
+ /* Decide if custom data attributes are okay */
586
+ let ALLOW_DATA_ATTR = true;
587
+ /* Decide if unknown protocols are okay */
588
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
589
+ /* Decide if self-closing tags in attributes are allowed.
590
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
591
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
592
+ /* Output should be safe for common template engines.
593
+ * This means, DOMPurify removes data attributes, mustaches and ERB
594
+ */
595
+ let SAFE_FOR_TEMPLATES = false;
596
+ /* Output should be safe even for XML used within HTML and alike.
597
+ * This means, DOMPurify removes comments when containing risky content.
598
+ */
599
+ let SAFE_FOR_XML = true;
600
+ /* Decide if document with <html>... should be returned */
601
+ let WHOLE_DOCUMENT = false;
602
+ /* Track whether config is already set on this instance of DOMPurify. */
603
+ let SET_CONFIG = false;
604
+ /* Pristine allowlist bindings captured at setConfig() time. On the
605
+ * persistent-config path sanitize() restores the sets from these before
606
+ * the per-walk hook clone-guard, so a hook's in-call widening cannot
607
+ * carry across calls. Null until setConfig() is called; reset by
608
+ * clearConfig(). */
609
+ let SET_CONFIG_ALLOWED_TAGS = null;
610
+ let SET_CONFIG_ALLOWED_ATTR = null;
611
+ /* Decide if all elements (e.g. style, script) must be children of
612
+ * document.body. By default, browsers might move them to document.head */
613
+ let FORCE_BODY = false;
614
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
615
+ * string (or a TrustedHTML object if Trusted Types are supported).
616
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
617
+ */
618
+ let RETURN_DOM = false;
619
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
620
+ * string (or a TrustedHTML object if Trusted Types are supported) */
621
+ let RETURN_DOM_FRAGMENT = false;
622
+ /* Try to return a Trusted Type object instead of a string, return a string in
623
+ * case Trusted Types are not supported */
624
+ let RETURN_TRUSTED_TYPE = false;
625
+ /* Output should be free from DOM clobbering attacks?
626
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
627
+ */
628
+ let SANITIZE_DOM = true;
629
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
630
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
631
+ *
632
+ * HTML/DOM spec rules that enable DOM Clobbering:
633
+ * - Named Access on Window (§7.3.3)
634
+ * - DOM Tree Accessors (§3.1.5)
635
+ * - Form Element Parent-Child Relations (§4.10.3)
636
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
637
+ * - HTMLCollection (§4.2.10.2)
638
+ *
639
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
640
+ * with a constant string, i.e., `user-content-`
641
+ */
642
+ let SANITIZE_NAMED_PROPS = false;
643
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
644
+ /* Keep element content when removing element? */
645
+ let KEEP_CONTENT = true;
646
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
647
+ * of importing it into a new Document and returning a sanitized copy */
648
+ let IN_PLACE = false;
649
+ /* Allow usage of profiles like html, svg and mathMl */
650
+ let USE_PROFILES = {};
651
+ /* Tags to ignore content of when KEEP_CONTENT is true */
652
+ let FORBID_CONTENTS = null;
653
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
654
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
655
+ // the UA (customizable <select>) — including any on* handlers — and the
656
+ // engine re-mirrors synchronously whenever a removal changes which
657
+ // option/selectedcontent is current, even inside DOMPurify's inert
658
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
659
+ // mirror target ahead of the walk, which the engine refills, looping
660
+ // forever (DoS) and amplifying output. Dropping its content on removal
661
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
662
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
663
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
664
+ /* Tags that are safe for data: URIs */
665
+ let DATA_URI_TAGS = null;
666
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
667
+ /* Attributes safe for values like "javascript:" */
668
+ let URI_SAFE_ATTRIBUTES = null;
669
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
670
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
671
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
672
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
673
+ /* Document namespace */
674
+ let NAMESPACE = HTML_NAMESPACE;
675
+ let IS_EMPTY_INPUT = false;
676
+ /* Allowed XHTML+XML namespaces */
677
+ let ALLOWED_NAMESPACES = null;
678
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
679
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
680
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
681
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
682
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
683
+ // Certain elements are allowed in both SVG and HTML
684
+ // namespace. We need to specify them explicitly
685
+ // so that they don't get erroneously deleted from
686
+ // HTML namespace.
687
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
688
+ /* Parsing of strict XHTML documents */
689
+ let PARSER_MEDIA_TYPE = null;
690
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
691
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
692
+ let transformCaseFunc = null;
693
+ /* Keep a reference to config to pass to hooks */
694
+ let CONFIG = null;
695
+ /* Ideally, do not touch anything below this line */
696
+ /* ______________________________________________ */
697
+ const formElement = document.createElement('form');
698
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
699
+ return testValue instanceof RegExp || testValue instanceof Function;
700
+ };
701
+ /**
702
+ * _parseConfig
703
+ *
704
+ * @param cfg optional config literal
705
+ */
706
+ // eslint-disable-next-line complexity
707
+ const _parseConfig = function _parseConfig() {
708
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
709
+ if (CONFIG && CONFIG === cfg) {
710
+ return;
711
+ }
712
+ /* Shield configuration object from tampering */
713
+ if (!cfg || typeof cfg !== 'object') {
714
+ cfg = {};
715
+ }
716
+ /* Shield configuration object from prototype pollution */
717
+ cfg = clone(cfg);
718
+ PARSER_MEDIA_TYPE =
719
+ // eslint-disable-next-line unicorn/prefer-includes
720
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
721
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
722
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
723
+ /* Set configuration parameters */
724
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
725
+ transform: transformCaseFunc
726
+ });
727
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
728
+ transform: transformCaseFunc
729
+ });
730
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
731
+ transform: stringToString
732
+ });
733
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
734
+ transform: transformCaseFunc,
735
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
736
+ });
737
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
738
+ transform: transformCaseFunc,
739
+ base: DEFAULT_DATA_URI_TAGS
740
+ });
741
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
742
+ transform: transformCaseFunc
743
+ });
744
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
745
+ transform: transformCaseFunc
746
+ });
747
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
748
+ transform: transformCaseFunc
749
+ });
750
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
751
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
752
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
753
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
754
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
755
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
756
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
757
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
758
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
759
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
760
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
761
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
762
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
763
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
764
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
765
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
766
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
767
+ NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
768
+ 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
769
+ 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
770
+ const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
771
+ CUSTOM_ELEMENT_HANDLING = create(null);
772
+ if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
773
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
774
+ }
775
+ if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
776
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
777
+ }
778
+ if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
779
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
780
+ }
781
+ seal(CUSTOM_ELEMENT_HANDLING);
782
+ if (SAFE_FOR_TEMPLATES) {
783
+ ALLOW_DATA_ATTR = false;
784
+ }
785
+ if (RETURN_DOM_FRAGMENT) {
786
+ RETURN_DOM = true;
787
+ }
788
+ /* Parse profile info */
789
+ if (USE_PROFILES) {
790
+ ALLOWED_TAGS = addToSet({}, text);
791
+ ALLOWED_ATTR = create(null);
792
+ if (USE_PROFILES.html === true) {
793
+ addToSet(ALLOWED_TAGS, html$1);
794
+ addToSet(ALLOWED_ATTR, html);
795
+ }
796
+ if (USE_PROFILES.svg === true) {
797
+ addToSet(ALLOWED_TAGS, svg$1);
798
+ addToSet(ALLOWED_ATTR, svg);
799
+ addToSet(ALLOWED_ATTR, xml);
800
+ }
801
+ if (USE_PROFILES.svgFilters === true) {
802
+ addToSet(ALLOWED_TAGS, svgFilters);
803
+ addToSet(ALLOWED_ATTR, svg);
804
+ addToSet(ALLOWED_ATTR, xml);
805
+ }
806
+ if (USE_PROFILES.mathMl === true) {
807
+ addToSet(ALLOWED_TAGS, mathMl$1);
808
+ addToSet(ALLOWED_ATTR, mathMl);
809
+ addToSet(ALLOWED_ATTR, xml);
810
+ }
811
+ }
812
+ /* Always reset function-based ADD_TAGS / ADD_ATTR checks to prevent
813
+ * leaking across calls when switching from function to array config */
814
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
815
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
816
+ /* Merge configuration parameters */
817
+ if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
818
+ if (typeof cfg.ADD_TAGS === 'function') {
819
+ EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
820
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
821
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
822
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
823
+ }
824
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
825
+ }
826
+ }
827
+ if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
828
+ if (typeof cfg.ADD_ATTR === 'function') {
829
+ EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
830
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
831
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
832
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
833
+ }
834
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
835
+ }
836
+ }
837
+ if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
838
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
839
+ }
840
+ if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
841
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
842
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
843
+ }
844
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
845
+ }
846
+ if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
847
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
848
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
849
+ }
850
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
851
+ }
852
+ /* Add #text in case KEEP_CONTENT is set to true */
853
+ if (KEEP_CONTENT) {
854
+ ALLOWED_TAGS['#text'] = true;
855
+ }
856
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
857
+ if (WHOLE_DOCUMENT) {
858
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
859
+ }
860
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
861
+ if (ALLOWED_TAGS.table) {
862
+ addToSet(ALLOWED_TAGS, ['tbody']);
863
+ delete FORBID_TAGS.tbody;
864
+ }
865
+ // Re-derive the active Trusted Types policy from this configuration on
866
+ // every parse. The active policy must never be sticky closure state that
867
+ // outlives the config that set it: a caller-supplied policy left in place
868
+ // after `clearConfig()` — or after a later call that supplied none, or
869
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
870
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
871
+ // See GHSA-vxr8-fq34-vvx9.
872
+ if (cfg.TRUSTED_TYPES_POLICY) {
873
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
874
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
875
+ }
876
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
877
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
878
+ }
879
+ // A caller-supplied policy applies to this configuration only.
880
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
881
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
882
+ // Sign local variables required by `sanitize`. If the supplied policy's
883
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
884
+ // throws via the re-entrancy guard. Restore the previous policy first so
885
+ // the instance is not left in a poisoned state. See #1422.
886
+ try {
887
+ emptyHTML = _createTrustedHTML('');
888
+ } catch (error) {
889
+ trustedTypesPolicy = previousTrustedTypesPolicy;
890
+ throw error;
891
+ }
892
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
893
+ // Explicit opt-out for this call: perform no Trusted Types signing and
894
+ // create nothing (so a strict `trusted-types` CSP that disallows a
895
+ // `dompurify` policy can still call `sanitize` from inside its own
896
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
897
+ // `null` also drops any previously retained caller policy, so it cannot
898
+ // resurface on a later call, while still allowing the next config-less
899
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
900
+ trustedTypesPolicy = undefined;
901
+ emptyHTML = '';
902
+ } else {
903
+ // No policy supplied: keep the currently active policy if one is set — a
904
+ // previously supplied policy is intentionally sticky across config-less
905
+ // calls — otherwise fall back to the instance's own internal policy,
906
+ // created at most once. (A policy supplied for a *single* call still
907
+ // lingers by design; what must not linger is a policy whose configuration
908
+ // has been torn down via `clearConfig()`, which restores the default.)
909
+ if (trustedTypesPolicy === undefined) {
910
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
911
+ }
912
+ // Sign internal variables only when a policy is active. A falsy policy
913
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
914
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
915
+ // a non-policy and throw. See #1422.
916
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
917
+ emptyHTML = _createTrustedHTML('');
918
+ }
919
+ }
920
+ // Prevent further manipulation of configuration.
921
+ // Not available in IE8, Safari 5, etc.
922
+ if (freeze) {
923
+ freeze(cfg);
924
+ }
925
+ CONFIG = cfg;
926
+ };
927
+ /* Keep track of all possible SVG and MathML tags
928
+ * so that we can perform the namespace checks
929
+ * correctly. */
930
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
931
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
932
+ /**
933
+ * Namespace rules for an element in the SVG namespace.
934
+ *
935
+ * @param tagName the element's lowercase tag name
936
+ * @param parent the (possibly simulated) parent node
937
+ * @param parentTagName the parent's lowercase tag name
938
+ * @returns true if a spec-compliant parser could produce this element
939
+ */
940
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
941
+ // The only way to switch from HTML namespace to SVG
942
+ // is via <svg>. If it happens via any other tag, then
943
+ // it should be killed.
944
+ if (parent.namespaceURI === HTML_NAMESPACE) {
945
+ return tagName === 'svg';
946
+ }
947
+ // The only way to switch from MathML to SVG is via <svg>
948
+ // if the parent is either <annotation-xml> or a MathML
949
+ // text integration point.
950
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
951
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
952
+ }
953
+ // We only allow elements that are defined in SVG
954
+ // spec. All others are disallowed in SVG namespace.
955
+ return Boolean(ALL_SVG_TAGS[tagName]);
956
+ };
957
+ /**
958
+ * Namespace rules for an element in the MathML 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 _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
966
+ // The only way to switch from HTML namespace to MathML
967
+ // is via <math>. If it happens via any other tag, then
968
+ // it should be killed.
969
+ if (parent.namespaceURI === HTML_NAMESPACE) {
970
+ return tagName === 'math';
971
+ }
972
+ // The only way to switch from SVG to MathML is via
973
+ // <math> and HTML integration points
974
+ if (parent.namespaceURI === SVG_NAMESPACE) {
975
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
976
+ }
977
+ // We only allow elements that are defined in MathML
978
+ // spec. All others are disallowed in MathML namespace.
979
+ return Boolean(ALL_MATHML_TAGS[tagName]);
980
+ };
981
+ /**
982
+ * Namespace rules for an element in the HTML namespace.
983
+ *
984
+ * @param tagName the element's lowercase tag name
985
+ * @param parent the (possibly simulated) parent node
986
+ * @param parentTagName the parent's lowercase tag name
987
+ * @returns true if a spec-compliant parser could produce this element
988
+ */
989
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
990
+ // The only way to switch from SVG to HTML is via
991
+ // HTML integration points, and from MathML to HTML
992
+ // is via MathML text integration points
993
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
994
+ return false;
995
+ }
996
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
997
+ return false;
998
+ }
999
+ // We disallow tags that are specific for MathML
1000
+ // or SVG and should never appear in HTML namespace
1001
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1002
+ };
1003
+ /**
1004
+ * @param element a DOM element whose namespace is being checked
1005
+ * @returns Return false if the element has a
1006
+ * namespace that a spec-compliant parser would never
1007
+ * return. Return true otherwise.
1008
+ */
1009
+ const _checkValidNamespace = function _checkValidNamespace(element) {
1010
+ let parent = getParentNode(element);
1011
+ // In JSDOM, if we're inside shadow DOM, then parentNode
1012
+ // can be null. We just simulate parent in this case.
1013
+ if (!parent || !parent.tagName) {
1014
+ parent = {
1015
+ namespaceURI: NAMESPACE,
1016
+ tagName: 'template'
1017
+ };
1018
+ }
1019
+ const tagName = stringToLowerCase(element.tagName);
1020
+ const parentTagName = stringToLowerCase(parent.tagName);
1021
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
1022
+ return false;
1023
+ }
1024
+ if (element.namespaceURI === SVG_NAMESPACE) {
1025
+ return _checkSvgNamespace(tagName, parent, parentTagName);
1026
+ }
1027
+ if (element.namespaceURI === MATHML_NAMESPACE) {
1028
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
1029
+ }
1030
+ if (element.namespaceURI === HTML_NAMESPACE) {
1031
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
1032
+ }
1033
+ // For XHTML and XML documents that support custom namespaces
1034
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
1035
+ return true;
1036
+ }
1037
+ // The code should never reach this place (this means
1038
+ // that the element somehow got namespace that is not
1039
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
1040
+ // Return false just in case.
1041
+ return false;
1042
+ };
1043
+ /**
1044
+ * _forceRemove
1045
+ *
1046
+ * @param node a DOM node
1047
+ */
1048
+ const _forceRemove = function _forceRemove(node) {
1049
+ arrayPush(DOMPurify.removed, {
1050
+ element: node
1051
+ });
1052
+ try {
1053
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
1054
+ getParentNode(node).removeChild(node);
1055
+ } catch (_) {
1056
+ /* The normal detach failed — this is reached for a parentless node
1057
+ (getParentNode() is null, so .removeChild throws). Element.prototype
1058
+ .remove() is itself a spec no-op on a parentless node, so a recorded
1059
+ "removal" would otherwise hand the caller back an intact,
1060
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
1061
+ the style-with-element-child rule decided to kill). Fail closed by
1062
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
1063
+ rather than trying to "neutralize" the node via its own methods.
1064
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
1065
+ on the node, both of which a <form> root can clobber via a named child
1066
+ (and _isClobbered does not even probe getAttributeNames), so the
1067
+ neutralize step could itself be silently defeated, leaving the payload
1068
+ intact. A throw touches only the cached, clobber-safe remove() and
1069
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
1070
+ to every root-kill reason. REPORT-3.
1071
+ This lives inside the catch, so it never fires for a normally-removed
1072
+ in-tree node: those have a parent, removeChild() succeeds, and the
1073
+ catch is not entered. Only a kept (parentless) root reaches here. */
1074
+ remove(node);
1075
+ if (!getParentNode(node)) {
1076
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
1077
+ }
1078
+ }
1079
+ };
1080
+ /**
1081
+ * _neutralizeRoot
1082
+ *
1083
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
1084
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
1085
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
1086
+ * parentless guard throws, or any other re-entrant engine mutation — would
1087
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
1088
+ * after the abort point still carrying its handlers. There is no safe way
1089
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
1090
+ * remove every child and every attribute, then let the caller's catch see
1091
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
1092
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
1093
+ *
1094
+ * @param root the in-place root to empty
1095
+ */
1096
+ const _neutralizeRoot = function _neutralizeRoot(root) {
1097
+ const childNodes = getChildNodes(root);
1098
+ if (childNodes) {
1099
+ const snapshot = [];
1100
+ arrayForEach(childNodes, child => {
1101
+ arrayPush(snapshot, child);
1102
+ });
1103
+ arrayForEach(snapshot, child => {
1104
+ try {
1105
+ remove(child);
1106
+ } catch (_) {
1107
+ /* Best-effort teardown; a still-attached child is handled below */
1108
+ }
1109
+ });
1110
+ }
1111
+ const attributes = getAttributes(root);
1112
+ if (attributes) {
1113
+ for (let i = attributes.length - 1; i >= 0; --i) {
1114
+ const attribute = attributes[i];
1115
+ const name = attribute && attribute.name;
1116
+ if (typeof name === 'string') {
1117
+ try {
1118
+ root.removeAttribute(name);
1119
+ } catch (_) {
1120
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
1121
+ }
1122
+ }
1123
+ }
1124
+ }
1125
+ };
1126
+ /**
1127
+ * _removeAttribute
1128
+ *
1129
+ * @param name an Attribute name
1130
+ * @param element a DOM node
1131
+ */
1132
+ const _removeAttribute = function _removeAttribute(name, element) {
1133
+ try {
1134
+ arrayPush(DOMPurify.removed, {
1135
+ attribute: element.getAttributeNode(name),
1136
+ from: element
1137
+ });
1138
+ } catch (_) {
1139
+ arrayPush(DOMPurify.removed, {
1140
+ attribute: null,
1141
+ from: element
1142
+ });
1143
+ }
1144
+ element.removeAttribute(name);
1145
+ // We void attribute values for unremovable "is" attributes
1146
+ if (name === 'is') {
1147
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
1148
+ try {
1149
+ _forceRemove(element);
1150
+ } catch (_) {}
1151
+ } else {
1152
+ try {
1153
+ element.setAttribute(name, '');
1154
+ } catch (_) {}
1155
+ }
1156
+ }
1157
+ };
1158
+ /**
1159
+ * _stripDisallowedAttributes
1160
+ *
1161
+ * Removes every attribute the active configuration does not allow from a
1162
+ * single element, using the same allowlist as the main attribute pass (so
1163
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
1164
+ * neutralise nodes that are being discarded from an in-place tree.
1165
+ *
1166
+ * @param element the element to strip
1167
+ */
1168
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
1169
+ const attributes = getAttributes(element);
1170
+ if (!attributes) {
1171
+ return;
1172
+ }
1173
+ for (let i = attributes.length - 1; i >= 0; --i) {
1174
+ const attribute = attributes[i];
1175
+ const name = attribute && attribute.name;
1176
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
1177
+ continue;
1178
+ }
1179
+ try {
1180
+ element.removeAttribute(name);
1181
+ } catch (_) {
1182
+ /* Clobbered removeAttribute on a doomed node — ignore */
1183
+ }
1184
+ }
1185
+ };
1186
+ /**
1187
+ * _neutralizeSubtree
1188
+ *
1189
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
1190
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
1191
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
1192
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
1193
+ * those dropped nodes are detached from the caller's LIVE tree but a
1194
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
1195
+ * loading) keeps its queued resource event, which fires in page scope after
1196
+ * sanitize returns. This walks a removed subtree and strips every attribute
1197
+ * the active configuration does not allow — so `on*` handlers are cancelled
1198
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
1199
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
1200
+ * queued event can fire. Hook-free by design: these nodes leave the output,
1201
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
1202
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
1203
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
1204
+ * the `<img>`, are reached and scrubbed).
1205
+ *
1206
+ * @param root the root of a removed subtree to neutralise
1207
+ */
1208
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
1209
+ const stack = [root];
1210
+ while (stack.length > 0) {
1211
+ const node = stack.pop();
1212
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1213
+ if (nodeType === NODE_TYPE.element) {
1214
+ _stripDisallowedAttributes(node);
1215
+ }
1216
+ const childNodes = getChildNodes(node);
1217
+ if (childNodes) {
1218
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1219
+ stack.push(childNodes[i]);
1220
+ }
1221
+ }
1222
+ }
1223
+ };
1224
+ /**
1225
+ * _initDocument
1226
+ *
1227
+ * @param dirty - a string of dirty markup
1228
+ * @return a DOM, filled with the dirty markup
1229
+ */
1230
+ const _initDocument = function _initDocument(dirty) {
1231
+ /* Create a HTML document */
1232
+ let doc = null;
1233
+ let leadingWhitespace = null;
1234
+ if (FORCE_BODY) {
1235
+ dirty = '<remove></remove>' + dirty;
1236
+ } else {
1237
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
1238
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1239
+ leadingWhitespace = matches && matches[0];
1240
+ }
1241
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
1242
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
1243
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
1244
+ }
1245
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
1246
+ /*
1247
+ * Use the DOMParser API by default, fallback later if needs be
1248
+ * DOMParser not work for svg when has multiple root element.
1249
+ */
1250
+ if (NAMESPACE === HTML_NAMESPACE) {
1251
+ try {
1252
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
1253
+ } catch (_) {}
1254
+ }
1255
+ /* Use createHTMLDocument in case DOMParser is not available */
1256
+ if (!doc || !doc.documentElement) {
1257
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
1258
+ try {
1259
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
1260
+ } catch (_) {
1261
+ // Syntax error if dirtyPayload is invalid xml
1262
+ }
1263
+ }
1264
+ const body = doc.body || doc.documentElement;
1265
+ if (dirty && leadingWhitespace) {
1266
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
1267
+ }
1268
+ /* Work on whole document or just its body */
1269
+ if (NAMESPACE === HTML_NAMESPACE) {
1270
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
1271
+ }
1272
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
1273
+ };
1274
+ /**
1275
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
1276
+ *
1277
+ * @param root The root element or node to start traversing on.
1278
+ * @return The created NodeIterator
1279
+ */
1280
+ const _createNodeIterator = function _createNodeIterator(root) {
1281
+ return createNodeIterator.call(root.ownerDocument || root, root,
1282
+ // eslint-disable-next-line no-bitwise
1283
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1284
+ };
1285
+ /**
1286
+ * Replace template expression syntax (mustache, ERB, template
1287
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
1288
+ * sites. Order matters: mustache, then ERB, then template literal.
1289
+ *
1290
+ * @param value the string to scrub
1291
+ * @returns the scrubbed string
1292
+ */
1293
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
1294
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
1295
+ value = stringReplace(value, ERB_EXPR$1, ' ');
1296
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
1297
+ return value;
1298
+ };
1299
+ /**
1300
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
1301
+ * character data of an element subtree. Used as the final safety net for
1302
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
1303
+ * which only form after text-node normalization (e.g. fragments split across
1304
+ * stripped elements) cannot survive into a template-evaluating framework.
1305
+ *
1306
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
1307
+ * in place rather than round-tripping through innerHTML. This preserves
1308
+ * descendant node references (important for IN_PLACE callers), avoids a
1309
+ * serialize/reparse cycle, and reads literal character data — which means
1310
+ * `<%...%>` in text content matches the ERB regex against its real bytes
1311
+ * instead of the HTML-entity-escaped form innerHTML would produce.
1312
+ *
1313
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
1314
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
1315
+ *
1316
+ * @param node The root element whose character data should be scrubbed.
1317
+ */
1318
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
1319
+ var _node$querySelectorAl;
1320
+ node.normalize();
1321
+ const walker = createNodeIterator.call(node.ownerDocument || node, node,
1322
+ // eslint-disable-next-line no-bitwise
1323
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
1324
+ let currentNode = walker.nextNode();
1325
+ while (currentNode) {
1326
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
1327
+ currentNode = walker.nextNode();
1328
+ }
1329
+ // NodeIterator does not descend into <template>.content per the DOM spec,
1330
+ // so we must explicitly recurse into each template's content fragment,
1331
+ // mirroring the approach used by _sanitizeShadowDOM.
1332
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
1333
+ if (templates) {
1334
+ arrayForEach(templates, tmpl => {
1335
+ if (_isDocumentFragment(tmpl.content)) {
1336
+ _scrubTemplateExpressions2(tmpl.content);
1337
+ }
1338
+ });
1339
+ }
1340
+ };
1341
+ /**
1342
+ * _isClobbered
1343
+ *
1344
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
1345
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
1346
+ * `name` attribute matching a prototype property shadows that property
1347
+ * on direct reads. We use this check at the IN_PLACE entry-point and
1348
+ * during attribute sanitization to refuse clobbered forms.
1349
+ *
1350
+ * @param element element to check for clobbering attacks
1351
+ * @return true if clobbered, false if safe
1352
+ */
1353
+ const _isClobbered = function _isClobbered(element) {
1354
+ // Realm-independent tag-name probe. If we can't determine the tag
1355
+ // name at all, we can't reason about clobbering — return false
1356
+ // (the caller's other defences still apply).
1357
+ const realTagName = getNodeName ? getNodeName(element) : null;
1358
+ if (typeof realTagName !== 'string') {
1359
+ return false;
1360
+ }
1361
+ if (transformCaseFunc(realTagName) !== 'form') {
1362
+ return false;
1363
+ }
1364
+ return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
1365
+ // Realm-safe NamedNodeMap detection: equality against the cached
1366
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
1367
+ // makes the direct read diverge from the cached read; a clean form
1368
+ // (same-realm OR foreign-realm) has both reads pointing at the same
1369
+ // canonical NamedNodeMap.
1370
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
1371
+ // NodeType clobbering probe. Cached Node.prototype.nodeType getter
1372
+ // returns the integer 1 for any Element regardless of realm; direct
1373
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
1374
+ // the named child element. Cheap addition — nodeType is read from
1375
+ // an internal slot, no serialization cost — and removes a residual
1376
+ // clobbering surface used by several mXSS / PI / comment branches
1377
+ // in _sanitizeElements that compare currentNode.nodeType directly.
1378
+ element.nodeType !== getNodeType(element) ||
1379
+ // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
1380
+ // "childNodes" shadows the prototype getter. Direct reads of
1381
+ // form.childNodes from a clobbered form return the named child
1382
+ // instead of the real NodeList, so any walk that reads it directly
1383
+ // skips the form's real children. Compare the direct read to the
1384
+ // cached Node.prototype getter — when the form's named-property
1385
+ // getter intercepts the read, the two values differ and we flag
1386
+ // the form. This catches every clobbering child type (input,
1387
+ // select, etc.) regardless of whether the named child happens to
1388
+ // carry a numeric .length, which a typeof-based probe would miss
1389
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
1390
+ element.childNodes !== getChildNodes(element);
1391
+ };
1392
+ /**
1393
+ * Checks whether the given value is a DocumentFragment from any realm.
1394
+ *
1395
+ * The realm-independent replacement reads `nodeType` through the cached
1396
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
1397
+ * constant (11). nodeType is a numeric value resolved from the node's
1398
+ * internal slot, identical across realms for the same kind of node.
1399
+ *
1400
+ * @param value object to check
1401
+ * @return true if value is a DocumentFragment-shaped node from any realm
1402
+ */
1403
+ const _isDocumentFragment = function _isDocumentFragment(value) {
1404
+ if (!getNodeType || typeof value !== 'object' || value === null) {
1405
+ return false;
1406
+ }
1407
+ try {
1408
+ return getNodeType(value) === NODE_TYPE.documentFragment;
1409
+ } catch (_) {
1410
+ return false;
1411
+ }
1412
+ };
1413
+ /**
1414
+ * Checks whether the given object is a DOM node, including nodes that
1415
+ * originate from a different window/realm (e.g. an iframe's
1416
+ * contentDocument). The previous `value instanceof Node` check was
1417
+ * realm-bound: nodes from a different window failed it, causing
1418
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
1419
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
1420
+ *
1421
+ * @param value object to check whether it's a DOM node
1422
+ * @return true if value is a DOM node from any realm
1423
+ */
1424
+ const _isNode = function _isNode(value) {
1425
+ if (!getNodeType || typeof value !== 'object' || value === null) {
1426
+ return false;
1427
+ }
1428
+ try {
1429
+ return typeof getNodeType(value) === 'number';
1430
+ } catch (_) {
1431
+ return false;
1432
+ }
1433
+ };
1434
+ function _executeHooks(hooks, currentNode, data) {
1435
+ if (hooks.length === 0) {
1436
+ return;
1437
+ }
1438
+ arrayForEach(hooks, hook => {
1439
+ hook.call(DOMPurify, currentNode, data, CONFIG);
1440
+ });
1441
+ }
1442
+ /**
1443
+ * Structural-threat checks that condemn a node regardless of the
1444
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
1445
+ * processing instructions, markup-bearing comments. Pure predicate;
1446
+ * the caller removes. Check order is load-bearing.
1447
+ *
1448
+ * @param currentNode the node to inspect
1449
+ * @param tagName the node's transformCaseFunc'd tag name
1450
+ * @return true if the node must be removed
1451
+ */
1452
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
1453
+ /* Detect mXSS attempts abusing namespace confusion */
1454
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
1455
+ return true;
1456
+ }
1457
+ /* Remove risky CSS construction leading to mXSS */
1458
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
1459
+ return true;
1460
+ }
1461
+ /* Remove any occurrence of processing instructions */
1462
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
1463
+ return true;
1464
+ }
1465
+ /* Remove any kind of possibly harmful comments */
1466
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
1467
+ return true;
1468
+ }
1469
+ return false;
1470
+ };
1471
+ /**
1472
+ * Handle a node whose tag is forbidden or not allowlisted: keep
1473
+ * allowed custom elements (false return exits _sanitizeElements
1474
+ * early - namespace/fallback checks and the afterSanitizeElements
1475
+ * hook are intentionally skipped for kept custom elements), else
1476
+ * hoist content per KEEP_CONTENT and remove.
1477
+ *
1478
+ * @param currentNode the disallowed node
1479
+ * @param tagName the node's transformCaseFunc'd tag name
1480
+ * @return true if the node was removed, false if kept
1481
+ */
1482
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
1483
+ /* Check if we have a custom element to handle */
1484
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
1485
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1486
+ return false;
1487
+ }
1488
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
1489
+ return false;
1490
+ }
1491
+ }
1492
+ /* Keep content except for bad-listed elements.
1493
+ Use the cached prototype getters exclusively — the previous code
1494
+ had `|| currentNode.parentNode` / `|| currentNode.childNodes`
1495
+ fallbacks, but the cached getters always return the canonical
1496
+ value (or null for a real parent-less node), so the fallback
1497
+ path was dead in safe cases and a clobbering surface in unsafe
1498
+ ones. Falsy cached results stay falsy; the `if (childNodes &&
1499
+ parentNode)` check already gates correctly. */
1500
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1501
+ const parentNode = getParentNode(currentNode);
1502
+ const childNodes = getChildNodes(currentNode);
1503
+ if (childNodes && parentNode) {
1504
+ const childCount = childNodes.length;
1505
+ /* In-place: hoist the *original* children so the iterator visits
1506
+ and sanitises them through the same allowlist pass as every other
1507
+ node. The caller built the tree in the live document, so the
1508
+ originals carry already-queued resource events (`<img onerror>`,
1509
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
1510
+ those originals detached but still armed, firing in page scope
1511
+ while the returned tree looked clean. Moving is safe in-place: the
1512
+ root is pre-validated as an allowed tag and so is never the node
1513
+ being removed, which keeps `parentNode` inside the iterator root
1514
+ and the relocated child inside the serialised tree.
1515
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
1516
+ at — and the result serialised from — `body`, so a restrictive
1517
+ ALLOWED_TAGS that removes `body` itself must leave its content in
1518
+ place, which only cloning does; and those paths parse into an
1519
+ inert document, so their discarded originals never had a queued
1520
+ event to neutralise.
1521
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
1522
+ valid whether we move (drops the trailing entry) or clone (leaves
1523
+ the list intact). */
1524
+ for (let i = childCount - 1; i >= 0; --i) {
1525
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
1526
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
1527
+ }
1528
+ }
1529
+ }
1530
+ _forceRemove(currentNode);
1531
+ return true;
1532
+ };
1533
+ /**
1534
+ * _sanitizeElements
1535
+ *
1536
+ * @protect nodeName
1537
+ * @protect textContent
1538
+ * @protect removeChild
1539
+ * @param currentNode to check for permission to exist
1540
+ * @return true if node was killed, false if left alive
1541
+ */
1542
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
1543
+ /* Execute a hook if present */
1544
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
1545
+ /* Check if element is clobbered or can clobber */
1546
+ if (_isClobbered(currentNode)) {
1547
+ _forceRemove(currentNode);
1548
+ return true;
1549
+ }
1550
+ /* Now let's check the element's type and name */
1551
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
1552
+ /* Execute a hook if present */
1553
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
1554
+ tagName,
1555
+ allowedTags: ALLOWED_TAGS
1556
+ });
1557
+ /* Remove mXSS vectors, processing instructions and risky comments */
1558
+ if (_isUnsafeNode(currentNode, tagName)) {
1559
+ _forceRemove(currentNode);
1560
+ return true;
1561
+ }
1562
+ /* Remove element if anything forbids its presence */
1563
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
1564
+ return _sanitizeDisallowedNode(currentNode, tagName);
1565
+ }
1566
+ /* Check whether element has a valid namespace.
1567
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
1568
+ nodeType getter rather than `instanceof Element`, which is realm-
1569
+ bound and short-circuits to false for any node minted in a different
1570
+ realm — letting a foreign-realm element with a forbidden namespace
1571
+ slip past the namespace check entirely. */
1572
+ const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
1573
+ if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
1574
+ _forceRemove(currentNode);
1575
+ return true;
1576
+ }
1577
+ /* Make sure that older browsers don't get fallback-tag mXSS */
1578
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
1579
+ _forceRemove(currentNode);
1580
+ return true;
1581
+ }
1582
+ /* Sanitize element content to be template-safe */
1583
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1584
+ /* Get the element's text content */
1585
+ const content = _stripTemplateExpressions(currentNode.textContent);
1586
+ if (currentNode.textContent !== content) {
1587
+ arrayPush(DOMPurify.removed, {
1588
+ element: currentNode.cloneNode()
1589
+ });
1590
+ currentNode.textContent = content;
1591
+ }
1592
+ }
1593
+ /* Execute a hook if present */
1594
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1595
+ return false;
1596
+ };
1597
+ /**
1598
+ * _isValidAttribute
1599
+ *
1600
+ * @param lcTag Lowercase tag name of containing element.
1601
+ * @param lcName Lowercase attribute name.
1602
+ * @param value Attribute value.
1603
+ * @return Returns true if `value` is valid, otherwise false.
1604
+ */
1605
+ // eslint-disable-next-line complexity
1606
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1607
+ /* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
1608
+ if (FORBID_ATTR[lcName]) {
1609
+ return false;
1610
+ }
1611
+ /* Make sure attribute cannot clobber */
1612
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1613
+ return false;
1614
+ }
1615
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
1616
+ /* Allow valid data-* attributes: At least one character after "-"
1617
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1618
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1619
+ We don't need to check the value; it's always URI safe. */
1620
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
1621
+ if (
1622
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1623
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1624
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1625
+ _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||
1626
+ // Alternative, second condition checks if it's an `is`-attribute, AND
1627
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1628
+ lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1629
+ return false;
1630
+ }
1631
+ /* Check value is safe. First, is attr inert? If so, is safe */
1632
+ } 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) {
1633
+ return false;
1634
+ } else ;
1635
+ return true;
1636
+ };
1637
+ /* Names the HTML spec reserves from valid-custom-element-name; these must
1638
+ * never be treated as basic custom elements even when a permissive
1639
+ * CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
1640
+ 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']);
1641
+ /**
1642
+ * _isBasicCustomElement
1643
+ * checks if at least one dash is included in tagName, and it's not the first char
1644
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1645
+ *
1646
+ * @param tagName name of the tag of the node to sanitize
1647
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1648
+ */
1649
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1650
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
1651
+ };
1652
+ /**
1653
+ * Wrap an attribute value in the matching Trusted Types object when
1654
+ * the active policy requires it. Namespaced attributes pass through
1655
+ * unchanged (no TT support yet, see
1656
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
1657
+ *
1658
+ * @param lcTag lowercase tag name of the containing element
1659
+ * @param lcName lowercase attribute name
1660
+ * @param namespaceURI the attribute's namespace, if any
1661
+ * @param value the attribute value to wrap
1662
+ * @return the value, wrapped when Trusted Types demand it
1663
+ */
1664
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
1665
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
1666
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1667
+ case 'TrustedHTML':
1668
+ {
1669
+ return _createTrustedHTML(value);
1670
+ }
1671
+ case 'TrustedScriptURL':
1672
+ {
1673
+ return _createTrustedScriptURL(value);
1674
+ }
1675
+ }
1676
+ }
1677
+ return value;
1678
+ };
1679
+ /**
1680
+ * Write a modified attribute value back onto the element. On
1681
+ * success, re-probe for clobbering introduced by the new value and
1682
+ * remove the element when found; otherwise pop the removal entry
1683
+ * recorded by the earlier _removeAttribute (long-standing pairing
1684
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
1685
+ * failure, remove the attribute instead.
1686
+ *
1687
+ * @param currentNode the element carrying the attribute
1688
+ * @param name the attribute name as present on the element
1689
+ * @param namespaceURI the attribute's namespace, if any
1690
+ * @param value the new attribute value
1691
+ */
1692
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
1693
+ try {
1694
+ if (namespaceURI) {
1695
+ currentNode.setAttributeNS(namespaceURI, name, value);
1696
+ } else {
1697
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1698
+ currentNode.setAttribute(name, value);
1699
+ }
1700
+ if (_isClobbered(currentNode)) {
1701
+ _forceRemove(currentNode);
1702
+ } else {
1703
+ arrayPop(DOMPurify.removed);
1704
+ }
1705
+ } catch (_) {
1706
+ _removeAttribute(name, currentNode);
1707
+ }
1708
+ };
1709
+ /**
1710
+ * _sanitizeAttributes
1711
+ *
1712
+ * @protect attributes
1713
+ * @protect nodeName
1714
+ * @protect removeAttribute
1715
+ * @protect setAttribute
1716
+ *
1717
+ * @param currentNode to sanitize
1718
+ */
1719
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1720
+ /* Execute a hook if present */
1721
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1722
+ const attributes = currentNode.attributes;
1723
+ /* Check if we have attributes; if not we might have a text node */
1724
+ if (!attributes || _isClobbered(currentNode)) {
1725
+ return;
1726
+ }
1727
+ const hookEvent = {
1728
+ attrName: '',
1729
+ attrValue: '',
1730
+ keepAttr: true,
1731
+ allowedAttributes: ALLOWED_ATTR,
1732
+ forceKeepAttr: undefined
1733
+ };
1734
+ let l = attributes.length;
1735
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1736
+ /* Go backwards over all attributes; safely remove bad ones */
1737
+ while (l--) {
1738
+ const attr = attributes[l];
1739
+ const name = attr.name,
1740
+ namespaceURI = attr.namespaceURI,
1741
+ attrValue = attr.value;
1742
+ const lcName = transformCaseFunc(name);
1743
+ const initValue = attrValue;
1744
+ let value = name === 'value' ? initValue : stringTrim(initValue);
1745
+ /* Execute a hook if present */
1746
+ hookEvent.attrName = lcName;
1747
+ hookEvent.attrValue = value;
1748
+ hookEvent.keepAttr = true;
1749
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1750
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1751
+ value = hookEvent.attrValue;
1752
+ /* Full DOM Clobbering protection via namespace isolation,
1753
+ * Prefix id and name attributes with `user-content-`
1754
+ */
1755
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
1756
+ // Remove the attribute with this value
1757
+ _removeAttribute(name, currentNode);
1758
+ // Prefix the value and later re-create the attribute with the sanitized value
1759
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1760
+ }
1761
+ // Else: already prefixed, leave the attribute alone — the prefix is
1762
+ // itself the clobbering protection, and re-applying it is incorrect.
1763
+ /* Work around a security issue with comments inside attributes */
1764
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
1765
+ _removeAttribute(name, currentNode);
1766
+ continue;
1767
+ }
1768
+ /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
1769
+ if (lcName === 'attributename' && stringMatch(value, 'href')) {
1770
+ _removeAttribute(name, currentNode);
1771
+ continue;
1772
+ }
1773
+ /* Did the hooks force-keep the attribute? */
1774
+ if (hookEvent.forceKeepAttr) {
1775
+ continue;
1776
+ }
1777
+ /* Did the hooks approve of the attribute? */
1778
+ if (!hookEvent.keepAttr) {
1779
+ _removeAttribute(name, currentNode);
1780
+ continue;
1781
+ }
1782
+ /* Work around a security issue in jQuery 3.0 */
1783
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
1784
+ _removeAttribute(name, currentNode);
1785
+ continue;
1786
+ }
1787
+ /* Sanitize attribute content to be template-safe */
1788
+ if (SAFE_FOR_TEMPLATES) {
1789
+ value = _stripTemplateExpressions(value);
1790
+ }
1791
+ /* Is `value` valid for this attribute? */
1792
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1793
+ _removeAttribute(name, currentNode);
1794
+ continue;
1795
+ }
1796
+ /* Handle attributes that require Trusted Types */
1797
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
1798
+ /* Handle invalid data-* attribute set by try-catching it */
1799
+ if (value !== initValue) {
1800
+ _setAttributeValue(currentNode, name, namespaceURI, value);
1801
+ }
1802
+ }
1803
+ /* Execute a hook if present */
1804
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1805
+ };
1806
+ /**
1807
+ * _sanitizeShadowDOM
1808
+ *
1809
+ * @param fragment to iterate over recursively
1810
+ */
1811
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
1812
+ let shadowNode = null;
1813
+ const shadowIterator = _createNodeIterator(fragment);
1814
+ /* Execute a hook if present */
1815
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1816
+ while (shadowNode = shadowIterator.nextNode()) {
1817
+ /* Execute a hook if present */
1818
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1819
+ /* Sanitize tags and elements */
1820
+ _sanitizeElements(shadowNode);
1821
+ /* Check attributes next */
1822
+ _sanitizeAttributes(shadowNode);
1823
+ /* Deep shadow DOM detected.
1824
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
1825
+ DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
1826
+ recurse into <template>.content from foreign realms too. */
1827
+ if (_isDocumentFragment(shadowNode.content)) {
1828
+ _sanitizeShadowDOM2(shadowNode.content);
1829
+ }
1830
+ /* An element iterated here may itself host an attached
1831
+ shadow root. The default NodeIterator does not enter shadow
1832
+ trees, so a shadow root nested inside template.content was
1833
+ previously reached by no walk at all (the pre-pass at
1834
+ _sanitizeAttachedShadowRoots descends via childNodes, which
1835
+ doesn't enter template.content; the template-content recursion
1836
+ above iterates the content but never inspected shadowRoot).
1837
+ Walk it explicitly. The nodeType guard avoids reading
1838
+ shadowRoot off text / comment / CDATA / PI nodes that the
1839
+ iterator also surfaces. */
1840
+ const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
1841
+ if (shadowNodeType === NODE_TYPE.element) {
1842
+ const innerSr = getShadowRoot(shadowNode);
1843
+ if (_isDocumentFragment(innerSr)) {
1844
+ _sanitizeAttachedShadowRoots(innerSr);
1845
+ _sanitizeShadowDOM2(innerSr);
1846
+ }
1847
+ }
1848
+ }
1849
+ /* Execute a hook if present */
1850
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1851
+ };
1852
+ /**
1853
+ * _sanitizeAttachedShadowRoots
1854
+ *
1855
+ * Walks `root` and feeds every attached shadow root we encounter into
1856
+ * the existing _sanitizeShadowDOM pipeline. The default node iterator
1857
+ * does not descend into shadow trees, so nodes inside an attached
1858
+ * shadow root would otherwise be skipped entirely.
1859
+ *
1860
+ * Two real input paths put attached shadow roots in front of us:
1861
+ * 1. IN_PLACE on a DOM node that already has shadow roots attached.
1862
+ * 2. DOM-node input where importNode(dirty, true) deep-clones the
1863
+ * shadow root because it was created with `clonable: true`.
1864
+ *
1865
+ * This pass runs once, up front, so the main iteration loop (and the
1866
+ * existing _sanitizeShadowDOM template-content recursion) stay
1867
+ * untouched — string-input paths are not affected.
1868
+ *
1869
+ * @param root the subtree root to walk for attached shadow roots
1870
+ */
1871
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
1872
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
1873
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
1874
+ built straight into the DOM — the IN_PLACE surface) deeper than the JS
1875
+ call-stack budget would otherwise overflow native recursion here and
1876
+ throw at the IN_PLACE entry pre-pass, before a single node is
1877
+ sanitized, leaving the caller's live tree untouched (fail-open). See
1878
+ campaign-3 F4. A heap stack keeps depth off the call stack.
1879
+ Each work item is either a node to descend into, or a deferred
1880
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
1881
+ form preserves the original post-order discipline: a shadow root's
1882
+ nested shadow roots are discovered before the outer shadow is
1883
+ sanitized (which may remove hosts). Pushes are in reverse of the
1884
+ desired processing order (LIFO): template content, then children, then
1885
+ the shadow-sanitize, then the shadow walk — so the order matches the
1886
+ previous recursion exactly. */
1887
+ const stack = [{
1888
+ node: root,
1889
+ shadow: null
1890
+ }];
1891
+ while (stack.length > 0) {
1892
+ const item = stack.pop();
1893
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
1894
+ if (item.shadow) {
1895
+ _sanitizeShadowDOM2(item.shadow);
1896
+ continue;
1897
+ }
1898
+ const node = item.node;
1899
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1900
+ const isElement = nodeType === NODE_TYPE.element;
1901
+ /* (pushed last → processed first) Children, snapshotted in reverse so
1902
+ the first child is processed first. Snapshotting matters because a
1903
+ hook may detach siblings mid-walk. */
1904
+ const childNodes = getChildNodes(node);
1905
+ if (childNodes) {
1906
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1907
+ stack.push({
1908
+ node: childNodes[i],
1909
+ shadow: null
1910
+ });
1911
+ }
1912
+ }
1913
+ /* (pushed before children → processed after them, matching the old
1914
+ "template content last" order) When the node is a <template>,
1915
+ descend into its content. */
1916
+ if (isElement) {
1917
+ const rootName = getNodeName ? getNodeName(node) : null;
1918
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
1919
+ const content = node.content;
1920
+ if (_isDocumentFragment(content)) {
1921
+ stack.push({
1922
+ node: content,
1923
+ shadow: null
1924
+ });
1925
+ }
1926
+ }
1927
+ }
1928
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
1929
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
1930
+ rather than `instanceof DocumentFragment`, which is realm-bound and
1931
+ silently skipped foreign-realm shadow roots (e.g.
1932
+ iframe.contentDocument attachShadow). */
1933
+ if (isElement) {
1934
+ const sr = getShadowRoot(node);
1935
+ if (_isDocumentFragment(sr)) {
1936
+ /* Push the deferred sanitise first so it pops after the shadow
1937
+ walk we push next, i.e. nested shadow roots are discovered
1938
+ before this one is sanitised. */
1939
+ stack.push({
1940
+ node: null,
1941
+ shadow: sr
1942
+ }, {
1943
+ node: sr,
1944
+ shadow: null
1945
+ });
1946
+ }
1947
+ }
1948
+ }
1949
+ };
1950
+ // eslint-disable-next-line complexity
1951
+ DOMPurify.sanitize = function (dirty) {
1952
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1953
+ let body = null;
1954
+ let importedNode = null;
1955
+ let currentNode = null;
1956
+ let returnNode = null;
1957
+ /* Make sure we have a string to sanitize.
1958
+ DO NOT return early, as this will return the wrong type if
1959
+ the user has requested a DOM object rather than a string */
1960
+ IS_EMPTY_INPUT = !dirty;
1961
+ if (IS_EMPTY_INPUT) {
1962
+ dirty = '<!-->';
1963
+ }
1964
+ /* Stringify, in case dirty is an object */
1965
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1966
+ dirty = stringifyValue(dirty);
1967
+ if (typeof dirty !== 'string') {
1968
+ throw typeErrorCreate('dirty is not a string, aborting');
1969
+ }
1970
+ }
1971
+ /* Return dirty HTML if DOMPurify cannot run */
1972
+ if (!DOMPurify.isSupported) {
1973
+ return dirty;
1974
+ }
1975
+ /* Assign config vars */
1976
+ if (SET_CONFIG) {
1977
+ /* Persistent setConfig() path: _parseConfig is skipped, so the sets are
1978
+ * not re-derived per call. Restore them from the pristine bindings
1979
+ * captured at setConfig() time so a previous call's hook clone (mutated
1980
+ * below) does not carry over. */
1981
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
1982
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
1983
+ } else {
1984
+ _parseConfig(cfg);
1985
+ }
1986
+ /* Clone the hook-mutable allowlists before the walk whenever an
1987
+ * uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
1988
+ * and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
1989
+ * a hook that widens them would otherwise mutate the shared set
1990
+ * permanently: across later calls and across every element. Cloning per
1991
+ * walk keeps documented in-call widening working while scoping it to the
1992
+ * call. A single guard for both config paths - the per-call path rebinds
1993
+ * the sets in _parseConfig each call, the persistent path restores them
1994
+ * from the captured bindings just above - so the two cannot diverge. */
1995
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
1996
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
1997
+ }
1998
+ if (hooks.uponSanitizeAttribute.length > 0) {
1999
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
2000
+ }
2001
+ /* Clean up removed elements */
2002
+ DOMPurify.removed = [];
2003
+ /* Resolve IN_PLACE for this call without mutating persistent config.
2004
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
2005
+ where _parseConfig is skipped on later calls: a single string call would
2006
+ disable in-place mode for every subsequent node call, returning a
2007
+ sanitized copy while leaving the caller's node — which in-place callers
2008
+ keep using and whose return value they ignore — unsanitized. REPORT-2. */
2009
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
2010
+ if (inPlace) {
2011
+ /* Do some early pre-sanitization to avoid unsafe root nodes.
2012
+ Read nodeName through the cached prototype getter — a clobbering
2013
+ child named "nodeName" on the form root would otherwise shadow
2014
+ the property and let this check skip the root-allowlist
2015
+ validation entirely. */
2016
+ const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
2017
+ if (typeof nn === 'string') {
2018
+ const tagName = transformCaseFunc(nn);
2019
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
2020
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
2021
+ }
2022
+ }
2023
+ /* Pre-flight the root through _isClobbered. The iterator-driven
2024
+ removal path can not detach a parent-less root: _forceRemove
2025
+ falls through to Element.prototype.remove(), which per spec
2026
+ is a no-op on a node with no parent. A clobbered root would
2027
+ then survive the main loop with its attributes uninspected,
2028
+ because _sanitizeAttributes early-returns on _isClobbered. The
2029
+ result would be an attacker-controlled form, complete with any
2030
+ event-handler attributes the caller passed in, handed back to
2031
+ the application unsanitized. Refuse to sanitize such a root
2032
+ the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
2033
+ if (_isClobbered(dirty)) {
2034
+ throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
2035
+ }
2036
+ /* Sanitize attached shadow roots before the main iterator runs.
2037
+ The iterator does not descend into shadow trees. Same fail-closed
2038
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
2039
+ inside a shadow root could abort this pre-pass before the walk runs,
2040
+ which would otherwise leave the entire live tree unsanitized. */
2041
+ try {
2042
+ _sanitizeAttachedShadowRoots(dirty);
2043
+ } catch (error) {
2044
+ _neutralizeRoot(dirty);
2045
+ throw error;
2046
+ }
2047
+ } else if (_isNode(dirty)) {
2048
+ /* If dirty is a DOM element, append to an empty document to avoid
2049
+ elements being stripped by the parser */
2050
+ body = _initDocument('<!---->');
2051
+ importedNode = body.ownerDocument.importNode(dirty, true);
2052
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
2053
+ /* Node is already a body, use as is */
2054
+ body = importedNode;
2055
+ } else if (importedNode.nodeName === 'HTML') {
2056
+ body = importedNode;
2057
+ } else {
2058
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
2059
+ body.appendChild(importedNode);
2060
+ }
2061
+ /* Clonable shadow roots are deep-cloned by importNode(); sanitize
2062
+ them before the main iterator runs, since the iterator does not
2063
+ descend into shadow trees. The walk routes every read through a
2064
+ cached prototype getter so clobbering descendants on a form root
2065
+ cannot hide a shadow host from this pass. */
2066
+ _sanitizeAttachedShadowRoots(importedNode);
2067
+ } else {
2068
+ /* Exit directly if we have nothing to do */
2069
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
2070
+ // eslint-disable-next-line unicorn/prefer-includes
2071
+ dirty.indexOf('<') === -1) {
2072
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
2073
+ }
2074
+ /* Initialize the document to work on */
2075
+ body = _initDocument(dirty);
2076
+ /* Check we have a DOM node from the data */
2077
+ if (!body) {
2078
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
2079
+ }
2080
+ }
2081
+ /* Remove first element node (ours) if FORCE_BODY is set */
2082
+ if (body && FORCE_BODY) {
2083
+ _forceRemove(body.firstChild);
2084
+ }
2085
+ /* Get node iterator */
2086
+ const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
2087
+ /* Now start iterating over the created document.
2088
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
2089
+ engine/custom-element mutation can detach a node mid-walk so
2090
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
2091
+ barrier the caller's in-place tree would be left half-sanitized with the
2092
+ unvisited tail still armed. On any throw we fail closed — strip the
2093
+ in-place root bare — then rethrow so the existing throw contract is
2094
+ preserved. (String/DOM-copy paths never return the partial body, so the
2095
+ propagating throw is already fail-closed there.) */
2096
+ try {
2097
+ while (currentNode = nodeIterator.nextNode()) {
2098
+ /* Sanitize tags and elements */
2099
+ _sanitizeElements(currentNode);
2100
+ /* Check attributes next */
2101
+ _sanitizeAttributes(currentNode);
2102
+ /* Shadow DOM detected, sanitize it.
2103
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
2104
+ instead of instanceof, so foreign-realm <template>.content is
2105
+ walked correctly. */
2106
+ if (_isDocumentFragment(currentNode.content)) {
2107
+ _sanitizeShadowDOM2(currentNode.content);
2108
+ }
2109
+ }
2110
+ } catch (error) {
2111
+ if (inPlace) {
2112
+ _neutralizeRoot(dirty);
2113
+ }
2114
+ throw error;
2115
+ }
2116
+ /* If we sanitized `dirty` in-place, return it. */
2117
+ if (inPlace) {
2118
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
2119
+ the caller's live tree is detached but may still hold a queued
2120
+ resource-event handler that fires in page scope after we return. The
2121
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
2122
+ non-allow-listed attributes off every other removed subtree (clobber,
2123
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
2124
+ cancelled before any event can fire. Runs synchronously, pre-return. */
2125
+ arrayForEach(DOMPurify.removed, entry => {
2126
+ if (entry.element) {
2127
+ _neutralizeSubtree(entry.element);
2128
+ }
2129
+ });
2130
+ if (SAFE_FOR_TEMPLATES) {
2131
+ _scrubTemplateExpressions2(dirty);
2132
+ }
2133
+ return dirty;
2134
+ }
2135
+ /* Return sanitized string or DOM */
2136
+ if (RETURN_DOM) {
2137
+ if (SAFE_FOR_TEMPLATES) {
2138
+ _scrubTemplateExpressions2(body);
2139
+ }
2140
+ if (RETURN_DOM_FRAGMENT) {
2141
+ returnNode = createDocumentFragment.call(body.ownerDocument);
2142
+ while (body.firstChild) {
2143
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
2144
+ returnNode.appendChild(body.firstChild);
2145
+ }
2146
+ } else {
2147
+ returnNode = body;
2148
+ }
2149
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
2150
+ /*
2151
+ AdoptNode() is not used because internal state is not reset
2152
+ (e.g. the past names map of a HTMLFormElement), this is safe
2153
+ in theory but we would rather not risk another attack vector.
2154
+ The state that is cloned by importNode() is explicitly defined
2155
+ by the specs.
2156
+ */
2157
+ returnNode = importNode.call(originalDocument, returnNode, true);
2158
+ }
2159
+ return returnNode;
2160
+ }
2161
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2162
+ /* Serialize doctype if allowed */
2163
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
2164
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
2165
+ }
2166
+ /* Sanitize final string template-safe */
2167
+ if (SAFE_FOR_TEMPLATES) {
2168
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
2169
+ }
2170
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
2171
+ };
2172
+ DOMPurify.setConfig = function () {
2173
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2174
+ _parseConfig(cfg);
2175
+ SET_CONFIG = true;
2176
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
2177
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
2178
+ };
2179
+ DOMPurify.clearConfig = function () {
2180
+ CONFIG = null;
2181
+ SET_CONFIG = false;
2182
+ SET_CONFIG_ALLOWED_TAGS = null;
2183
+ SET_CONFIG_ALLOWED_ATTR = null;
2184
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
2185
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
2186
+ // never recreated — Trusted Types throws on duplicate names) is restored by
2187
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
2188
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
2189
+ emptyHTML = '';
2190
+ };
2191
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
2192
+ /* Initialize shared config vars if necessary. */
2193
+ if (!CONFIG) {
2194
+ _parseConfig({});
2195
+ }
2196
+ const lcTag = transformCaseFunc(tag);
2197
+ const lcName = transformCaseFunc(attr);
2198
+ return _isValidAttribute(lcTag, lcName, value);
2199
+ };
2200
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
2201
+ if (typeof hookFunction !== 'function') {
2202
+ return;
2203
+ }
2204
+ /* Reject unknown entry points. Without this, a non-hook key (e.g.
2205
+ * '__proto__') indexes off the prototype chain rather than a real
2206
+ * hook array, and arrayPush then writes to Object.prototype. Guard
2207
+ * with an own-property check against the known hook names. */
2208
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2209
+ return;
2210
+ }
2211
+ arrayPush(hooks[entryPoint], hookFunction);
2212
+ };
2213
+ DOMPurify.removeHook = function (entryPoint, hookFunction) {
2214
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2215
+ return undefined;
2216
+ }
2217
+ if (hookFunction !== undefined) {
2218
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
2219
+ return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
2220
+ }
2221
+ return arrayPop(hooks[entryPoint]);
2222
+ };
2223
+ DOMPurify.removeHooks = function (entryPoint) {
2224
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2225
+ return;
2226
+ }
2227
+ hooks[entryPoint] = [];
2228
+ };
2229
+ DOMPurify.removeAllHooks = function () {
2230
+ hooks = _createHooksMap();
2231
+ };
2232
+ return DOMPurify;
2233
+ }
2234
+ var purify = createDOMPurify();
2235
+
2236
+ const sanitizeSvg = (svg) => {
2237
+ return purify.sanitize(svg, {
2238
+ USE_PROFILES: { svg: true },
2239
+ FORBID_ATTR: ['height', 'width'],
2240
+ });
2241
+ };
2242
+
2243
+ export { sanitizeSvg as s };