@ukic/web-components 3.27.0 → 3.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/components/close-icon.js +1 -2
  2. package/components/close-icon.js.map +1 -1
  3. package/components/ic-breadcrumb-group.js +16 -12
  4. package/components/ic-breadcrumb-group.js.map +1 -1
  5. package/components/ic-data-list.js +1 -1
  6. package/components/ic-data-list.js.map +1 -1
  7. package/components/ic-data-row.js +1 -1
  8. package/components/ic-data-row.js.map +1 -1
  9. package/components/ic-menu-item2.js +7 -2
  10. package/components/ic-menu-item2.js.map +1 -1
  11. package/components/ic-menu2.js +1153 -306
  12. package/components/ic-menu2.js.map +1 -1
  13. package/components/ic-pagination-bar.js.map +1 -1
  14. package/components/ic-pagination-item2.js +1 -1
  15. package/components/ic-pagination-item2.js.map +1 -1
  16. package/components/ic-pagination2.js +12 -8
  17. package/components/ic-pagination2.js.map +1 -1
  18. package/components/ic-popover-menu.js +46 -12
  19. package/components/ic-popover-menu.js.map +1 -1
  20. package/components/ic-radio-group.js.map +1 -1
  21. package/components/ic-search-bar.js +2 -6
  22. package/components/ic-search-bar.js.map +1 -1
  23. package/components/ic-section-container2.js +2 -2
  24. package/components/ic-skeleton.js +2 -2
  25. package/components/ic-skip-link.js +2 -2
  26. package/components/ic-status-tag.js +2 -2
  27. package/components/ic-step.js +13 -13
  28. package/components/ic-stepper.js +2 -2
  29. package/components/ic-switch.js +4 -4
  30. package/components/ic-switch.js.map +1 -1
  31. package/components/ic-tab-context.js +1 -1
  32. package/components/ic-tab-group.js +2 -2
  33. package/components/ic-tab-panel.js +2 -2
  34. package/components/ic-theme.js +1 -1
  35. package/components/ic-toast-region.js +1 -1
  36. package/components/ic-toast.js +5 -5
  37. package/components/ic-toggle-button-group.js +2 -2
  38. package/components/ic-toggle-button.js +2 -2
  39. package/dist/cjs/{close-icon-7f6ef8e4.js → close-icon-30d8bb41.js} +2 -3
  40. package/dist/cjs/close-icon-30d8bb41.js.map +1 -0
  41. package/dist/cjs/core.cjs.js +1 -1
  42. package/dist/cjs/ic-alert.cjs.entry.js +1 -1
  43. package/dist/cjs/ic-breadcrumb-group.cjs.entry.js +16 -12
  44. package/dist/cjs/ic-breadcrumb-group.cjs.entry.js.map +1 -1
  45. package/dist/cjs/ic-data-list.cjs.entry.js +1 -1
  46. package/dist/cjs/ic-data-list.cjs.entry.js.map +1 -1
  47. package/dist/cjs/ic-data-row.cjs.entry.js +1 -1
  48. package/dist/cjs/ic-data-row.cjs.entry.js.map +1 -1
  49. package/dist/cjs/ic-dialog.cjs.entry.js +1 -1
  50. package/dist/cjs/ic-input-component-container_3.cjs.entry.js +1153 -306
  51. package/dist/cjs/ic-input-component-container_3.cjs.entry.js.map +1 -1
  52. package/dist/cjs/ic-menu-item.cjs.entry.js +5 -1
  53. package/dist/cjs/ic-menu-item.cjs.entry.js.map +1 -1
  54. package/dist/cjs/ic-pagination-item.cjs.entry.js +1 -1
  55. package/dist/cjs/ic-pagination-item.cjs.entry.js.map +1 -1
  56. package/dist/cjs/ic-pagination_3.cjs.entry.js +12 -8
  57. package/dist/cjs/ic-pagination_3.cjs.entry.js.map +1 -1
  58. package/dist/cjs/ic-popover-menu.cjs.entry.js +44 -11
  59. package/dist/cjs/ic-popover-menu.cjs.entry.js.map +1 -1
  60. package/dist/cjs/ic-search-bar.cjs.entry.js +2 -6
  61. package/dist/cjs/ic-search-bar.cjs.entry.js.map +1 -1
  62. package/dist/cjs/ic-section-container.cjs.entry.js +2 -2
  63. package/dist/cjs/ic-side-navigation.cjs.entry.js +1 -1
  64. package/dist/cjs/ic-skeleton.cjs.entry.js +2 -2
  65. package/dist/cjs/ic-skip-link.cjs.entry.js +2 -2
  66. package/dist/cjs/ic-status-tag.cjs.entry.js +2 -2
  67. package/dist/cjs/ic-step.cjs.entry.js +13 -13
  68. package/dist/cjs/ic-stepper.cjs.entry.js +2 -2
  69. package/dist/cjs/ic-switch.cjs.entry.js +4 -4
  70. package/dist/cjs/ic-tab-context.cjs.entry.js +1 -1
  71. package/dist/cjs/ic-tab-group.cjs.entry.js +2 -2
  72. package/dist/cjs/ic-tab-panel.cjs.entry.js +2 -2
  73. package/dist/cjs/ic-theme.cjs.entry.js +1 -1
  74. package/dist/cjs/ic-toast-region.cjs.entry.js +1 -1
  75. package/dist/cjs/ic-toast.cjs.entry.js +6 -6
  76. package/dist/cjs/ic-toggle-button-group.cjs.entry.js +2 -2
  77. package/dist/cjs/ic-toggle-button.cjs.entry.js +2 -2
  78. package/dist/cjs/loader.cjs.js +1 -1
  79. package/dist/collection/assets/close-icon.svg +1 -2
  80. package/dist/collection/components/ic-breadcrumb-group/ic-breadcrumb-group.js +17 -13
  81. package/dist/collection/components/ic-breadcrumb-group/ic-breadcrumb-group.js.map +1 -1
  82. package/dist/collection/components/ic-data-list/ic-data-list.css +4 -0
  83. package/dist/collection/components/ic-data-row/ic-data-row.css +1 -1
  84. package/dist/collection/components/ic-menu-item/ic-menu-item.css +9 -14
  85. package/dist/collection/components/ic-menu-item/ic-menu-item.js +24 -0
  86. package/dist/collection/components/ic-menu-item/ic-menu-item.js.map +1 -1
  87. package/dist/collection/components/ic-pagination/ic-pagination.js +12 -8
  88. package/dist/collection/components/ic-pagination/ic-pagination.js.map +1 -1
  89. package/dist/collection/components/ic-pagination-item/ic-pagination-item.css +2 -1
  90. package/dist/collection/components/ic-popover-menu/ic-popover-menu.css +4 -4
  91. package/dist/collection/components/ic-popover-menu/ic-popover-menu.js +67 -11
  92. package/dist/collection/components/ic-popover-menu/ic-popover-menu.js.map +1 -1
  93. package/dist/collection/components/ic-popover-menu/ic-popover-menu.stories.js +241 -1
  94. package/dist/collection/components/ic-search-bar/ic-search-bar.js +1 -1
  95. package/dist/collection/components/ic-search-bar/ic-search-bar.js.map +1 -1
  96. package/dist/collection/components/ic-section-container/ic-section-container.js +2 -2
  97. package/dist/collection/components/ic-skeleton/ic-skeleton.js +2 -2
  98. package/dist/collection/components/ic-skip-link/ic-skip-link.js +2 -2
  99. package/dist/collection/components/ic-status-tag/ic-status-tag.js +2 -2
  100. package/dist/collection/components/ic-step/ic-step.js +13 -13
  101. package/dist/collection/components/ic-stepper/ic-stepper.js +2 -2
  102. package/dist/collection/components/ic-switch/ic-switch.js +4 -4
  103. package/dist/collection/components/ic-tab-context/ic-tab-context.js +1 -1
  104. package/dist/collection/components/ic-tab-group/ic-tab-group.js +2 -2
  105. package/dist/collection/components/ic-tab-panel/ic-tab-panel.js +2 -2
  106. package/dist/collection/components/ic-theme/ic-theme.js +1 -1
  107. package/dist/collection/components/ic-toast/ic-toast.js +5 -5
  108. package/dist/collection/components/ic-toast-region/ic-toast-region.js +1 -1
  109. package/dist/collection/components/ic-toggle-button/ic-toggle-button.js +2 -2
  110. package/dist/collection/components/ic-toggle-button-group/ic-toggle-button-group.js +2 -2
  111. package/dist/components/close-icon.js +1 -2
  112. package/dist/components/close-icon.js.map +1 -1
  113. package/dist/components/ic-breadcrumb-group.js +16 -12
  114. package/dist/components/ic-breadcrumb-group.js.map +1 -1
  115. package/dist/components/ic-data-list.js +1 -1
  116. package/dist/components/ic-data-list.js.map +1 -1
  117. package/dist/components/ic-data-row.js +1 -1
  118. package/dist/components/ic-data-row.js.map +1 -1
  119. package/dist/components/ic-hero.js.map +1 -1
  120. package/dist/components/ic-menu-item2.js +7 -2
  121. package/dist/components/ic-menu-item2.js.map +1 -1
  122. package/dist/components/ic-menu2.js +1153 -306
  123. package/dist/components/ic-menu2.js.map +1 -1
  124. package/dist/components/ic-pagination-bar.js.map +1 -1
  125. package/dist/components/ic-pagination-item2.js +1 -1
  126. package/dist/components/ic-pagination-item2.js.map +1 -1
  127. package/dist/components/ic-pagination2.js +12 -8
  128. package/dist/components/ic-pagination2.js.map +1 -1
  129. package/dist/components/ic-popover-menu.js +46 -12
  130. package/dist/components/ic-popover-menu.js.map +1 -1
  131. package/dist/components/ic-radio-group.js.map +1 -1
  132. package/dist/components/ic-search-bar.js +2 -6
  133. package/dist/components/ic-search-bar.js.map +1 -1
  134. package/dist/components/ic-section-container2.js +2 -2
  135. package/dist/components/ic-skeleton.js +2 -2
  136. package/dist/components/ic-skeleton.js.map +1 -1
  137. package/dist/components/ic-skip-link.js +2 -2
  138. package/dist/components/ic-status-tag.js +2 -2
  139. package/dist/components/ic-step.js +13 -13
  140. package/dist/components/ic-stepper.js +2 -2
  141. package/dist/components/ic-switch.js +4 -4
  142. package/dist/components/ic-switch.js.map +1 -1
  143. package/dist/components/ic-tab-context.js +1 -1
  144. package/dist/components/ic-tab-group.js +2 -2
  145. package/dist/components/ic-tab-panel.js +2 -2
  146. package/dist/components/ic-theme.js +1 -1
  147. package/dist/components/ic-toast-region.js +1 -1
  148. package/dist/components/ic-toast.js +5 -5
  149. package/dist/components/ic-toggle-button-group.js +2 -2
  150. package/dist/components/ic-toggle-button.js +2 -2
  151. package/dist/core/core.esm.js +1 -1
  152. package/dist/core/core.esm.js.map +1 -1
  153. package/dist/core/{p-23fb87be.entry.js → p-0558baed.entry.js} +2 -2
  154. package/dist/core/{p-a0c54a50.entry.js → p-0740be66.entry.js} +2 -2
  155. package/dist/core/{p-d0dd9f2c.entry.js → p-0cd21e04.entry.js} +2 -2
  156. package/dist/core/p-0cd21e04.entry.js.map +1 -0
  157. package/dist/core/{p-bb52e752.entry.js → p-1043f3dd.entry.js} +2 -2
  158. package/dist/core/{p-74a3a450.entry.js → p-1843357b.entry.js} +2 -2
  159. package/dist/core/{p-b58fb588.entry.js → p-2251df98.entry.js} +2 -2
  160. package/dist/core/{p-cf87b6db.entry.js → p-2bb815ef.entry.js} +2 -2
  161. package/dist/core/p-305d9639.entry.js +3 -0
  162. package/dist/core/p-305d9639.entry.js.map +1 -0
  163. package/dist/core/p-308be45e.entry.js +2 -0
  164. package/dist/core/p-308be45e.entry.js.map +1 -0
  165. package/dist/core/p-4b61e92e.entry.js +2 -0
  166. package/dist/core/{p-99b20121.entry.js.map → p-4b61e92e.entry.js.map} +1 -1
  167. package/dist/core/{p-fd9ea62a.entry.js → p-75f91c8c.entry.js} +2 -2
  168. package/dist/core/p-77f011e7.entry.js +2 -0
  169. package/dist/core/p-77f011e7.entry.js.map +1 -0
  170. package/dist/core/{p-70ca7796.entry.js → p-85db7e71.entry.js} +2 -2
  171. package/dist/core/{p-ab104baa.entry.js → p-987b08f9.entry.js} +2 -2
  172. package/dist/core/{p-85ac0d78.entry.js → p-9b144bed.entry.js} +2 -2
  173. package/dist/core/{p-d1220d2a.entry.js → p-a8d98164.entry.js} +2 -2
  174. package/dist/core/{p-a7c263bd.entry.js → p-ba8799ea.entry.js} +2 -2
  175. package/dist/core/p-ba8799ea.entry.js.map +1 -0
  176. package/dist/core/p-be8bbed8.entry.js +2 -0
  177. package/dist/core/p-be8bbed8.entry.js.map +1 -0
  178. package/dist/core/{p-85232cec.entry.js → p-bf06d022.entry.js} +2 -2
  179. package/dist/core/{p-c41fd2cf.entry.js → p-c0f6f568.entry.js} +2 -2
  180. package/dist/core/p-c391e323.js +2 -0
  181. package/dist/core/{p-271ee0bc.entry.js → p-c75c316b.entry.js} +2 -2
  182. package/dist/core/{p-970e190c.entry.js → p-e0b52a71.entry.js} +2 -2
  183. package/dist/core/p-ef289935.entry.js +2 -0
  184. package/dist/core/p-ef289935.entry.js.map +1 -0
  185. package/dist/core/{p-3da9774b.entry.js → p-ef91cf17.entry.js} +2 -2
  186. package/dist/core/p-f8aa89ff.entry.js +2 -0
  187. package/dist/core/p-f8aa89ff.entry.js.map +1 -0
  188. package/dist/core/{p-d7c6fc8d.entry.js → p-f8e5d8f8.entry.js} +2 -2
  189. package/dist/core/{p-6b5edd6b.entry.js → p-f9daecc7.entry.js} +2 -2
  190. package/dist/esm/{close-icon-539ec8d1.js → close-icon-0db44bf2.js} +2 -3
  191. package/dist/esm/close-icon-0db44bf2.js.map +1 -0
  192. package/dist/esm/core.js +1 -1
  193. package/dist/esm/ic-alert.entry.js +1 -1
  194. package/dist/esm/ic-breadcrumb-group.entry.js +16 -12
  195. package/dist/esm/ic-breadcrumb-group.entry.js.map +1 -1
  196. package/dist/esm/ic-data-list.entry.js +1 -1
  197. package/dist/esm/ic-data-list.entry.js.map +1 -1
  198. package/dist/esm/ic-data-row.entry.js +1 -1
  199. package/dist/esm/ic-data-row.entry.js.map +1 -1
  200. package/dist/esm/ic-dialog.entry.js +1 -1
  201. package/dist/esm/ic-input-component-container_3.entry.js +1153 -306
  202. package/dist/esm/ic-input-component-container_3.entry.js.map +1 -1
  203. package/dist/esm/ic-menu-item.entry.js +5 -1
  204. package/dist/esm/ic-menu-item.entry.js.map +1 -1
  205. package/dist/esm/ic-pagination-item.entry.js +1 -1
  206. package/dist/esm/ic-pagination-item.entry.js.map +1 -1
  207. package/dist/esm/ic-pagination_3.entry.js +12 -8
  208. package/dist/esm/ic-pagination_3.entry.js.map +1 -1
  209. package/dist/esm/ic-popover-menu.entry.js +45 -12
  210. package/dist/esm/ic-popover-menu.entry.js.map +1 -1
  211. package/dist/esm/ic-search-bar.entry.js +2 -6
  212. package/dist/esm/ic-search-bar.entry.js.map +1 -1
  213. package/dist/esm/ic-section-container.entry.js +2 -2
  214. package/dist/esm/ic-side-navigation.entry.js +1 -1
  215. package/dist/esm/ic-skeleton.entry.js +2 -2
  216. package/dist/esm/ic-skip-link.entry.js +2 -2
  217. package/dist/esm/ic-status-tag.entry.js +2 -2
  218. package/dist/esm/ic-step.entry.js +13 -13
  219. package/dist/esm/ic-stepper.entry.js +2 -2
  220. package/dist/esm/ic-switch.entry.js +4 -4
  221. package/dist/esm/ic-tab-context.entry.js +1 -1
  222. package/dist/esm/ic-tab-group.entry.js +2 -2
  223. package/dist/esm/ic-tab-panel.entry.js +2 -2
  224. package/dist/esm/ic-theme.entry.js +1 -1
  225. package/dist/esm/ic-toast-region.entry.js +1 -1
  226. package/dist/esm/ic-toast.entry.js +6 -6
  227. package/dist/esm/ic-toggle-button-group.entry.js +2 -2
  228. package/dist/esm/ic-toggle-button.entry.js +2 -2
  229. package/dist/esm/loader.js +1 -1
  230. package/dist/types/components/ic-breadcrumb-group/ic-breadcrumb-group.d.ts +6 -1
  231. package/dist/types/components/ic-menu-item/ic-menu-item.d.ts +4 -0
  232. package/dist/types/components/ic-popover-menu/ic-popover-menu.d.ts +8 -0
  233. package/dist/types/components.d.ts +18 -2
  234. package/hydrate/index.js +1284 -393
  235. package/hydrate/index.mjs +1284 -393
  236. package/package.json +12 -9
  237. package/vscode-data.json +20 -1
  238. package/dist/cjs/close-icon-7f6ef8e4.js.map +0 -1
  239. package/dist/collection/assets/clear-icon.svg +0 -3
  240. package/dist/core/p-023cf5d9.entry.js +0 -2
  241. package/dist/core/p-023cf5d9.entry.js.map +0 -1
  242. package/dist/core/p-2424f82f.entry.js +0 -2
  243. package/dist/core/p-2424f82f.entry.js.map +0 -1
  244. package/dist/core/p-2b1ce5b7.entry.js +0 -2
  245. package/dist/core/p-2b1ce5b7.entry.js.map +0 -1
  246. package/dist/core/p-99b20121.entry.js +0 -2
  247. package/dist/core/p-a7c263bd.entry.js.map +0 -1
  248. package/dist/core/p-d0dd9f2c.entry.js.map +0 -1
  249. package/dist/core/p-d5fcd4f9.entry.js +0 -2
  250. package/dist/core/p-d5fcd4f9.entry.js.map +0 -1
  251. package/dist/core/p-e0b66371.entry.js +0 -2
  252. package/dist/core/p-e0b66371.entry.js.map +0 -1
  253. package/dist/core/p-f074ef5b.js +0 -2
  254. package/dist/core/p-fdc4376e.entry.js +0 -3
  255. package/dist/core/p-fdc4376e.entry.js.map +0 -1
  256. package/dist/esm/close-icon-539ec8d1.js.map +0 -1
  257. /package/dist/core/{p-23fb87be.entry.js.map → p-0558baed.entry.js.map} +0 -0
  258. /package/dist/core/{p-a0c54a50.entry.js.map → p-0740be66.entry.js.map} +0 -0
  259. /package/dist/core/{p-bb52e752.entry.js.map → p-1043f3dd.entry.js.map} +0 -0
  260. /package/dist/core/{p-74a3a450.entry.js.map → p-1843357b.entry.js.map} +0 -0
  261. /package/dist/core/{p-b58fb588.entry.js.map → p-2251df98.entry.js.map} +0 -0
  262. /package/dist/core/{p-cf87b6db.entry.js.map → p-2bb815ef.entry.js.map} +0 -0
  263. /package/dist/core/{p-fd9ea62a.entry.js.map → p-75f91c8c.entry.js.map} +0 -0
  264. /package/dist/core/{p-70ca7796.entry.js.map → p-85db7e71.entry.js.map} +0 -0
  265. /package/dist/core/{p-ab104baa.entry.js.map → p-987b08f9.entry.js.map} +0 -0
  266. /package/dist/core/{p-85ac0d78.entry.js.map → p-9b144bed.entry.js.map} +0 -0
  267. /package/dist/core/{p-d1220d2a.entry.js.map → p-a8d98164.entry.js.map} +0 -0
  268. /package/dist/core/{p-85232cec.entry.js.map → p-bf06d022.entry.js.map} +0 -0
  269. /package/dist/core/{p-c41fd2cf.entry.js.map → p-c0f6f568.entry.js.map} +0 -0
  270. /package/dist/core/{p-f074ef5b.js.map → p-c391e323.js.map} +0 -0
  271. /package/dist/core/{p-271ee0bc.entry.js.map → p-c75c316b.entry.js.map} +0 -0
  272. /package/dist/core/{p-970e190c.entry.js.map → p-e0b52a71.entry.js.map} +0 -0
  273. /package/dist/core/{p-3da9774b.entry.js.map → p-ef91cf17.entry.js.map} +0 -0
  274. /package/dist/core/{p-d7c6fc8d.entry.js.map → p-f8e5d8f8.entry.js.map} +0 -0
  275. /package/dist/core/{p-6b5edd6b.entry.js.map → p-f9daecc7.entry.js.map} +0 -0
@@ -97,28 +97,69 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof win
97
97
 
98
98
  var purify = {exports: {}};
99
99
 
100
- /*! @license DOMPurify 3.4.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.0/LICENSE */
100
+ /*! @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 */
101
101
 
102
102
  (function (module, exports) {
103
103
  (function (global, factory) {
104
104
  module.exports = factory() ;
105
105
  })(commonjsGlobal, (function () {
106
- const {
107
- entries,
108
- setPrototypeOf,
109
- isFrozen,
110
- getPrototypeOf,
111
- getOwnPropertyDescriptor
112
- } = Object;
113
- let {
114
- freeze,
115
- seal,
116
- create
117
- } = Object; // eslint-disable-line import/no-mutable-exports
118
- let {
119
- apply,
120
- construct
121
- } = typeof Reflect !== 'undefined' && Reflect;
106
+ function _arrayLikeToArray(r, a) {
107
+ (null == a || a > r.length) && (a = r.length);
108
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
109
+ return n;
110
+ }
111
+ function _arrayWithHoles(r) {
112
+ if (Array.isArray(r)) return r;
113
+ }
114
+ function _iterableToArrayLimit(r, l) {
115
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
116
+ if (null != t) {
117
+ var e,
118
+ n,
119
+ i,
120
+ u,
121
+ a = [],
122
+ f = true,
123
+ o = false;
124
+ try {
125
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
126
+ } catch (r) {
127
+ o = true, n = r;
128
+ } finally {
129
+ try {
130
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
131
+ } finally {
132
+ if (o) throw n;
133
+ }
134
+ }
135
+ return a;
136
+ }
137
+ }
138
+ function _nonIterableRest() {
139
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
140
+ }
141
+ function _slicedToArray(r, e) {
142
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
143
+ }
144
+ function _unsupportedIterableToArray(r, a) {
145
+ if (r) {
146
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
147
+ var t = {}.toString.call(r).slice(8, -1);
148
+ 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;
149
+ }
150
+ }
151
+
152
+ const entries = Object.entries,
153
+ setPrototypeOf = Object.setPrototypeOf,
154
+ isFrozen = Object.isFrozen,
155
+ getPrototypeOf = Object.getPrototypeOf,
156
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
157
+ let freeze = Object.freeze,
158
+ seal = Object.seal,
159
+ create = Object.create; // eslint-disable-line import/no-mutable-exports
160
+ let _ref = typeof Reflect !== 'undefined' && Reflect,
161
+ apply = _ref.apply,
162
+ construct = _ref.construct;
122
163
  if (!freeze) {
123
164
  freeze = function freeze(x) {
124
165
  return x;
@@ -150,13 +191,19 @@ var purify = {exports: {}};
150
191
  const arrayPop = unapply(Array.prototype.pop);
151
192
  const arrayPush = unapply(Array.prototype.push);
152
193
  const arraySplice = unapply(Array.prototype.splice);
194
+ const arrayIsArray = Array.isArray;
153
195
  const stringToLowerCase = unapply(String.prototype.toLowerCase);
154
196
  const stringToString = unapply(String.prototype.toString);
155
197
  const stringMatch = unapply(String.prototype.match);
156
198
  const stringReplace = unapply(String.prototype.replace);
157
199
  const stringIndexOf = unapply(String.prototype.indexOf);
158
200
  const stringTrim = unapply(String.prototype.trim);
201
+ const numberToString = unapply(Number.prototype.toString);
202
+ const booleanToString = unapply(Boolean.prototype.toString);
203
+ const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
204
+ const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
159
205
  const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
206
+ const objectToString = unapply(Object.prototype.toString);
160
207
  const regExpTest = unapply(RegExp.prototype.test);
161
208
  const typeErrorCreate = unconstruct(TypeError);
162
209
  /**
@@ -206,6 +253,9 @@ var purify = {exports: {}};
206
253
  // Prevent prototype setters from intercepting set as a this value.
207
254
  setPrototypeOf(set, null);
208
255
  }
256
+ if (!arrayIsArray(array)) {
257
+ return set;
258
+ }
209
259
  let l = array.length;
210
260
  while (l--) {
211
261
  let element = array[l];
@@ -246,10 +296,13 @@ var purify = {exports: {}};
246
296
  */
247
297
  function clone(object) {
248
298
  const newObject = create(null);
249
- for (const [property, value] of entries(object)) {
299
+ for (const _ref2 of entries(object)) {
300
+ var _ref3 = _slicedToArray(_ref2, 2);
301
+ const property = _ref3[0];
302
+ const value = _ref3[1];
250
303
  const isPropertyExist = objectHasOwnProperty(object, property);
251
304
  if (isPropertyExist) {
252
- if (Array.isArray(value)) {
305
+ if (arrayIsArray(value)) {
253
306
  newObject[property] = cleanArray(value);
254
307
  } else if (value && typeof value === 'object' && value.constructor === Object) {
255
308
  newObject[property] = clone(value);
@@ -260,6 +313,58 @@ var purify = {exports: {}};
260
313
  }
261
314
  return newObject;
262
315
  }
316
+ /**
317
+ * Convert non-node values into strings without depending on direct property access.
318
+ *
319
+ * @param value - The value to stringify.
320
+ * @returns A string representation of the provided value.
321
+ */
322
+ function stringifyValue(value) {
323
+ switch (typeof value) {
324
+ case 'string':
325
+ {
326
+ return value;
327
+ }
328
+ case 'number':
329
+ {
330
+ return numberToString(value);
331
+ }
332
+ case 'boolean':
333
+ {
334
+ return booleanToString(value);
335
+ }
336
+ case 'bigint':
337
+ {
338
+ return bigintToString ? bigintToString(value) : '0';
339
+ }
340
+ case 'symbol':
341
+ {
342
+ return symbolToString ? symbolToString(value) : 'Symbol()';
343
+ }
344
+ case 'undefined':
345
+ {
346
+ return objectToString(value);
347
+ }
348
+ case 'function':
349
+ case 'object':
350
+ {
351
+ if (value === null) {
352
+ return objectToString(value);
353
+ }
354
+ const valueAsRecord = value;
355
+ const valueToString = lookupGetter(valueAsRecord, 'toString');
356
+ if (typeof valueToString === 'function') {
357
+ const stringified = valueToString(valueAsRecord);
358
+ return typeof stringified === 'string' ? stringified : objectToString(stringified);
359
+ }
360
+ return objectToString(value);
361
+ }
362
+ default:
363
+ {
364
+ return objectToString(value);
365
+ }
366
+ }
367
+ }
263
368
  /**
264
369
  * This method automatically checks if the prop is function or getter and behaves accordingly.
265
370
  *
@@ -285,6 +390,14 @@ var purify = {exports: {}};
285
390
  }
286
391
  return fallbackValue;
287
392
  }
393
+ function isRegex(value) {
394
+ try {
395
+ regExpTest(value, '');
396
+ return true;
397
+ } catch (_unused) {
398
+ return false;
399
+ }
400
+ }
288
401
 
289
402
  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']);
290
403
  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']);
@@ -300,15 +413,14 @@ var purify = {exports: {}};
300
413
  const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
301
414
  const text = freeze(['#text']);
302
415
 
303
- const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
416
+ 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']);
304
417
  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']);
305
418
  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']);
306
419
  const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
307
420
 
308
- // eslint-disable-next-line unicorn/better-regex
309
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
310
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
311
- const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
421
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
422
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
423
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
312
424
  const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
313
425
  const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
314
426
  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
@@ -318,30 +430,31 @@ var purify = {exports: {}};
318
430
  );
319
431
  const DOCTYPE_NAME = seal(/^html$/i);
320
432
  const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
433
+ // Markup-significant character probes used by _sanitizeElements.
434
+ // Shared module-level instances are safe despite the sticky /g flags:
435
+ // unapply() resets lastIndex for RegExp receivers before every call.
436
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
437
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
438
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
439
+ const SELF_CLOSING_TAG = seal(/\/>/i);
321
440
 
322
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
323
- __proto__: null,
324
- ARIA_ATTR: ARIA_ATTR,
325
- ATTR_WHITESPACE: ATTR_WHITESPACE,
326
- CUSTOM_ELEMENT: CUSTOM_ELEMENT,
327
- DATA_ATTR: DATA_ATTR,
328
- DOCTYPE_NAME: DOCTYPE_NAME,
329
- ERB_EXPR: ERB_EXPR,
330
- IS_ALLOWED_URI: IS_ALLOWED_URI,
331
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
332
- MUSTACHE_EXPR: MUSTACHE_EXPR,
333
- TMPLIT_EXPR: TMPLIT_EXPR
334
- });
335
-
336
- /* eslint-disable @typescript-eslint/indent */
337
441
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
338
442
  const NODE_TYPE = {
339
443
  element: 1,
444
+ attribute: 2,
340
445
  text: 3,
446
+ cdataSection: 4,
447
+ entityReference: 5,
341
448
  // Deprecated
342
- progressingInstruction: 7,
449
+ entityNode: 6,
450
+ // Deprecated
451
+ processingInstruction: 7,
343
452
  comment: 8,
344
- document: 9};
453
+ document: 9,
454
+ documentType: 10,
455
+ documentFragment: 11,
456
+ notation: 12 // Deprecated
457
+ };
345
458
  const getGlobal = function getGlobal() {
346
459
  return typeof window === 'undefined' ? null : window;
347
460
  };
@@ -396,10 +509,25 @@ var purify = {exports: {}};
396
509
  uponSanitizeShadowNode: []
397
510
  };
398
511
  };
512
+ /**
513
+ * Resolve a set-valued configuration option: a fresh set built from
514
+ * cfg[key] when it is an own array property (seeded with a clone of
515
+ * options.base when given, case-normalized via options.transform),
516
+ * the fallback set otherwise.
517
+ *
518
+ * @param cfg the cloned, prototype-free configuration object
519
+ * @param key the configuration property to read
520
+ * @param fallback the set to use when the option is absent or not an array
521
+ * @param options transform and optional base set to merge into
522
+ * @returns the resolved set
523
+ */
524
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
525
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
526
+ };
399
527
  function createDOMPurify() {
400
528
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
401
529
  const DOMPurify = root => createDOMPurify(root);
402
- DOMPurify.version = '3.4.0';
530
+ DOMPurify.version = '3.4.11';
403
531
  DOMPurify.removed = [];
404
532
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
405
533
  // Not running in a browser, provide a factory function
@@ -407,28 +535,25 @@ var purify = {exports: {}};
407
535
  DOMPurify.isSupported = false;
408
536
  return DOMPurify;
409
537
  }
410
- let {
411
- document
412
- } = window;
538
+ let document = window.document;
413
539
  const originalDocument = document;
414
540
  const currentScript = originalDocument.currentScript;
415
- const {
416
- DocumentFragment,
417
- HTMLTemplateElement,
418
- Node,
419
- Element,
420
- NodeFilter,
421
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
422
- HTMLFormElement,
423
- DOMParser,
424
- trustedTypes
425
- } = window;
541
+ const HTMLTemplateElement = window.HTMLTemplateElement,
542
+ Node = window.Node,
543
+ Element = window.Element,
544
+ NodeFilter = window.NodeFilter;
545
+ const DOMParser = window.DOMParser,
546
+ trustedTypes = window.trustedTypes;
426
547
  const ElementPrototype = Element.prototype;
427
548
  const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
428
549
  const remove = lookupGetter(ElementPrototype, 'remove');
429
550
  const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
430
551
  const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
431
552
  const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
553
+ const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
554
+ const getAttributes = lookupGetter(ElementPrototype, 'attributes');
555
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
556
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
432
557
  // As per issue #47, the web-components registry is inherited by a
433
558
  // new document created via createHTMLDocument. As per the spec
434
559
  // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
@@ -443,33 +568,74 @@ var purify = {exports: {}};
443
568
  }
444
569
  let trustedTypesPolicy;
445
570
  let emptyHTML = '';
446
- const {
447
- implementation,
448
- createNodeIterator,
449
- createDocumentFragment,
450
- getElementsByTagName
451
- } = document;
452
- const {
453
- importNode
454
- } = originalDocument;
571
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
572
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
573
+ // on duplicate policy names — and is the only policy allowed to persist
574
+ // across configurations and survive `clearConfig()`.
575
+ let defaultTrustedTypesPolicy;
576
+ let defaultTrustedTypesPolicyResolved = false;
577
+ // Tracks whether we are already inside a call to the configured Trusted Types
578
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
579
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
580
+ // re-enter the policy and recurse until the stack overflows. We detect that
581
+ // re-entry and throw a clear, actionable error instead. The guard is shared
582
+ // across both callbacks, because either one re-entering `sanitize` triggers
583
+ // the same unbounded recursion.
584
+ let IN_TRUSTED_TYPES_POLICY = 0;
585
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
586
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
587
+ 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.');
588
+ }
589
+ };
590
+ const _createTrustedHTML = function _createTrustedHTML(html) {
591
+ _assertNotInTrustedTypesPolicy();
592
+ IN_TRUSTED_TYPES_POLICY++;
593
+ try {
594
+ return trustedTypesPolicy.createHTML(html);
595
+ } finally {
596
+ IN_TRUSTED_TYPES_POLICY--;
597
+ }
598
+ };
599
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
600
+ _assertNotInTrustedTypesPolicy();
601
+ IN_TRUSTED_TYPES_POLICY++;
602
+ try {
603
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
604
+ } finally {
605
+ IN_TRUSTED_TYPES_POLICY--;
606
+ }
607
+ };
608
+ // Lazily resolve (and cache) the instance's internal default policy.
609
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
610
+ // repeated (Trusted Types throws on duplicate names), and a failed or
611
+ // unsupported attempt must not be retried on every parse.
612
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
613
+ if (!defaultTrustedTypesPolicyResolved) {
614
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
615
+ defaultTrustedTypesPolicyResolved = true;
616
+ }
617
+ return defaultTrustedTypesPolicy;
618
+ };
619
+ const _document = document,
620
+ implementation = _document.implementation,
621
+ createNodeIterator = _document.createNodeIterator,
622
+ createDocumentFragment = _document.createDocumentFragment,
623
+ getElementsByTagName = _document.getElementsByTagName;
624
+ const importNode = originalDocument.importNode;
455
625
  let hooks = _createHooksMap();
456
626
  /**
457
627
  * Expose whether this browser supports running the full DOMPurify.
458
628
  */
459
629
  DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
460
- const {
461
- MUSTACHE_EXPR,
462
- ERB_EXPR,
463
- TMPLIT_EXPR,
464
- DATA_ATTR,
465
- ARIA_ATTR,
466
- IS_SCRIPT_OR_DATA,
467
- ATTR_WHITESPACE,
468
- CUSTOM_ELEMENT
469
- } = EXPRESSIONS;
470
- let {
471
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
472
- } = EXPRESSIONS;
630
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
631
+ ERB_EXPR$1 = ERB_EXPR,
632
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
633
+ DATA_ATTR$1 = DATA_ATTR,
634
+ ARIA_ATTR$1 = ARIA_ATTR,
635
+ IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
636
+ ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
637
+ CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
638
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
473
639
  /**
474
640
  * We consider the elements and attributes below to be safe. Ideally
475
641
  * don't add any new ones but feel free to remove unwanted ones.
@@ -546,6 +712,13 @@ var purify = {exports: {}};
546
712
  let WHOLE_DOCUMENT = false;
547
713
  /* Track whether config is already set on this instance of DOMPurify. */
548
714
  let SET_CONFIG = false;
715
+ /* Pristine allowlist bindings captured at setConfig() time. On the
716
+ * persistent-config path sanitize() restores the sets from these before
717
+ * the per-walk hook clone-guard, so a hook's in-call widening cannot
718
+ * carry across calls. Null until setConfig() is called; reset by
719
+ * clearConfig(). */
720
+ let SET_CONFIG_ALLOWED_TAGS = null;
721
+ let SET_CONFIG_ALLOWED_ATTR = null;
549
722
  /* Decide if all elements (e.g. style, script) must be children of
550
723
  * document.body. By default, browsers might move them to document.head */
551
724
  let FORCE_BODY = false;
@@ -588,7 +761,17 @@ var purify = {exports: {}};
588
761
  let USE_PROFILES = {};
589
762
  /* Tags to ignore content of when KEEP_CONTENT is true */
590
763
  let FORBID_CONTENTS = null;
591
- const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
764
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
765
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
766
+ // the UA (customizable <select>) — including any on* handlers — and the
767
+ // engine re-mirrors synchronously whenever a removal changes which
768
+ // option/selectedcontent is current, even inside DOMPurify's inert
769
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
770
+ // mirror target ahead of the walk, which the engine refills, looping
771
+ // forever (DoS) and amplifying output. Dropping its content on removal
772
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
773
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
774
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
592
775
  /* Tags that are safe for data: URIs */
593
776
  let DATA_URI_TAGS = null;
594
777
  const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
@@ -604,8 +787,10 @@ var purify = {exports: {}};
604
787
  /* Allowed XHTML+XML namespaces */
605
788
  let ALLOWED_NAMESPACES = null;
606
789
  const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
607
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
608
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
790
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
791
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
792
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
793
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
609
794
  // Certain elements are allowed in both SVG and HTML
610
795
  // namespace. We need to specify them explicitly
611
796
  // so that they don't get erroneously deleted from
@@ -647,15 +832,33 @@ var purify = {exports: {}};
647
832
  // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
648
833
  transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
649
834
  /* Set configuration parameters */
650
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
651
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
652
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
653
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
654
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
655
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
656
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
657
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
658
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
835
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
836
+ transform: transformCaseFunc
837
+ });
838
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
839
+ transform: transformCaseFunc
840
+ });
841
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
842
+ transform: stringToString
843
+ });
844
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
845
+ transform: transformCaseFunc,
846
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
847
+ });
848
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
849
+ transform: transformCaseFunc,
850
+ base: DEFAULT_DATA_URI_TAGS
851
+ });
852
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
853
+ transform: transformCaseFunc
854
+ });
855
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
856
+ transform: transformCaseFunc
857
+ });
858
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
859
+ transform: transformCaseFunc
860
+ });
861
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
659
862
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
660
863
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
661
864
  ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
@@ -671,20 +874,22 @@ var purify = {exports: {}};
671
874
  SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
672
875
  KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
673
876
  IN_PLACE = cfg.IN_PLACE || false; // Default false
674
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
675
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
676
- MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
677
- HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
678
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || create(null);
679
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
680
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
681
- }
682
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
683
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
684
- }
685
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
686
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
687
- }
877
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
878
+ NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
879
+ 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
880
+ 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
881
+ const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
882
+ CUSTOM_ELEMENT_HANDLING = create(null);
883
+ if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
884
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
885
+ }
886
+ if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
887
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
888
+ }
889
+ if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
890
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
891
+ }
892
+ seal(CUSTOM_ELEMENT_HANDLING);
688
893
  if (SAFE_FOR_TEMPLATES) {
689
894
  ALLOW_DATA_ATTR = false;
690
895
  }
@@ -720,36 +925,36 @@ var purify = {exports: {}};
720
925
  EXTRA_ELEMENT_HANDLING.tagCheck = null;
721
926
  EXTRA_ELEMENT_HANDLING.attributeCheck = null;
722
927
  /* Merge configuration parameters */
723
- if (cfg.ADD_TAGS) {
928
+ if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
724
929
  if (typeof cfg.ADD_TAGS === 'function') {
725
930
  EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
726
- } else {
931
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
727
932
  if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
728
933
  ALLOWED_TAGS = clone(ALLOWED_TAGS);
729
934
  }
730
935
  addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
731
936
  }
732
937
  }
733
- if (cfg.ADD_ATTR) {
938
+ if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
734
939
  if (typeof cfg.ADD_ATTR === 'function') {
735
940
  EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
736
- } else {
941
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
737
942
  if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
738
943
  ALLOWED_ATTR = clone(ALLOWED_ATTR);
739
944
  }
740
945
  addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
741
946
  }
742
947
  }
743
- if (cfg.ADD_URI_SAFE_ATTR) {
948
+ if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
744
949
  addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
745
950
  }
746
- if (cfg.FORBID_CONTENTS) {
951
+ if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
747
952
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
748
953
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
749
954
  }
750
955
  addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
751
956
  }
752
- if (cfg.ADD_FORBID_CONTENTS) {
957
+ if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
753
958
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
754
959
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
755
960
  }
@@ -768,6 +973,13 @@ var purify = {exports: {}};
768
973
  addToSet(ALLOWED_TAGS, ['tbody']);
769
974
  delete FORBID_TAGS.tbody;
770
975
  }
976
+ // Re-derive the active Trusted Types policy from this configuration on
977
+ // every parse. The active policy must never be sticky closure state that
978
+ // outlives the config that set it: a caller-supplied policy left in place
979
+ // after `clearConfig()` — or after a later call that supplied none, or
980
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
981
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
982
+ // See GHSA-vxr8-fq34-vvx9.
771
983
  if (cfg.TRUSTED_TYPES_POLICY) {
772
984
  if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
773
985
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
@@ -775,18 +987,45 @@ var purify = {exports: {}};
775
987
  if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
776
988
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
777
989
  }
778
- // Overwrite existing TrustedTypes policy.
990
+ // A caller-supplied policy applies to this configuration only.
991
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
779
992
  trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
780
- // Sign local variables required by `sanitize`.
781
- emptyHTML = trustedTypesPolicy.createHTML('');
993
+ // Sign local variables required by `sanitize`. If the supplied policy's
994
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
995
+ // throws via the re-entrancy guard. Restore the previous policy first so
996
+ // the instance is not left in a poisoned state. See #1422.
997
+ try {
998
+ emptyHTML = _createTrustedHTML('');
999
+ } catch (error) {
1000
+ trustedTypesPolicy = previousTrustedTypesPolicy;
1001
+ throw error;
1002
+ }
1003
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
1004
+ // Explicit opt-out for this call: perform no Trusted Types signing and
1005
+ // create nothing (so a strict `trusted-types` CSP that disallows a
1006
+ // `dompurify` policy can still call `sanitize` from inside its own
1007
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
1008
+ // `null` also drops any previously retained caller policy, so it cannot
1009
+ // resurface on a later call, while still allowing the next config-less
1010
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
1011
+ trustedTypesPolicy = undefined;
1012
+ emptyHTML = '';
782
1013
  } else {
783
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
1014
+ // No policy supplied: keep the currently active policy if one is set — a
1015
+ // previously supplied policy is intentionally sticky across config-less
1016
+ // calls — otherwise fall back to the instance's own internal policy,
1017
+ // created at most once. (A policy supplied for a *single* call still
1018
+ // lingers by design; what must not linger is a policy whose configuration
1019
+ // has been torn down via `clearConfig()`, which restores the default.)
784
1020
  if (trustedTypesPolicy === undefined) {
785
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
1021
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
786
1022
  }
787
- // If creating the internal policy succeeded sign internal variables.
788
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
789
- emptyHTML = trustedTypesPolicy.createHTML('');
1023
+ // Sign internal variables only when a policy is active. A falsy policy
1024
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
1025
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
1026
+ // a non-policy and throw. See #1422.
1027
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
1028
+ emptyHTML = _createTrustedHTML('');
790
1029
  }
791
1030
  }
792
1031
  // Prevent further manipulation of configuration.
@@ -801,6 +1040,77 @@ var purify = {exports: {}};
801
1040
  * correctly. */
802
1041
  const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
803
1042
  const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
1043
+ /**
1044
+ * Namespace rules for an element in the SVG namespace.
1045
+ *
1046
+ * @param tagName the element's lowercase tag name
1047
+ * @param parent the (possibly simulated) parent node
1048
+ * @param parentTagName the parent's lowercase tag name
1049
+ * @returns true if a spec-compliant parser could produce this element
1050
+ */
1051
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
1052
+ // The only way to switch from HTML namespace to SVG
1053
+ // is via <svg>. If it happens via any other tag, then
1054
+ // it should be killed.
1055
+ if (parent.namespaceURI === HTML_NAMESPACE) {
1056
+ return tagName === 'svg';
1057
+ }
1058
+ // The only way to switch from MathML to SVG is via <svg>
1059
+ // if the parent is either <annotation-xml> or a MathML
1060
+ // text integration point.
1061
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
1062
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1063
+ }
1064
+ // We only allow elements that are defined in SVG
1065
+ // spec. All others are disallowed in SVG namespace.
1066
+ return Boolean(ALL_SVG_TAGS[tagName]);
1067
+ };
1068
+ /**
1069
+ * Namespace rules for an element in the MathML namespace.
1070
+ *
1071
+ * @param tagName the element's lowercase tag name
1072
+ * @param parent the (possibly simulated) parent node
1073
+ * @param parentTagName the parent's lowercase tag name
1074
+ * @returns true if a spec-compliant parser could produce this element
1075
+ */
1076
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
1077
+ // The only way to switch from HTML namespace to MathML
1078
+ // is via <math>. If it happens via any other tag, then
1079
+ // it should be killed.
1080
+ if (parent.namespaceURI === HTML_NAMESPACE) {
1081
+ return tagName === 'math';
1082
+ }
1083
+ // The only way to switch from SVG to MathML is via
1084
+ // <math> and HTML integration points
1085
+ if (parent.namespaceURI === SVG_NAMESPACE) {
1086
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
1087
+ }
1088
+ // We only allow elements that are defined in MathML
1089
+ // spec. All others are disallowed in MathML namespace.
1090
+ return Boolean(ALL_MATHML_TAGS[tagName]);
1091
+ };
1092
+ /**
1093
+ * Namespace rules for an element in the HTML namespace.
1094
+ *
1095
+ * @param tagName the element's lowercase tag name
1096
+ * @param parent the (possibly simulated) parent node
1097
+ * @param parentTagName the parent's lowercase tag name
1098
+ * @returns true if a spec-compliant parser could produce this element
1099
+ */
1100
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
1101
+ // The only way to switch from SVG to HTML is via
1102
+ // HTML integration points, and from MathML to HTML
1103
+ // is via MathML text integration points
1104
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
1105
+ return false;
1106
+ }
1107
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
1108
+ return false;
1109
+ }
1110
+ // We disallow tags that are specific for MathML
1111
+ // or SVG and should never appear in HTML namespace
1112
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1113
+ };
804
1114
  /**
805
1115
  * @param element a DOM element whose namespace is being checked
806
1116
  * @returns Return false if the element has a
@@ -823,51 +1133,13 @@ var purify = {exports: {}};
823
1133
  return false;
824
1134
  }
825
1135
  if (element.namespaceURI === SVG_NAMESPACE) {
826
- // The only way to switch from HTML namespace to SVG
827
- // is via <svg>. If it happens via any other tag, then
828
- // it should be killed.
829
- if (parent.namespaceURI === HTML_NAMESPACE) {
830
- return tagName === 'svg';
831
- }
832
- // The only way to switch from MathML to SVG is via`
833
- // svg if parent is either <annotation-xml> or MathML
834
- // text integration points.
835
- if (parent.namespaceURI === MATHML_NAMESPACE) {
836
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
837
- }
838
- // We only allow elements that are defined in SVG
839
- // spec. All others are disallowed in SVG namespace.
840
- return Boolean(ALL_SVG_TAGS[tagName]);
1136
+ return _checkSvgNamespace(tagName, parent, parentTagName);
841
1137
  }
842
1138
  if (element.namespaceURI === MATHML_NAMESPACE) {
843
- // The only way to switch from HTML namespace to MathML
844
- // is via <math>. If it happens via any other tag, then
845
- // it should be killed.
846
- if (parent.namespaceURI === HTML_NAMESPACE) {
847
- return tagName === 'math';
848
- }
849
- // The only way to switch from SVG to MathML is via
850
- // <math> and HTML integration points
851
- if (parent.namespaceURI === SVG_NAMESPACE) {
852
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
853
- }
854
- // We only allow elements that are defined in MathML
855
- // spec. All others are disallowed in MathML namespace.
856
- return Boolean(ALL_MATHML_TAGS[tagName]);
1139
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
857
1140
  }
858
1141
  if (element.namespaceURI === HTML_NAMESPACE) {
859
- // The only way to switch from SVG to HTML is via
860
- // HTML integration points, and from MathML to HTML
861
- // is via MathML text integration points
862
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
863
- return false;
864
- }
865
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
866
- return false;
867
- }
868
- // We disallow tags that are specific for MathML
869
- // or SVG and should never appear in HTML namespace
870
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1142
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
871
1143
  }
872
1144
  // For XHTML and XML documents that support custom namespaces
873
1145
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
@@ -892,7 +1164,74 @@ var purify = {exports: {}};
892
1164
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
893
1165
  getParentNode(node).removeChild(node);
894
1166
  } catch (_) {
1167
+ /* The normal detach failed — this is reached for a parentless node
1168
+ (getParentNode() is null, so .removeChild throws). Element.prototype
1169
+ .remove() is itself a spec no-op on a parentless node, so a recorded
1170
+ "removal" would otherwise hand the caller back an intact,
1171
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
1172
+ the style-with-element-child rule decided to kill). Fail closed by
1173
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
1174
+ rather than trying to "neutralize" the node via its own methods.
1175
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
1176
+ on the node, both of which a <form> root can clobber via a named child
1177
+ (and _isClobbered does not even probe getAttributeNames), so the
1178
+ neutralize step could itself be silently defeated, leaving the payload
1179
+ intact. A throw touches only the cached, clobber-safe remove() and
1180
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
1181
+ to every root-kill reason. REPORT-3.
1182
+ This lives inside the catch, so it never fires for a normally-removed
1183
+ in-tree node: those have a parent, removeChild() succeeds, and the
1184
+ catch is not entered. Only a kept (parentless) root reaches here. */
895
1185
  remove(node);
1186
+ if (!getParentNode(node)) {
1187
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
1188
+ }
1189
+ }
1190
+ };
1191
+ /**
1192
+ * _neutralizeRoot
1193
+ *
1194
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
1195
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
1196
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
1197
+ * parentless guard throws, or any other re-entrant engine mutation — would
1198
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
1199
+ * after the abort point still carrying its handlers. There is no safe way
1200
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
1201
+ * remove every child and every attribute, then let the caller's catch see
1202
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
1203
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
1204
+ *
1205
+ * @param root the in-place root to empty
1206
+ */
1207
+ const _neutralizeRoot = function _neutralizeRoot(root) {
1208
+ const childNodes = getChildNodes(root);
1209
+ if (childNodes) {
1210
+ const snapshot = [];
1211
+ arrayForEach(childNodes, child => {
1212
+ arrayPush(snapshot, child);
1213
+ });
1214
+ arrayForEach(snapshot, child => {
1215
+ try {
1216
+ remove(child);
1217
+ } catch (_) {
1218
+ /* Best-effort teardown; a still-attached child is handled below */
1219
+ }
1220
+ });
1221
+ }
1222
+ const attributes = getAttributes(root);
1223
+ if (attributes) {
1224
+ for (let i = attributes.length - 1; i >= 0; --i) {
1225
+ const attribute = attributes[i];
1226
+ const name = attribute && attribute.name;
1227
+ if (typeof name === 'string') {
1228
+ try {
1229
+ root.removeAttribute(name);
1230
+ } catch (_) {
1231
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
1232
+ }
1233
+ }
1234
+ }
896
1235
  }
897
1236
  };
898
1237
  /**
@@ -927,6 +1266,72 @@ var purify = {exports: {}};
927
1266
  }
928
1267
  }
929
1268
  };
1269
+ /**
1270
+ * _stripDisallowedAttributes
1271
+ *
1272
+ * Removes every attribute the active configuration does not allow from a
1273
+ * single element, using the same allowlist as the main attribute pass (so
1274
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
1275
+ * neutralise nodes that are being discarded from an in-place tree.
1276
+ *
1277
+ * @param element the element to strip
1278
+ */
1279
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
1280
+ const attributes = getAttributes(element);
1281
+ if (!attributes) {
1282
+ return;
1283
+ }
1284
+ for (let i = attributes.length - 1; i >= 0; --i) {
1285
+ const attribute = attributes[i];
1286
+ const name = attribute && attribute.name;
1287
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
1288
+ continue;
1289
+ }
1290
+ try {
1291
+ element.removeAttribute(name);
1292
+ } catch (_) {
1293
+ /* Clobbered removeAttribute on a doomed node — ignore */
1294
+ }
1295
+ }
1296
+ };
1297
+ /**
1298
+ * _neutralizeSubtree
1299
+ *
1300
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
1301
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
1302
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
1303
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
1304
+ * those dropped nodes are detached from the caller's LIVE tree but a
1305
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
1306
+ * loading) keeps its queued resource event, which fires in page scope after
1307
+ * sanitize returns. This walks a removed subtree and strips every attribute
1308
+ * the active configuration does not allow — so `on*` handlers are cancelled
1309
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
1310
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
1311
+ * queued event can fire. Hook-free by design: these nodes leave the output,
1312
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
1313
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
1314
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
1315
+ * the `<img>`, are reached and scrubbed).
1316
+ *
1317
+ * @param root the root of a removed subtree to neutralise
1318
+ */
1319
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
1320
+ const stack = [root];
1321
+ while (stack.length > 0) {
1322
+ const node = stack.pop();
1323
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1324
+ if (nodeType === NODE_TYPE.element) {
1325
+ _stripDisallowedAttributes(node);
1326
+ }
1327
+ const childNodes = getChildNodes(node);
1328
+ if (childNodes) {
1329
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1330
+ stack.push(childNodes[i]);
1331
+ }
1332
+ }
1333
+ }
1334
+ };
930
1335
  /**
931
1336
  * _initDocument
932
1337
  *
@@ -948,7 +1353,7 @@ var purify = {exports: {}};
948
1353
  // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
949
1354
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
950
1355
  }
951
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
1356
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
952
1357
  /*
953
1358
  * Use the DOMParser API by default, fallback later if needs be
954
1359
  * DOMParser not work for svg when has multiple root element.
@@ -988,29 +1393,254 @@ var purify = {exports: {}};
988
1393
  // eslint-disable-next-line no-bitwise
989
1394
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
990
1395
  };
1396
+ /**
1397
+ * Replace template expression syntax (mustache, ERB, template
1398
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
1399
+ * sites. Order matters: mustache, then ERB, then template literal.
1400
+ *
1401
+ * @param value the string to scrub
1402
+ * @returns the scrubbed string
1403
+ */
1404
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
1405
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
1406
+ value = stringReplace(value, ERB_EXPR$1, ' ');
1407
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
1408
+ return value;
1409
+ };
1410
+ /**
1411
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
1412
+ * character data of an element subtree. Used as the final safety net for
1413
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
1414
+ * which only form after text-node normalization (e.g. fragments split across
1415
+ * stripped elements) cannot survive into a template-evaluating framework.
1416
+ *
1417
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
1418
+ * in place rather than round-tripping through innerHTML. This preserves
1419
+ * descendant node references (important for IN_PLACE callers), avoids a
1420
+ * serialize/reparse cycle, and reads literal character data — which means
1421
+ * `<%...%>` in text content matches the ERB regex against its real bytes
1422
+ * instead of the HTML-entity-escaped form innerHTML would produce.
1423
+ *
1424
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
1425
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
1426
+ *
1427
+ * @param node The root element whose character data should be scrubbed.
1428
+ */
1429
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
1430
+ var _node$querySelectorAl;
1431
+ node.normalize();
1432
+ const walker = createNodeIterator.call(node.ownerDocument || node, node,
1433
+ // eslint-disable-next-line no-bitwise
1434
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
1435
+ let currentNode = walker.nextNode();
1436
+ while (currentNode) {
1437
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
1438
+ currentNode = walker.nextNode();
1439
+ }
1440
+ // NodeIterator does not descend into <template>.content per the DOM spec,
1441
+ // so we must explicitly recurse into each template's content fragment,
1442
+ // mirroring the approach used by _sanitizeShadowDOM.
1443
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
1444
+ if (templates) {
1445
+ arrayForEach(templates, tmpl => {
1446
+ if (_isDocumentFragment(tmpl.content)) {
1447
+ _scrubTemplateExpressions2(tmpl.content);
1448
+ }
1449
+ });
1450
+ }
1451
+ };
991
1452
  /**
992
1453
  * _isClobbered
993
1454
  *
1455
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
1456
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
1457
+ * `name` attribute matching a prototype property shadows that property
1458
+ * on direct reads. We use this check at the IN_PLACE entry-point and
1459
+ * during attribute sanitization to refuse clobbered forms.
1460
+ *
994
1461
  * @param element element to check for clobbering attacks
995
1462
  * @return true if clobbered, false if safe
996
1463
  */
997
1464
  const _isClobbered = function _isClobbered(element) {
998
- return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
1465
+ // Realm-independent tag-name probe. If we can't determine the tag
1466
+ // name at all, we can't reason about clobbering — return false
1467
+ // (the caller's other defences still apply).
1468
+ const realTagName = getNodeName ? getNodeName(element) : null;
1469
+ if (typeof realTagName !== 'string') {
1470
+ return false;
1471
+ }
1472
+ if (transformCaseFunc(realTagName) !== 'form') {
1473
+ return false;
1474
+ }
1475
+ return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
1476
+ // Realm-safe NamedNodeMap detection: equality against the cached
1477
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
1478
+ // makes the direct read diverge from the cached read; a clean form
1479
+ // (same-realm OR foreign-realm) has both reads pointing at the same
1480
+ // canonical NamedNodeMap.
1481
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
1482
+ // NodeType clobbering probe. Cached Node.prototype.nodeType getter
1483
+ // returns the integer 1 for any Element regardless of realm; direct
1484
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
1485
+ // the named child element. Cheap addition — nodeType is read from
1486
+ // an internal slot, no serialization cost — and removes a residual
1487
+ // clobbering surface used by several mXSS / PI / comment branches
1488
+ // in _sanitizeElements that compare currentNode.nodeType directly.
1489
+ element.nodeType !== getNodeType(element) ||
1490
+ // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
1491
+ // "childNodes" shadows the prototype getter. Direct reads of
1492
+ // form.childNodes from a clobbered form return the named child
1493
+ // instead of the real NodeList, so any walk that reads it directly
1494
+ // skips the form's real children. Compare the direct read to the
1495
+ // cached Node.prototype getter — when the form's named-property
1496
+ // getter intercepts the read, the two values differ and we flag
1497
+ // the form. This catches every clobbering child type (input,
1498
+ // select, etc.) regardless of whether the named child happens to
1499
+ // carry a numeric .length, which a typeof-based probe would miss
1500
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
1501
+ element.childNodes !== getChildNodes(element);
999
1502
  };
1000
1503
  /**
1001
- * Checks whether the given object is a DOM node.
1504
+ * Checks whether the given value is a DocumentFragment from any realm.
1505
+ *
1506
+ * The realm-independent replacement reads `nodeType` through the cached
1507
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
1508
+ * constant (11). nodeType is a numeric value resolved from the node's
1509
+ * internal slot, identical across realms for the same kind of node.
1510
+ *
1511
+ * @param value object to check
1512
+ * @return true if value is a DocumentFragment-shaped node from any realm
1513
+ */
1514
+ const _isDocumentFragment = function _isDocumentFragment(value) {
1515
+ if (!getNodeType || typeof value !== 'object' || value === null) {
1516
+ return false;
1517
+ }
1518
+ try {
1519
+ return getNodeType(value) === NODE_TYPE.documentFragment;
1520
+ } catch (_) {
1521
+ return false;
1522
+ }
1523
+ };
1524
+ /**
1525
+ * Checks whether the given object is a DOM node, including nodes that
1526
+ * originate from a different window/realm (e.g. an iframe's
1527
+ * contentDocument). The previous `value instanceof Node` check was
1528
+ * realm-bound: nodes from a different window failed it, causing
1529
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
1530
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
1002
1531
  *
1003
1532
  * @param value object to check whether it's a DOM node
1004
- * @return true is object is a DOM node
1533
+ * @return true if value is a DOM node from any realm
1005
1534
  */
1006
1535
  const _isNode = function _isNode(value) {
1007
- return typeof Node === 'function' && value instanceof Node;
1536
+ if (!getNodeType || typeof value !== 'object' || value === null) {
1537
+ return false;
1538
+ }
1539
+ try {
1540
+ return typeof getNodeType(value) === 'number';
1541
+ } catch (_) {
1542
+ return false;
1543
+ }
1008
1544
  };
1009
1545
  function _executeHooks(hooks, currentNode, data) {
1546
+ if (hooks.length === 0) {
1547
+ return;
1548
+ }
1010
1549
  arrayForEach(hooks, hook => {
1011
1550
  hook.call(DOMPurify, currentNode, data, CONFIG);
1012
1551
  });
1013
1552
  }
1553
+ /**
1554
+ * Structural-threat checks that condemn a node regardless of the
1555
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
1556
+ * processing instructions, markup-bearing comments. Pure predicate;
1557
+ * the caller removes. Check order is load-bearing.
1558
+ *
1559
+ * @param currentNode the node to inspect
1560
+ * @param tagName the node's transformCaseFunc'd tag name
1561
+ * @return true if the node must be removed
1562
+ */
1563
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
1564
+ /* Detect mXSS attempts abusing namespace confusion */
1565
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
1566
+ return true;
1567
+ }
1568
+ /* Remove risky CSS construction leading to mXSS */
1569
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
1570
+ return true;
1571
+ }
1572
+ /* Remove any occurrence of processing instructions */
1573
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
1574
+ return true;
1575
+ }
1576
+ /* Remove any kind of possibly harmful comments */
1577
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
1578
+ return true;
1579
+ }
1580
+ return false;
1581
+ };
1582
+ /**
1583
+ * Handle a node whose tag is forbidden or not allowlisted: keep
1584
+ * allowed custom elements (false return exits _sanitizeElements
1585
+ * early - namespace/fallback checks and the afterSanitizeElements
1586
+ * hook are intentionally skipped for kept custom elements), else
1587
+ * hoist content per KEEP_CONTENT and remove.
1588
+ *
1589
+ * @param currentNode the disallowed node
1590
+ * @param tagName the node's transformCaseFunc'd tag name
1591
+ * @return true if the node was removed, false if kept
1592
+ */
1593
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
1594
+ /* Check if we have a custom element to handle */
1595
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
1596
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1597
+ return false;
1598
+ }
1599
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
1600
+ return false;
1601
+ }
1602
+ }
1603
+ /* Keep content except for bad-listed elements.
1604
+ Use the cached prototype getters exclusively — the previous code
1605
+ had `|| currentNode.parentNode` / `|| currentNode.childNodes`
1606
+ fallbacks, but the cached getters always return the canonical
1607
+ value (or null for a real parent-less node), so the fallback
1608
+ path was dead in safe cases and a clobbering surface in unsafe
1609
+ ones. Falsy cached results stay falsy; the `if (childNodes &&
1610
+ parentNode)` check already gates correctly. */
1611
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1612
+ const parentNode = getParentNode(currentNode);
1613
+ const childNodes = getChildNodes(currentNode);
1614
+ if (childNodes && parentNode) {
1615
+ const childCount = childNodes.length;
1616
+ /* In-place: hoist the *original* children so the iterator visits
1617
+ and sanitises them through the same allowlist pass as every other
1618
+ node. The caller built the tree in the live document, so the
1619
+ originals carry already-queued resource events (`<img onerror>`,
1620
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
1621
+ those originals detached but still armed, firing in page scope
1622
+ while the returned tree looked clean. Moving is safe in-place: the
1623
+ root is pre-validated as an allowed tag and so is never the node
1624
+ being removed, which keeps `parentNode` inside the iterator root
1625
+ and the relocated child inside the serialised tree.
1626
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
1627
+ at — and the result serialised from — `body`, so a restrictive
1628
+ ALLOWED_TAGS that removes `body` itself must leave its content in
1629
+ place, which only cloning does; and those paths parse into an
1630
+ inert document, so their discarded originals never had a queued
1631
+ event to neutralise.
1632
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
1633
+ valid whether we move (drops the trailing entry) or clone (leaves
1634
+ the list intact). */
1635
+ for (let i = childCount - 1; i >= 0; --i) {
1636
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
1637
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
1638
+ }
1639
+ }
1640
+ }
1641
+ _forceRemove(currentNode);
1642
+ return true;
1643
+ };
1014
1644
  /**
1015
1645
  * _sanitizeElements
1016
1646
  *
@@ -1021,7 +1651,6 @@ var purify = {exports: {}};
1021
1651
  * @return true if node was killed, false if left alive
1022
1652
  */
1023
1653
  const _sanitizeElements = function _sanitizeElements(currentNode) {
1024
- let content = null;
1025
1654
  /* Execute a hook if present */
1026
1655
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
1027
1656
  /* Check if element is clobbered or can clobber */
@@ -1030,76 +1659,41 @@ var purify = {exports: {}};
1030
1659
  return true;
1031
1660
  }
1032
1661
  /* Now let's check the element's type and name */
1033
- const tagName = transformCaseFunc(currentNode.nodeName);
1662
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
1034
1663
  /* Execute a hook if present */
1035
1664
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
1036
1665
  tagName,
1037
1666
  allowedTags: ALLOWED_TAGS
1038
1667
  });
1039
- /* Detect mXSS attempts abusing namespace confusion */
1040
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
1041
- _forceRemove(currentNode);
1042
- return true;
1043
- }
1044
- /* Remove risky CSS construction leading to mXSS */
1045
- if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
1046
- _forceRemove(currentNode);
1047
- return true;
1048
- }
1049
- /* Remove any occurrence of processing instructions */
1050
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
1051
- _forceRemove(currentNode);
1052
- return true;
1053
- }
1054
- /* Remove any kind of possibly harmful comments */
1055
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
1668
+ /* Remove mXSS vectors, processing instructions and risky comments */
1669
+ if (_isUnsafeNode(currentNode, tagName)) {
1056
1670
  _forceRemove(currentNode);
1057
1671
  return true;
1058
1672
  }
1059
1673
  /* Remove element if anything forbids its presence */
1060
1674
  if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
1061
- /* Check if we have a custom element to handle */
1062
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
1063
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1064
- return false;
1065
- }
1066
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
1067
- return false;
1068
- }
1069
- }
1070
- /* Keep content except for bad-listed elements */
1071
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1072
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
1073
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1074
- if (childNodes && parentNode) {
1075
- const childCount = childNodes.length;
1076
- for (let i = childCount - 1; i >= 0; --i) {
1077
- const childClone = cloneNode(childNodes[i], true);
1078
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
1079
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
1080
- }
1081
- }
1082
- }
1083
- _forceRemove(currentNode);
1084
- return true;
1085
- }
1086
- /* Check whether element has a valid namespace */
1087
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1675
+ return _sanitizeDisallowedNode(currentNode, tagName);
1676
+ }
1677
+ /* Check whether element has a valid namespace.
1678
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
1679
+ nodeType getter rather than `instanceof Element`, which is realm-
1680
+ bound and short-circuits to false for any node minted in a different
1681
+ realm — letting a foreign-realm element with a forbidden namespace
1682
+ slip past the namespace check entirely. */
1683
+ const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
1684
+ if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
1088
1685
  _forceRemove(currentNode);
1089
1686
  return true;
1090
1687
  }
1091
1688
  /* Make sure that older browsers don't get fallback-tag mXSS */
1092
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
1689
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
1093
1690
  _forceRemove(currentNode);
1094
1691
  return true;
1095
1692
  }
1096
1693
  /* Sanitize element content to be template-safe */
1097
1694
  if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1098
1695
  /* Get the element's text content */
1099
- content = currentNode.textContent;
1100
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1101
- content = stringReplace(content, expr, ' ');
1102
- });
1696
+ const content = _stripTemplateExpressions(currentNode.textContent);
1103
1697
  if (currentNode.textContent !== content) {
1104
1698
  arrayPush(DOMPurify.removed, {
1105
1699
  element: currentNode.cloneNode()
@@ -1129,11 +1723,12 @@ var purify = {exports: {}};
1129
1723
  if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1130
1724
  return false;
1131
1725
  }
1726
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
1132
1727
  /* Allow valid data-* attributes: At least one character after "-"
1133
1728
  (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1134
1729
  XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1135
1730
  We don't need to check the value; it's always URI safe. */
1136
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1731
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
1137
1732
  if (
1138
1733
  // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1139
1734
  // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
@@ -1145,11 +1740,15 @@ var purify = {exports: {}};
1145
1740
  return false;
1146
1741
  }
1147
1742
  /* Check value is safe. First, is attr inert? If so, is safe */
1148
- } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1743
+ } 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) {
1149
1744
  return false;
1150
1745
  } else ;
1151
1746
  return true;
1152
1747
  };
1748
+ /* Names the HTML spec reserves from valid-custom-element-name; these must
1749
+ * never be treated as basic custom elements even when a permissive
1750
+ * CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
1751
+ 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']);
1153
1752
  /**
1154
1753
  * _isBasicCustomElement
1155
1754
  * checks if at least one dash is included in tagName, and it's not the first char
@@ -1159,7 +1758,64 @@ var purify = {exports: {}};
1159
1758
  * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1160
1759
  */
1161
1760
  const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1162
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1761
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
1762
+ };
1763
+ /**
1764
+ * Wrap an attribute value in the matching Trusted Types object when
1765
+ * the active policy requires it. Namespaced attributes pass through
1766
+ * unchanged (no TT support yet, see
1767
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
1768
+ *
1769
+ * @param lcTag lowercase tag name of the containing element
1770
+ * @param lcName lowercase attribute name
1771
+ * @param namespaceURI the attribute's namespace, if any
1772
+ * @param value the attribute value to wrap
1773
+ * @return the value, wrapped when Trusted Types demand it
1774
+ */
1775
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
1776
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
1777
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1778
+ case 'TrustedHTML':
1779
+ {
1780
+ return _createTrustedHTML(value);
1781
+ }
1782
+ case 'TrustedScriptURL':
1783
+ {
1784
+ return _createTrustedScriptURL(value);
1785
+ }
1786
+ }
1787
+ }
1788
+ return value;
1789
+ };
1790
+ /**
1791
+ * Write a modified attribute value back onto the element. On
1792
+ * success, re-probe for clobbering introduced by the new value and
1793
+ * remove the element when found; otherwise pop the removal entry
1794
+ * recorded by the earlier _removeAttribute (long-standing pairing
1795
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
1796
+ * failure, remove the attribute instead.
1797
+ *
1798
+ * @param currentNode the element carrying the attribute
1799
+ * @param name the attribute name as present on the element
1800
+ * @param namespaceURI the attribute's namespace, if any
1801
+ * @param value the new attribute value
1802
+ */
1803
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
1804
+ try {
1805
+ if (namespaceURI) {
1806
+ currentNode.setAttributeNS(namespaceURI, name, value);
1807
+ } else {
1808
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1809
+ currentNode.setAttribute(name, value);
1810
+ }
1811
+ if (_isClobbered(currentNode)) {
1812
+ _forceRemove(currentNode);
1813
+ } else {
1814
+ arrayPop(DOMPurify.removed);
1815
+ }
1816
+ } catch (_) {
1817
+ _removeAttribute(name, currentNode);
1818
+ }
1163
1819
  };
1164
1820
  /**
1165
1821
  * _sanitizeAttributes
@@ -1174,9 +1830,7 @@ var purify = {exports: {}};
1174
1830
  const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1175
1831
  /* Execute a hook if present */
1176
1832
  _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1177
- const {
1178
- attributes
1179
- } = currentNode;
1833
+ const attributes = currentNode.attributes;
1180
1834
  /* Check if we have attributes; if not we might have a text node */
1181
1835
  if (!attributes || _isClobbered(currentNode)) {
1182
1836
  return;
@@ -1189,14 +1843,13 @@ var purify = {exports: {}};
1189
1843
  forceKeepAttr: undefined
1190
1844
  };
1191
1845
  let l = attributes.length;
1846
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1192
1847
  /* Go backwards over all attributes; safely remove bad ones */
1193
1848
  while (l--) {
1194
1849
  const attr = attributes[l];
1195
- const {
1196
- name,
1197
- namespaceURI,
1198
- value: attrValue
1199
- } = attr;
1850
+ const name = attr.name,
1851
+ namespaceURI = attr.namespaceURI,
1852
+ attrValue = attr.value;
1200
1853
  const lcName = transformCaseFunc(name);
1201
1854
  const initValue = attrValue;
1202
1855
  let value = name === 'value' ? initValue : stringTrim(initValue);
@@ -1210,12 +1863,14 @@ var purify = {exports: {}};
1210
1863
  /* Full DOM Clobbering protection via namespace isolation,
1211
1864
  * Prefix id and name attributes with `user-content-`
1212
1865
  */
1213
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1866
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
1214
1867
  // Remove the attribute with this value
1215
1868
  _removeAttribute(name, currentNode);
1216
1869
  // Prefix the value and later re-create the attribute with the sanitized value
1217
1870
  value = SANITIZE_NAMED_PROPS_PREFIX + value;
1218
1871
  }
1872
+ // Else: already prefixed, leave the attribute alone — the prefix is
1873
+ // itself the clobbering protection, and re-applying it is incorrect.
1219
1874
  /* Work around a security issue with comments inside attributes */
1220
1875
  if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
1221
1876
  _removeAttribute(name, currentNode);
@@ -1226,7 +1881,7 @@ var purify = {exports: {}};
1226
1881
  _removeAttribute(name, currentNode);
1227
1882
  continue;
1228
1883
  }
1229
- /* Did the hooks approve of the attribute? */
1884
+ /* Did the hooks force-keep the attribute? */
1230
1885
  if (hookEvent.forceKeepAttr) {
1231
1886
  continue;
1232
1887
  }
@@ -1236,56 +1891,24 @@ var purify = {exports: {}};
1236
1891
  continue;
1237
1892
  }
1238
1893
  /* Work around a security issue in jQuery 3.0 */
1239
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1894
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
1240
1895
  _removeAttribute(name, currentNode);
1241
1896
  continue;
1242
1897
  }
1243
1898
  /* Sanitize attribute content to be template-safe */
1244
1899
  if (SAFE_FOR_TEMPLATES) {
1245
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1246
- value = stringReplace(value, expr, ' ');
1247
- });
1900
+ value = _stripTemplateExpressions(value);
1248
1901
  }
1249
1902
  /* Is `value` valid for this attribute? */
1250
- const lcTag = transformCaseFunc(currentNode.nodeName);
1251
1903
  if (!_isValidAttribute(lcTag, lcName, value)) {
1252
1904
  _removeAttribute(name, currentNode);
1253
1905
  continue;
1254
1906
  }
1255
1907
  /* Handle attributes that require Trusted Types */
1256
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1257
- if (namespaceURI) ; else {
1258
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1259
- case 'TrustedHTML':
1260
- {
1261
- value = trustedTypesPolicy.createHTML(value);
1262
- break;
1263
- }
1264
- case 'TrustedScriptURL':
1265
- {
1266
- value = trustedTypesPolicy.createScriptURL(value);
1267
- break;
1268
- }
1269
- }
1270
- }
1271
- }
1908
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
1272
1909
  /* Handle invalid data-* attribute set by try-catching it */
1273
1910
  if (value !== initValue) {
1274
- try {
1275
- if (namespaceURI) {
1276
- currentNode.setAttributeNS(namespaceURI, name, value);
1277
- } else {
1278
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1279
- currentNode.setAttribute(name, value);
1280
- }
1281
- if (_isClobbered(currentNode)) {
1282
- _forceRemove(currentNode);
1283
- } else {
1284
- arrayPop(DOMPurify.removed);
1285
- }
1286
- } catch (_) {
1287
- _removeAttribute(name, currentNode);
1288
- }
1911
+ _setAttributeValue(currentNode, name, namespaceURI, value);
1289
1912
  }
1290
1913
  }
1291
1914
  /* Execute a hook if present */
@@ -1308,14 +1931,133 @@ var purify = {exports: {}};
1308
1931
  _sanitizeElements(shadowNode);
1309
1932
  /* Check attributes next */
1310
1933
  _sanitizeAttributes(shadowNode);
1311
- /* Deep shadow DOM detected */
1312
- if (shadowNode.content instanceof DocumentFragment) {
1934
+ /* Deep shadow DOM detected.
1935
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
1936
+ DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
1937
+ recurse into <template>.content from foreign realms too. */
1938
+ if (_isDocumentFragment(shadowNode.content)) {
1313
1939
  _sanitizeShadowDOM2(shadowNode.content);
1314
1940
  }
1941
+ /* An element iterated here may itself host an attached
1942
+ shadow root. The default NodeIterator does not enter shadow
1943
+ trees, so a shadow root nested inside template.content was
1944
+ previously reached by no walk at all (the pre-pass at
1945
+ _sanitizeAttachedShadowRoots descends via childNodes, which
1946
+ doesn't enter template.content; the template-content recursion
1947
+ above iterates the content but never inspected shadowRoot).
1948
+ Walk it explicitly. The nodeType guard avoids reading
1949
+ shadowRoot off text / comment / CDATA / PI nodes that the
1950
+ iterator also surfaces. */
1951
+ const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
1952
+ if (shadowNodeType === NODE_TYPE.element) {
1953
+ const innerSr = getShadowRoot(shadowNode);
1954
+ if (_isDocumentFragment(innerSr)) {
1955
+ _sanitizeAttachedShadowRoots(innerSr);
1956
+ _sanitizeShadowDOM2(innerSr);
1957
+ }
1958
+ }
1315
1959
  }
1316
1960
  /* Execute a hook if present */
1317
1961
  _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1318
1962
  };
1963
+ /**
1964
+ * _sanitizeAttachedShadowRoots
1965
+ *
1966
+ * Walks `root` and feeds every attached shadow root we encounter into
1967
+ * the existing _sanitizeShadowDOM pipeline. The default node iterator
1968
+ * does not descend into shadow trees, so nodes inside an attached
1969
+ * shadow root would otherwise be skipped entirely.
1970
+ *
1971
+ * Two real input paths put attached shadow roots in front of us:
1972
+ * 1. IN_PLACE on a DOM node that already has shadow roots attached.
1973
+ * 2. DOM-node input where importNode(dirty, true) deep-clones the
1974
+ * shadow root because it was created with `clonable: true`.
1975
+ *
1976
+ * This pass runs once, up front, so the main iteration loop (and the
1977
+ * existing _sanitizeShadowDOM template-content recursion) stay
1978
+ * untouched — string-input paths are not affected.
1979
+ *
1980
+ * @param root the subtree root to walk for attached shadow roots
1981
+ */
1982
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
1983
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
1984
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
1985
+ built straight into the DOM — the IN_PLACE surface) deeper than the JS
1986
+ call-stack budget would otherwise overflow native recursion here and
1987
+ throw at the IN_PLACE entry pre-pass, before a single node is
1988
+ sanitized, leaving the caller's live tree untouched (fail-open). See
1989
+ campaign-3 F4. A heap stack keeps depth off the call stack.
1990
+ Each work item is either a node to descend into, or a deferred
1991
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
1992
+ form preserves the original post-order discipline: a shadow root's
1993
+ nested shadow roots are discovered before the outer shadow is
1994
+ sanitized (which may remove hosts). Pushes are in reverse of the
1995
+ desired processing order (LIFO): template content, then children, then
1996
+ the shadow-sanitize, then the shadow walk — so the order matches the
1997
+ previous recursion exactly. */
1998
+ const stack = [{
1999
+ node: root,
2000
+ shadow: null
2001
+ }];
2002
+ while (stack.length > 0) {
2003
+ const item = stack.pop();
2004
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
2005
+ if (item.shadow) {
2006
+ _sanitizeShadowDOM2(item.shadow);
2007
+ continue;
2008
+ }
2009
+ const node = item.node;
2010
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
2011
+ const isElement = nodeType === NODE_TYPE.element;
2012
+ /* (pushed last → processed first) Children, snapshotted in reverse so
2013
+ the first child is processed first. Snapshotting matters because a
2014
+ hook may detach siblings mid-walk. */
2015
+ const childNodes = getChildNodes(node);
2016
+ if (childNodes) {
2017
+ for (let i = childNodes.length - 1; i >= 0; --i) {
2018
+ stack.push({
2019
+ node: childNodes[i],
2020
+ shadow: null
2021
+ });
2022
+ }
2023
+ }
2024
+ /* (pushed before children → processed after them, matching the old
2025
+ "template content last" order) When the node is a <template>,
2026
+ descend into its content. */
2027
+ if (isElement) {
2028
+ const rootName = getNodeName ? getNodeName(node) : null;
2029
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
2030
+ const content = node.content;
2031
+ if (_isDocumentFragment(content)) {
2032
+ stack.push({
2033
+ node: content,
2034
+ shadow: null
2035
+ });
2036
+ }
2037
+ }
2038
+ }
2039
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
2040
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
2041
+ rather than `instanceof DocumentFragment`, which is realm-bound and
2042
+ silently skipped foreign-realm shadow roots (e.g.
2043
+ iframe.contentDocument attachShadow). */
2044
+ if (isElement) {
2045
+ const sr = getShadowRoot(node);
2046
+ if (_isDocumentFragment(sr)) {
2047
+ /* Push the deferred sanitise first so it pops after the shadow
2048
+ walk we push next, i.e. nested shadow roots are discovered
2049
+ before this one is sanitised. */
2050
+ stack.push({
2051
+ node: null,
2052
+ shadow: sr
2053
+ }, {
2054
+ node: sr,
2055
+ shadow: null
2056
+ });
2057
+ }
2058
+ }
2059
+ }
2060
+ };
1319
2061
  // eslint-disable-next-line complexity
1320
2062
  DOMPurify.sanitize = function (dirty) {
1321
2063
  let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -1332,13 +2074,9 @@ var purify = {exports: {}};
1332
2074
  }
1333
2075
  /* Stringify, in case dirty is an object */
1334
2076
  if (typeof dirty !== 'string' && !_isNode(dirty)) {
1335
- if (typeof dirty.toString === 'function') {
1336
- dirty = dirty.toString();
1337
- if (typeof dirty !== 'string') {
1338
- throw typeErrorCreate('dirty is not a string, aborting');
1339
- }
1340
- } else {
1341
- throw typeErrorCreate('toString is not a function');
2077
+ dirty = stringifyValue(dirty);
2078
+ if (typeof dirty !== 'string') {
2079
+ throw typeErrorCreate('dirty is not a string, aborting');
1342
2080
  }
1343
2081
  }
1344
2082
  /* Return dirty HTML if DOMPurify cannot run */
@@ -1346,24 +2084,78 @@ var purify = {exports: {}};
1346
2084
  return dirty;
1347
2085
  }
1348
2086
  /* Assign config vars */
1349
- if (!SET_CONFIG) {
2087
+ if (SET_CONFIG) {
2088
+ /* Persistent setConfig() path: _parseConfig is skipped, so the sets are
2089
+ * not re-derived per call. Restore them from the pristine bindings
2090
+ * captured at setConfig() time so a previous call's hook clone (mutated
2091
+ * below) does not carry over. */
2092
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
2093
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
2094
+ } else {
1350
2095
  _parseConfig(cfg);
1351
2096
  }
2097
+ /* Clone the hook-mutable allowlists before the walk whenever an
2098
+ * uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
2099
+ * and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
2100
+ * a hook that widens them would otherwise mutate the shared set
2101
+ * permanently: across later calls and across every element. Cloning per
2102
+ * walk keeps documented in-call widening working while scoping it to the
2103
+ * call. A single guard for both config paths - the per-call path rebinds
2104
+ * the sets in _parseConfig each call, the persistent path restores them
2105
+ * from the captured bindings just above - so the two cannot diverge. */
2106
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
2107
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
2108
+ }
2109
+ if (hooks.uponSanitizeAttribute.length > 0) {
2110
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
2111
+ }
1352
2112
  /* Clean up removed elements */
1353
2113
  DOMPurify.removed = [];
1354
- /* Check if dirty is correctly typed for IN_PLACE */
1355
- if (typeof dirty === 'string') {
1356
- IN_PLACE = false;
1357
- }
1358
- if (IN_PLACE) {
1359
- /* Do some early pre-sanitization to avoid unsafe root nodes */
1360
- if (dirty.nodeName) {
1361
- const tagName = transformCaseFunc(dirty.nodeName);
2114
+ /* Resolve IN_PLACE for this call without mutating persistent config.
2115
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
2116
+ where _parseConfig is skipped on later calls: a single string call would
2117
+ disable in-place mode for every subsequent node call, returning a
2118
+ sanitized copy while leaving the caller's node — which in-place callers
2119
+ keep using and whose return value they ignore unsanitized. REPORT-2. */
2120
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
2121
+ if (inPlace) {
2122
+ /* Do some early pre-sanitization to avoid unsafe root nodes.
2123
+ Read nodeName through the cached prototype getter — a clobbering
2124
+ child named "nodeName" on the form root would otherwise shadow
2125
+ the property and let this check skip the root-allowlist
2126
+ validation entirely. */
2127
+ const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
2128
+ if (typeof nn === 'string') {
2129
+ const tagName = transformCaseFunc(nn);
1362
2130
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1363
2131
  throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1364
2132
  }
1365
2133
  }
1366
- } else if (dirty instanceof Node) {
2134
+ /* Pre-flight the root through _isClobbered. The iterator-driven
2135
+ removal path can not detach a parent-less root: _forceRemove
2136
+ falls through to Element.prototype.remove(), which per spec
2137
+ is a no-op on a node with no parent. A clobbered root would
2138
+ then survive the main loop with its attributes uninspected,
2139
+ because _sanitizeAttributes early-returns on _isClobbered. The
2140
+ result would be an attacker-controlled form, complete with any
2141
+ event-handler attributes the caller passed in, handed back to
2142
+ the application unsanitized. Refuse to sanitize such a root
2143
+ the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
2144
+ if (_isClobbered(dirty)) {
2145
+ throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
2146
+ }
2147
+ /* Sanitize attached shadow roots before the main iterator runs.
2148
+ The iterator does not descend into shadow trees. Same fail-closed
2149
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
2150
+ inside a shadow root could abort this pre-pass before the walk runs,
2151
+ which would otherwise leave the entire live tree unsanitized. */
2152
+ try {
2153
+ _sanitizeAttachedShadowRoots(dirty);
2154
+ } catch (error) {
2155
+ _neutralizeRoot(dirty);
2156
+ throw error;
2157
+ }
2158
+ } else if (_isNode(dirty)) {
1367
2159
  /* If dirty is a DOM element, append to an empty document to avoid
1368
2160
  elements being stripped by the parser */
1369
2161
  body = _initDocument('<!---->');
@@ -1377,12 +2169,18 @@ var purify = {exports: {}};
1377
2169
  // eslint-disable-next-line unicorn/prefer-dom-node-append
1378
2170
  body.appendChild(importedNode);
1379
2171
  }
2172
+ /* Clonable shadow roots are deep-cloned by importNode(); sanitize
2173
+ them before the main iterator runs, since the iterator does not
2174
+ descend into shadow trees. The walk routes every read through a
2175
+ cached prototype getter so clobbering descendants on a form root
2176
+ cannot hide a shadow host from this pass. */
2177
+ _sanitizeAttachedShadowRoots(importedNode);
1380
2178
  } else {
1381
2179
  /* Exit directly if we have nothing to do */
1382
2180
  if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1383
2181
  // eslint-disable-next-line unicorn/prefer-includes
1384
2182
  dirty.indexOf('<') === -1) {
1385
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
2183
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
1386
2184
  }
1387
2185
  /* Initialize the document to work on */
1388
2186
  body = _initDocument(dirty);
@@ -1396,31 +2194,59 @@ var purify = {exports: {}};
1396
2194
  _forceRemove(body.firstChild);
1397
2195
  }
1398
2196
  /* Get node iterator */
1399
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1400
- /* Now start iterating over the created document */
1401
- while (currentNode = nodeIterator.nextNode()) {
1402
- /* Sanitize tags and elements */
1403
- _sanitizeElements(currentNode);
1404
- /* Check attributes next */
1405
- _sanitizeAttributes(currentNode);
1406
- /* Shadow DOM detected, sanitize it */
1407
- if (currentNode.content instanceof DocumentFragment) {
1408
- _sanitizeShadowDOM2(currentNode.content);
2197
+ const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
2198
+ /* Now start iterating over the created document.
2199
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
2200
+ engine/custom-element mutation can detach a node mid-walk so
2201
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
2202
+ barrier the caller's in-place tree would be left half-sanitized with the
2203
+ unvisited tail still armed. On any throw we fail closed — strip the
2204
+ in-place root bare then rethrow so the existing throw contract is
2205
+ preserved. (String/DOM-copy paths never return the partial body, so the
2206
+ propagating throw is already fail-closed there.) */
2207
+ try {
2208
+ while (currentNode = nodeIterator.nextNode()) {
2209
+ /* Sanitize tags and elements */
2210
+ _sanitizeElements(currentNode);
2211
+ /* Check attributes next */
2212
+ _sanitizeAttributes(currentNode);
2213
+ /* Shadow DOM detected, sanitize it.
2214
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
2215
+ instead of instanceof, so foreign-realm <template>.content is
2216
+ walked correctly. */
2217
+ if (_isDocumentFragment(currentNode.content)) {
2218
+ _sanitizeShadowDOM2(currentNode.content);
2219
+ }
2220
+ }
2221
+ } catch (error) {
2222
+ if (inPlace) {
2223
+ _neutralizeRoot(dirty);
1409
2224
  }
2225
+ throw error;
1410
2226
  }
1411
2227
  /* If we sanitized `dirty` in-place, return it. */
1412
- if (IN_PLACE) {
2228
+ if (inPlace) {
2229
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
2230
+ the caller's live tree is detached but may still hold a queued
2231
+ resource-event handler that fires in page scope after we return. The
2232
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
2233
+ non-allow-listed attributes off every other removed subtree (clobber,
2234
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
2235
+ cancelled before any event can fire. Runs synchronously, pre-return. */
2236
+ arrayForEach(DOMPurify.removed, entry => {
2237
+ if (entry.element) {
2238
+ _neutralizeSubtree(entry.element);
2239
+ }
2240
+ });
2241
+ if (SAFE_FOR_TEMPLATES) {
2242
+ _scrubTemplateExpressions2(dirty);
2243
+ }
1413
2244
  return dirty;
1414
2245
  }
1415
2246
  /* Return sanitized string or DOM */
1416
2247
  if (RETURN_DOM) {
1417
2248
  if (SAFE_FOR_TEMPLATES) {
1418
- body.normalize();
1419
- let html = body.innerHTML;
1420
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1421
- html = stringReplace(html, expr, ' ');
1422
- });
1423
- body.innerHTML = html;
2249
+ _scrubTemplateExpressions2(body);
1424
2250
  }
1425
2251
  if (RETURN_DOM_FRAGMENT) {
1426
2252
  returnNode = createDocumentFragment.call(body.ownerDocument);
@@ -1450,20 +2276,28 @@ var purify = {exports: {}};
1450
2276
  }
1451
2277
  /* Sanitize final string template-safe */
1452
2278
  if (SAFE_FOR_TEMPLATES) {
1453
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1454
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
1455
- });
2279
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
1456
2280
  }
1457
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
2281
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
1458
2282
  };
1459
2283
  DOMPurify.setConfig = function () {
1460
2284
  let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1461
2285
  _parseConfig(cfg);
1462
2286
  SET_CONFIG = true;
2287
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
2288
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
1463
2289
  };
1464
2290
  DOMPurify.clearConfig = function () {
1465
2291
  CONFIG = null;
1466
2292
  SET_CONFIG = false;
2293
+ SET_CONFIG_ALLOWED_TAGS = null;
2294
+ SET_CONFIG_ALLOWED_ATTR = null;
2295
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
2296
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
2297
+ // never recreated — Trusted Types throws on duplicate names) is restored by
2298
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
2299
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
2300
+ emptyHTML = '';
1467
2301
  };
1468
2302
  DOMPurify.isValidAttribute = function (tag, attr, value) {
1469
2303
  /* Initialize shared config vars if necessary. */
@@ -1478,9 +2312,19 @@ var purify = {exports: {}};
1478
2312
  if (typeof hookFunction !== 'function') {
1479
2313
  return;
1480
2314
  }
2315
+ /* Reject unknown entry points. Without this, a non-hook key (e.g.
2316
+ * '__proto__') indexes off the prototype chain rather than a real
2317
+ * hook array, and arrayPush then writes to Object.prototype. Guard
2318
+ * with an own-property check against the known hook names. */
2319
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2320
+ return;
2321
+ }
1481
2322
  arrayPush(hooks[entryPoint], hookFunction);
1482
2323
  };
1483
2324
  DOMPurify.removeHook = function (entryPoint, hookFunction) {
2325
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2326
+ return undefined;
2327
+ }
1484
2328
  if (hookFunction !== undefined) {
1485
2329
  const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1486
2330
  return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
@@ -1488,6 +2332,9 @@ var purify = {exports: {}};
1488
2332
  return arrayPop(hooks[entryPoint]);
1489
2333
  };
1490
2334
  DOMPurify.removeHooks = function (entryPoint) {
2335
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2336
+ return;
2337
+ }
1491
2338
  hooks[entryPoint] = [];
1492
2339
  };
1493
2340
  DOMPurify.removeAllHooks = function () {