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