@mulmoclaude/core 1.7.1 → 1.9.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/dist/artifacts/paths.cjs +43 -0
- package/dist/artifacts/paths.cjs.map +1 -1
- package/dist/artifacts/paths.d.ts +27 -0
- package/dist/artifacts/paths.js +41 -1
- package/dist/artifacts/paths.js.map +1 -1
- package/dist/files/byPath.d.ts +32 -0
- package/dist/files/htmlFileRequest.d.ts +4 -0
- package/dist/files/index.cjs +108 -0
- package/dist/files/index.cjs.map +1 -1
- package/dist/files/index.d.ts +2 -0
- package/dist/files/index.js +103 -1
- package/dist/files/index.js.map +1 -1
- package/dist/plugin-vue/index.cjs +2247 -0
- package/dist/plugin-vue/index.cjs.map +1 -1
- package/dist/plugin-vue/index.d.ts +1 -0
- package/dist/plugin-vue/index.js +2246 -1
- package/dist/plugin-vue/index.js.map +1 -1
- package/dist/plugin-vue/sanitizeMarkdownHtml.d.ts +6 -0
- package/dist/remote-host/server/firestoreSafeResult.d.ts +28 -0
- package/dist/remote-host/server/hostRunner.d.ts +5 -1
- package/dist/remote-host/server/index.cjs +168 -29
- package/dist/remote-host/server/index.cjs.map +1 -1
- package/dist/remote-host/server/index.d.ts +3 -1
- package/dist/remote-host/server/index.js +162 -30
- package/dist/remote-host/server/index.js.map +1 -1
- package/dist/remote-host/server/presenceBeat.d.ts +18 -0
- package/package.json +2 -1
package/dist/plugin-vue/index.js
CHANGED
|
@@ -86,6 +86,2251 @@ function useClipboardCopy(resetMs = DEFAULT_RESET_MS) {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
//#endregion
|
|
89
|
-
|
|
89
|
+
//#region ../../node_modules/dompurify/dist/purify.es.mjs
|
|
90
|
+
/*! @license DOMPurify 3.4.12 | (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.12/LICENSE */
|
|
91
|
+
function _arrayLikeToArray(r, a) {
|
|
92
|
+
(null == a || a > r.length) && (a = r.length);
|
|
93
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
94
|
+
return n;
|
|
95
|
+
}
|
|
96
|
+
function _arrayWithHoles(r) {
|
|
97
|
+
if (Array.isArray(r)) return r;
|
|
98
|
+
}
|
|
99
|
+
function _iterableToArrayLimit(r, l) {
|
|
100
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
101
|
+
if (null != t) {
|
|
102
|
+
var e, n, i, u, a = [], f = true, o = false;
|
|
103
|
+
try {
|
|
104
|
+
if (i = (t = t.call(r)).next, 0 === l);
|
|
105
|
+
else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
106
|
+
} catch (r) {
|
|
107
|
+
o = true, n = r;
|
|
108
|
+
} finally {
|
|
109
|
+
try {
|
|
110
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
111
|
+
} finally {
|
|
112
|
+
if (o) throw n;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return a;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function _nonIterableRest() {
|
|
119
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
120
|
+
}
|
|
121
|
+
function _slicedToArray(r, e) {
|
|
122
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
123
|
+
}
|
|
124
|
+
function _unsupportedIterableToArray(r, a) {
|
|
125
|
+
if (r) {
|
|
126
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
127
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
128
|
+
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;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
var entries = Object.entries;
|
|
132
|
+
var setPrototypeOf = Object.setPrototypeOf;
|
|
133
|
+
var isFrozen = Object.isFrozen;
|
|
134
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
135
|
+
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
136
|
+
var freeze = Object.freeze;
|
|
137
|
+
var seal = Object.seal;
|
|
138
|
+
var create = Object.create;
|
|
139
|
+
var _ref = typeof Reflect !== "undefined" && Reflect;
|
|
140
|
+
var apply = _ref.apply;
|
|
141
|
+
var construct = _ref.construct;
|
|
142
|
+
if (!freeze) freeze = function freeze(x) {
|
|
143
|
+
return x;
|
|
144
|
+
};
|
|
145
|
+
if (!seal) seal = function seal(x) {
|
|
146
|
+
return x;
|
|
147
|
+
};
|
|
148
|
+
if (!apply) apply = function apply(func, thisArg) {
|
|
149
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
|
|
150
|
+
return func.apply(thisArg, args);
|
|
151
|
+
};
|
|
152
|
+
if (!construct) construct = function construct(Func) {
|
|
153
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) args[_key2 - 1] = arguments[_key2];
|
|
154
|
+
return new Func(...args);
|
|
155
|
+
};
|
|
156
|
+
var arrayForEach = unapply(Array.prototype.forEach);
|
|
157
|
+
var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
|
|
158
|
+
var arrayPop = unapply(Array.prototype.pop);
|
|
159
|
+
var arrayPush = unapply(Array.prototype.push);
|
|
160
|
+
var arraySplice = unapply(Array.prototype.splice);
|
|
161
|
+
var arrayIsArray = Array.isArray;
|
|
162
|
+
var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
163
|
+
var stringToString = unapply(String.prototype.toString);
|
|
164
|
+
var stringMatch = unapply(String.prototype.match);
|
|
165
|
+
var stringReplace = unapply(String.prototype.replace);
|
|
166
|
+
var stringIndexOf = unapply(String.prototype.indexOf);
|
|
167
|
+
var stringTrim = unapply(String.prototype.trim);
|
|
168
|
+
var numberToString = unapply(Number.prototype.toString);
|
|
169
|
+
var booleanToString = unapply(Boolean.prototype.toString);
|
|
170
|
+
var bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.prototype.toString);
|
|
171
|
+
var symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
|
|
172
|
+
var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
173
|
+
var objectToString = unapply(Object.prototype.toString);
|
|
174
|
+
var regExpTest = unapply(RegExp.prototype.test);
|
|
175
|
+
var typeErrorCreate = unconstruct(TypeError);
|
|
176
|
+
/**
|
|
177
|
+
* Creates a new function that calls the given function with a specified thisArg and arguments.
|
|
178
|
+
*
|
|
179
|
+
* @param func - The function to be wrapped and called.
|
|
180
|
+
* @returns A new function that calls the given function with a specified thisArg and arguments.
|
|
181
|
+
*/
|
|
182
|
+
function unapply(func) {
|
|
183
|
+
return function(thisArg) {
|
|
184
|
+
if (thisArg instanceof RegExp) thisArg.lastIndex = 0;
|
|
185
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
|
|
186
|
+
return apply(func, thisArg, args);
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Creates a new function that constructs an instance of the given constructor function with the provided arguments.
|
|
191
|
+
*
|
|
192
|
+
* @param func - The constructor function to be wrapped and called.
|
|
193
|
+
* @returns A new function that constructs an instance of the given constructor function with the provided arguments.
|
|
194
|
+
*/
|
|
195
|
+
function unconstruct(Func) {
|
|
196
|
+
return function() {
|
|
197
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) args[_key4] = arguments[_key4];
|
|
198
|
+
return construct(Func, args);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Add properties to a lookup table
|
|
203
|
+
*
|
|
204
|
+
* @param set - The set to which elements will be added.
|
|
205
|
+
* @param array - The array containing elements to be added to the set.
|
|
206
|
+
* @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
|
|
207
|
+
* @returns The modified set with added elements.
|
|
208
|
+
*/
|
|
209
|
+
function addToSet(set, array) {
|
|
210
|
+
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
|
211
|
+
if (setPrototypeOf) setPrototypeOf(set, null);
|
|
212
|
+
if (!arrayIsArray(array)) return set;
|
|
213
|
+
let l = array.length;
|
|
214
|
+
while (l--) {
|
|
215
|
+
let element = array[l];
|
|
216
|
+
if (typeof element === "string") {
|
|
217
|
+
const lcElement = transformCaseFunc(element);
|
|
218
|
+
if (lcElement !== element) {
|
|
219
|
+
if (!isFrozen(array)) array[l] = lcElement;
|
|
220
|
+
element = lcElement;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
set[element] = true;
|
|
224
|
+
}
|
|
225
|
+
return set;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Clean up an array to harden against CSPP
|
|
229
|
+
*
|
|
230
|
+
* @param array - The array to be cleaned.
|
|
231
|
+
* @returns The cleaned version of the array
|
|
232
|
+
*/
|
|
233
|
+
function cleanArray(array) {
|
|
234
|
+
for (let index = 0; index < array.length; index++) if (!objectHasOwnProperty(array, index)) array[index] = null;
|
|
235
|
+
return array;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Shallow clone an object
|
|
239
|
+
*
|
|
240
|
+
* @param object - The object to be cloned.
|
|
241
|
+
* @returns A new object that copies the original.
|
|
242
|
+
*/
|
|
243
|
+
function clone(object) {
|
|
244
|
+
const newObject = create(null);
|
|
245
|
+
for (const _ref2 of entries(object)) {
|
|
246
|
+
var _ref3 = _slicedToArray(_ref2, 2);
|
|
247
|
+
const property = _ref3[0];
|
|
248
|
+
const value = _ref3[1];
|
|
249
|
+
if (objectHasOwnProperty(object, property)) if (arrayIsArray(value)) newObject[property] = cleanArray(value);
|
|
250
|
+
else if (value && typeof value === "object" && value.constructor === Object) newObject[property] = clone(value);
|
|
251
|
+
else newObject[property] = value;
|
|
252
|
+
}
|
|
253
|
+
return newObject;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Convert non-node values into strings without depending on direct property access.
|
|
257
|
+
*
|
|
258
|
+
* @param value - The value to stringify.
|
|
259
|
+
* @returns A string representation of the provided value.
|
|
260
|
+
*/
|
|
261
|
+
function stringifyValue(value) {
|
|
262
|
+
switch (typeof value) {
|
|
263
|
+
case "string": return value;
|
|
264
|
+
case "number": return numberToString(value);
|
|
265
|
+
case "boolean": return booleanToString(value);
|
|
266
|
+
case "bigint": return bigintToString ? bigintToString(value) : "0";
|
|
267
|
+
case "symbol": return symbolToString ? symbolToString(value) : "Symbol()";
|
|
268
|
+
case "undefined": return objectToString(value);
|
|
269
|
+
case "function":
|
|
270
|
+
case "object": {
|
|
271
|
+
if (value === null) return objectToString(value);
|
|
272
|
+
const valueAsRecord = value;
|
|
273
|
+
const valueToString = lookupGetter(valueAsRecord, "toString");
|
|
274
|
+
if (typeof valueToString === "function") {
|
|
275
|
+
const stringified = valueToString(valueAsRecord);
|
|
276
|
+
return typeof stringified === "string" ? stringified : objectToString(stringified);
|
|
277
|
+
}
|
|
278
|
+
return objectToString(value);
|
|
279
|
+
}
|
|
280
|
+
default: return objectToString(value);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* This method automatically checks if the prop is function or getter and behaves accordingly.
|
|
285
|
+
*
|
|
286
|
+
* @param object - The object to look up the getter function in its prototype chain.
|
|
287
|
+
* @param prop - The property name for which to find the getter function.
|
|
288
|
+
* @returns The getter function found in the prototype chain or a fallback function.
|
|
289
|
+
*/
|
|
290
|
+
function lookupGetter(object, prop) {
|
|
291
|
+
while (object !== null) {
|
|
292
|
+
const desc = getOwnPropertyDescriptor(object, prop);
|
|
293
|
+
if (desc) {
|
|
294
|
+
if (desc.get) return unapply(desc.get);
|
|
295
|
+
if (typeof desc.value === "function") return unapply(desc.value);
|
|
296
|
+
}
|
|
297
|
+
object = getPrototypeOf(object);
|
|
298
|
+
}
|
|
299
|
+
function fallbackValue() {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
return fallbackValue;
|
|
303
|
+
}
|
|
304
|
+
function isRegex(value) {
|
|
305
|
+
try {
|
|
306
|
+
regExpTest(value, "");
|
|
307
|
+
return true;
|
|
308
|
+
} catch (_unused) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
var html$1 = freeze([
|
|
313
|
+
"a",
|
|
314
|
+
"abbr",
|
|
315
|
+
"acronym",
|
|
316
|
+
"address",
|
|
317
|
+
"area",
|
|
318
|
+
"article",
|
|
319
|
+
"aside",
|
|
320
|
+
"audio",
|
|
321
|
+
"b",
|
|
322
|
+
"bdi",
|
|
323
|
+
"bdo",
|
|
324
|
+
"big",
|
|
325
|
+
"blink",
|
|
326
|
+
"blockquote",
|
|
327
|
+
"body",
|
|
328
|
+
"br",
|
|
329
|
+
"button",
|
|
330
|
+
"canvas",
|
|
331
|
+
"caption",
|
|
332
|
+
"center",
|
|
333
|
+
"cite",
|
|
334
|
+
"code",
|
|
335
|
+
"col",
|
|
336
|
+
"colgroup",
|
|
337
|
+
"content",
|
|
338
|
+
"data",
|
|
339
|
+
"datalist",
|
|
340
|
+
"dd",
|
|
341
|
+
"decorator",
|
|
342
|
+
"del",
|
|
343
|
+
"details",
|
|
344
|
+
"dfn",
|
|
345
|
+
"dialog",
|
|
346
|
+
"dir",
|
|
347
|
+
"div",
|
|
348
|
+
"dl",
|
|
349
|
+
"dt",
|
|
350
|
+
"element",
|
|
351
|
+
"em",
|
|
352
|
+
"fieldset",
|
|
353
|
+
"figcaption",
|
|
354
|
+
"figure",
|
|
355
|
+
"font",
|
|
356
|
+
"footer",
|
|
357
|
+
"form",
|
|
358
|
+
"h1",
|
|
359
|
+
"h2",
|
|
360
|
+
"h3",
|
|
361
|
+
"h4",
|
|
362
|
+
"h5",
|
|
363
|
+
"h6",
|
|
364
|
+
"head",
|
|
365
|
+
"header",
|
|
366
|
+
"hgroup",
|
|
367
|
+
"hr",
|
|
368
|
+
"html",
|
|
369
|
+
"i",
|
|
370
|
+
"img",
|
|
371
|
+
"input",
|
|
372
|
+
"ins",
|
|
373
|
+
"kbd",
|
|
374
|
+
"label",
|
|
375
|
+
"legend",
|
|
376
|
+
"li",
|
|
377
|
+
"main",
|
|
378
|
+
"map",
|
|
379
|
+
"mark",
|
|
380
|
+
"marquee",
|
|
381
|
+
"menu",
|
|
382
|
+
"menuitem",
|
|
383
|
+
"meter",
|
|
384
|
+
"nav",
|
|
385
|
+
"nobr",
|
|
386
|
+
"ol",
|
|
387
|
+
"optgroup",
|
|
388
|
+
"option",
|
|
389
|
+
"output",
|
|
390
|
+
"p",
|
|
391
|
+
"picture",
|
|
392
|
+
"pre",
|
|
393
|
+
"progress",
|
|
394
|
+
"q",
|
|
395
|
+
"rp",
|
|
396
|
+
"rt",
|
|
397
|
+
"ruby",
|
|
398
|
+
"s",
|
|
399
|
+
"samp",
|
|
400
|
+
"search",
|
|
401
|
+
"section",
|
|
402
|
+
"select",
|
|
403
|
+
"shadow",
|
|
404
|
+
"slot",
|
|
405
|
+
"small",
|
|
406
|
+
"source",
|
|
407
|
+
"spacer",
|
|
408
|
+
"span",
|
|
409
|
+
"strike",
|
|
410
|
+
"strong",
|
|
411
|
+
"style",
|
|
412
|
+
"sub",
|
|
413
|
+
"summary",
|
|
414
|
+
"sup",
|
|
415
|
+
"table",
|
|
416
|
+
"tbody",
|
|
417
|
+
"td",
|
|
418
|
+
"template",
|
|
419
|
+
"textarea",
|
|
420
|
+
"tfoot",
|
|
421
|
+
"th",
|
|
422
|
+
"thead",
|
|
423
|
+
"time",
|
|
424
|
+
"tr",
|
|
425
|
+
"track",
|
|
426
|
+
"tt",
|
|
427
|
+
"u",
|
|
428
|
+
"ul",
|
|
429
|
+
"var",
|
|
430
|
+
"video",
|
|
431
|
+
"wbr"
|
|
432
|
+
]);
|
|
433
|
+
var svg$1 = freeze([
|
|
434
|
+
"svg",
|
|
435
|
+
"a",
|
|
436
|
+
"altglyph",
|
|
437
|
+
"altglyphdef",
|
|
438
|
+
"altglyphitem",
|
|
439
|
+
"animatecolor",
|
|
440
|
+
"animatemotion",
|
|
441
|
+
"animatetransform",
|
|
442
|
+
"circle",
|
|
443
|
+
"clippath",
|
|
444
|
+
"defs",
|
|
445
|
+
"desc",
|
|
446
|
+
"ellipse",
|
|
447
|
+
"enterkeyhint",
|
|
448
|
+
"exportparts",
|
|
449
|
+
"filter",
|
|
450
|
+
"font",
|
|
451
|
+
"g",
|
|
452
|
+
"glyph",
|
|
453
|
+
"glyphref",
|
|
454
|
+
"hkern",
|
|
455
|
+
"image",
|
|
456
|
+
"inputmode",
|
|
457
|
+
"line",
|
|
458
|
+
"lineargradient",
|
|
459
|
+
"marker",
|
|
460
|
+
"mask",
|
|
461
|
+
"metadata",
|
|
462
|
+
"mpath",
|
|
463
|
+
"part",
|
|
464
|
+
"path",
|
|
465
|
+
"pattern",
|
|
466
|
+
"polygon",
|
|
467
|
+
"polyline",
|
|
468
|
+
"radialgradient",
|
|
469
|
+
"rect",
|
|
470
|
+
"stop",
|
|
471
|
+
"style",
|
|
472
|
+
"switch",
|
|
473
|
+
"symbol",
|
|
474
|
+
"text",
|
|
475
|
+
"textpath",
|
|
476
|
+
"title",
|
|
477
|
+
"tref",
|
|
478
|
+
"tspan",
|
|
479
|
+
"view",
|
|
480
|
+
"vkern"
|
|
481
|
+
]);
|
|
482
|
+
var svgFilters = freeze([
|
|
483
|
+
"feBlend",
|
|
484
|
+
"feColorMatrix",
|
|
485
|
+
"feComponentTransfer",
|
|
486
|
+
"feComposite",
|
|
487
|
+
"feConvolveMatrix",
|
|
488
|
+
"feDiffuseLighting",
|
|
489
|
+
"feDisplacementMap",
|
|
490
|
+
"feDistantLight",
|
|
491
|
+
"feDropShadow",
|
|
492
|
+
"feFlood",
|
|
493
|
+
"feFuncA",
|
|
494
|
+
"feFuncB",
|
|
495
|
+
"feFuncG",
|
|
496
|
+
"feFuncR",
|
|
497
|
+
"feGaussianBlur",
|
|
498
|
+
"feImage",
|
|
499
|
+
"feMerge",
|
|
500
|
+
"feMergeNode",
|
|
501
|
+
"feMorphology",
|
|
502
|
+
"feOffset",
|
|
503
|
+
"fePointLight",
|
|
504
|
+
"feSpecularLighting",
|
|
505
|
+
"feSpotLight",
|
|
506
|
+
"feTile",
|
|
507
|
+
"feTurbulence"
|
|
508
|
+
]);
|
|
509
|
+
var svgDisallowed = freeze([
|
|
510
|
+
"animate",
|
|
511
|
+
"color-profile",
|
|
512
|
+
"cursor",
|
|
513
|
+
"discard",
|
|
514
|
+
"font-face",
|
|
515
|
+
"font-face-format",
|
|
516
|
+
"font-face-name",
|
|
517
|
+
"font-face-src",
|
|
518
|
+
"font-face-uri",
|
|
519
|
+
"foreignobject",
|
|
520
|
+
"hatch",
|
|
521
|
+
"hatchpath",
|
|
522
|
+
"mesh",
|
|
523
|
+
"meshgradient",
|
|
524
|
+
"meshpatch",
|
|
525
|
+
"meshrow",
|
|
526
|
+
"missing-glyph",
|
|
527
|
+
"script",
|
|
528
|
+
"set",
|
|
529
|
+
"solidcolor",
|
|
530
|
+
"unknown",
|
|
531
|
+
"use"
|
|
532
|
+
]);
|
|
533
|
+
var mathMl$1 = freeze([
|
|
534
|
+
"math",
|
|
535
|
+
"menclose",
|
|
536
|
+
"merror",
|
|
537
|
+
"mfenced",
|
|
538
|
+
"mfrac",
|
|
539
|
+
"mglyph",
|
|
540
|
+
"mi",
|
|
541
|
+
"mlabeledtr",
|
|
542
|
+
"mmultiscripts",
|
|
543
|
+
"mn",
|
|
544
|
+
"mo",
|
|
545
|
+
"mover",
|
|
546
|
+
"mpadded",
|
|
547
|
+
"mphantom",
|
|
548
|
+
"mroot",
|
|
549
|
+
"mrow",
|
|
550
|
+
"ms",
|
|
551
|
+
"mspace",
|
|
552
|
+
"msqrt",
|
|
553
|
+
"mstyle",
|
|
554
|
+
"msub",
|
|
555
|
+
"msup",
|
|
556
|
+
"msubsup",
|
|
557
|
+
"mtable",
|
|
558
|
+
"mtd",
|
|
559
|
+
"mtext",
|
|
560
|
+
"mtr",
|
|
561
|
+
"munder",
|
|
562
|
+
"munderover",
|
|
563
|
+
"mprescripts"
|
|
564
|
+
]);
|
|
565
|
+
var mathMlDisallowed = freeze([
|
|
566
|
+
"maction",
|
|
567
|
+
"maligngroup",
|
|
568
|
+
"malignmark",
|
|
569
|
+
"mlongdiv",
|
|
570
|
+
"mscarries",
|
|
571
|
+
"mscarry",
|
|
572
|
+
"msgroup",
|
|
573
|
+
"mstack",
|
|
574
|
+
"msline",
|
|
575
|
+
"msrow",
|
|
576
|
+
"semantics",
|
|
577
|
+
"annotation",
|
|
578
|
+
"annotation-xml",
|
|
579
|
+
"mprescripts",
|
|
580
|
+
"none"
|
|
581
|
+
]);
|
|
582
|
+
var text = freeze(["#text"]);
|
|
583
|
+
var html = freeze([
|
|
584
|
+
"accept",
|
|
585
|
+
"action",
|
|
586
|
+
"align",
|
|
587
|
+
"alt",
|
|
588
|
+
"autocapitalize",
|
|
589
|
+
"autocomplete",
|
|
590
|
+
"autopictureinpicture",
|
|
591
|
+
"autoplay",
|
|
592
|
+
"background",
|
|
593
|
+
"bgcolor",
|
|
594
|
+
"border",
|
|
595
|
+
"capture",
|
|
596
|
+
"cellpadding",
|
|
597
|
+
"cellspacing",
|
|
598
|
+
"checked",
|
|
599
|
+
"cite",
|
|
600
|
+
"class",
|
|
601
|
+
"clear",
|
|
602
|
+
"color",
|
|
603
|
+
"cols",
|
|
604
|
+
"colspan",
|
|
605
|
+
"command",
|
|
606
|
+
"commandfor",
|
|
607
|
+
"controls",
|
|
608
|
+
"controlslist",
|
|
609
|
+
"coords",
|
|
610
|
+
"crossorigin",
|
|
611
|
+
"datetime",
|
|
612
|
+
"decoding",
|
|
613
|
+
"default",
|
|
614
|
+
"dir",
|
|
615
|
+
"disabled",
|
|
616
|
+
"disablepictureinpicture",
|
|
617
|
+
"disableremoteplayback",
|
|
618
|
+
"download",
|
|
619
|
+
"draggable",
|
|
620
|
+
"enctype",
|
|
621
|
+
"enterkeyhint",
|
|
622
|
+
"exportparts",
|
|
623
|
+
"face",
|
|
624
|
+
"for",
|
|
625
|
+
"headers",
|
|
626
|
+
"height",
|
|
627
|
+
"hidden",
|
|
628
|
+
"high",
|
|
629
|
+
"href",
|
|
630
|
+
"hreflang",
|
|
631
|
+
"id",
|
|
632
|
+
"inert",
|
|
633
|
+
"inputmode",
|
|
634
|
+
"integrity",
|
|
635
|
+
"ismap",
|
|
636
|
+
"kind",
|
|
637
|
+
"label",
|
|
638
|
+
"lang",
|
|
639
|
+
"list",
|
|
640
|
+
"loading",
|
|
641
|
+
"loop",
|
|
642
|
+
"low",
|
|
643
|
+
"max",
|
|
644
|
+
"maxlength",
|
|
645
|
+
"media",
|
|
646
|
+
"method",
|
|
647
|
+
"min",
|
|
648
|
+
"minlength",
|
|
649
|
+
"multiple",
|
|
650
|
+
"muted",
|
|
651
|
+
"name",
|
|
652
|
+
"nonce",
|
|
653
|
+
"noshade",
|
|
654
|
+
"novalidate",
|
|
655
|
+
"nowrap",
|
|
656
|
+
"open",
|
|
657
|
+
"optimum",
|
|
658
|
+
"part",
|
|
659
|
+
"pattern",
|
|
660
|
+
"placeholder",
|
|
661
|
+
"playsinline",
|
|
662
|
+
"popover",
|
|
663
|
+
"popovertarget",
|
|
664
|
+
"popovertargetaction",
|
|
665
|
+
"poster",
|
|
666
|
+
"preload",
|
|
667
|
+
"pubdate",
|
|
668
|
+
"radiogroup",
|
|
669
|
+
"readonly",
|
|
670
|
+
"rel",
|
|
671
|
+
"required",
|
|
672
|
+
"rev",
|
|
673
|
+
"reversed",
|
|
674
|
+
"role",
|
|
675
|
+
"rows",
|
|
676
|
+
"rowspan",
|
|
677
|
+
"spellcheck",
|
|
678
|
+
"scope",
|
|
679
|
+
"selected",
|
|
680
|
+
"shape",
|
|
681
|
+
"size",
|
|
682
|
+
"sizes",
|
|
683
|
+
"slot",
|
|
684
|
+
"span",
|
|
685
|
+
"srclang",
|
|
686
|
+
"start",
|
|
687
|
+
"src",
|
|
688
|
+
"srcset",
|
|
689
|
+
"step",
|
|
690
|
+
"style",
|
|
691
|
+
"summary",
|
|
692
|
+
"tabindex",
|
|
693
|
+
"title",
|
|
694
|
+
"translate",
|
|
695
|
+
"type",
|
|
696
|
+
"usemap",
|
|
697
|
+
"valign",
|
|
698
|
+
"value",
|
|
699
|
+
"width",
|
|
700
|
+
"wrap",
|
|
701
|
+
"xmlns"
|
|
702
|
+
]);
|
|
703
|
+
var svg = freeze([
|
|
704
|
+
"accent-height",
|
|
705
|
+
"accumulate",
|
|
706
|
+
"additive",
|
|
707
|
+
"alignment-baseline",
|
|
708
|
+
"amplitude",
|
|
709
|
+
"ascent",
|
|
710
|
+
"attributename",
|
|
711
|
+
"attributetype",
|
|
712
|
+
"azimuth",
|
|
713
|
+
"basefrequency",
|
|
714
|
+
"baseline-shift",
|
|
715
|
+
"begin",
|
|
716
|
+
"bias",
|
|
717
|
+
"by",
|
|
718
|
+
"class",
|
|
719
|
+
"clip",
|
|
720
|
+
"clippathunits",
|
|
721
|
+
"clip-path",
|
|
722
|
+
"clip-rule",
|
|
723
|
+
"color",
|
|
724
|
+
"color-interpolation",
|
|
725
|
+
"color-interpolation-filters",
|
|
726
|
+
"color-profile",
|
|
727
|
+
"color-rendering",
|
|
728
|
+
"cx",
|
|
729
|
+
"cy",
|
|
730
|
+
"d",
|
|
731
|
+
"dx",
|
|
732
|
+
"dy",
|
|
733
|
+
"diffuseconstant",
|
|
734
|
+
"direction",
|
|
735
|
+
"display",
|
|
736
|
+
"divisor",
|
|
737
|
+
"dominant-baseline",
|
|
738
|
+
"dur",
|
|
739
|
+
"edgemode",
|
|
740
|
+
"elevation",
|
|
741
|
+
"end",
|
|
742
|
+
"exponent",
|
|
743
|
+
"fill",
|
|
744
|
+
"fill-opacity",
|
|
745
|
+
"fill-rule",
|
|
746
|
+
"filter",
|
|
747
|
+
"filterunits",
|
|
748
|
+
"flood-color",
|
|
749
|
+
"flood-opacity",
|
|
750
|
+
"font-family",
|
|
751
|
+
"font-size",
|
|
752
|
+
"font-size-adjust",
|
|
753
|
+
"font-stretch",
|
|
754
|
+
"font-style",
|
|
755
|
+
"font-variant",
|
|
756
|
+
"font-weight",
|
|
757
|
+
"fx",
|
|
758
|
+
"fy",
|
|
759
|
+
"g1",
|
|
760
|
+
"g2",
|
|
761
|
+
"glyph-name",
|
|
762
|
+
"glyphref",
|
|
763
|
+
"gradientunits",
|
|
764
|
+
"gradienttransform",
|
|
765
|
+
"height",
|
|
766
|
+
"href",
|
|
767
|
+
"id",
|
|
768
|
+
"image-rendering",
|
|
769
|
+
"in",
|
|
770
|
+
"in2",
|
|
771
|
+
"intercept",
|
|
772
|
+
"k",
|
|
773
|
+
"k1",
|
|
774
|
+
"k2",
|
|
775
|
+
"k3",
|
|
776
|
+
"k4",
|
|
777
|
+
"kerning",
|
|
778
|
+
"keypoints",
|
|
779
|
+
"keysplines",
|
|
780
|
+
"keytimes",
|
|
781
|
+
"lang",
|
|
782
|
+
"lengthadjust",
|
|
783
|
+
"letter-spacing",
|
|
784
|
+
"kernelmatrix",
|
|
785
|
+
"kernelunitlength",
|
|
786
|
+
"lighting-color",
|
|
787
|
+
"local",
|
|
788
|
+
"marker-end",
|
|
789
|
+
"marker-mid",
|
|
790
|
+
"marker-start",
|
|
791
|
+
"markerheight",
|
|
792
|
+
"markerunits",
|
|
793
|
+
"markerwidth",
|
|
794
|
+
"maskcontentunits",
|
|
795
|
+
"maskunits",
|
|
796
|
+
"max",
|
|
797
|
+
"mask",
|
|
798
|
+
"mask-type",
|
|
799
|
+
"media",
|
|
800
|
+
"method",
|
|
801
|
+
"mode",
|
|
802
|
+
"min",
|
|
803
|
+
"name",
|
|
804
|
+
"numoctaves",
|
|
805
|
+
"offset",
|
|
806
|
+
"operator",
|
|
807
|
+
"opacity",
|
|
808
|
+
"order",
|
|
809
|
+
"orient",
|
|
810
|
+
"orientation",
|
|
811
|
+
"origin",
|
|
812
|
+
"overflow",
|
|
813
|
+
"paint-order",
|
|
814
|
+
"path",
|
|
815
|
+
"pathlength",
|
|
816
|
+
"patterncontentunits",
|
|
817
|
+
"patterntransform",
|
|
818
|
+
"patternunits",
|
|
819
|
+
"points",
|
|
820
|
+
"preservealpha",
|
|
821
|
+
"preserveaspectratio",
|
|
822
|
+
"primitiveunits",
|
|
823
|
+
"r",
|
|
824
|
+
"rx",
|
|
825
|
+
"ry",
|
|
826
|
+
"radius",
|
|
827
|
+
"refx",
|
|
828
|
+
"refy",
|
|
829
|
+
"repeatcount",
|
|
830
|
+
"repeatdur",
|
|
831
|
+
"restart",
|
|
832
|
+
"result",
|
|
833
|
+
"rotate",
|
|
834
|
+
"scale",
|
|
835
|
+
"seed",
|
|
836
|
+
"shape-rendering",
|
|
837
|
+
"slope",
|
|
838
|
+
"specularconstant",
|
|
839
|
+
"specularexponent",
|
|
840
|
+
"spreadmethod",
|
|
841
|
+
"startoffset",
|
|
842
|
+
"stddeviation",
|
|
843
|
+
"stitchtiles",
|
|
844
|
+
"stop-color",
|
|
845
|
+
"stop-opacity",
|
|
846
|
+
"stroke-dasharray",
|
|
847
|
+
"stroke-dashoffset",
|
|
848
|
+
"stroke-linecap",
|
|
849
|
+
"stroke-linejoin",
|
|
850
|
+
"stroke-miterlimit",
|
|
851
|
+
"stroke-opacity",
|
|
852
|
+
"stroke",
|
|
853
|
+
"stroke-width",
|
|
854
|
+
"style",
|
|
855
|
+
"surfacescale",
|
|
856
|
+
"systemlanguage",
|
|
857
|
+
"tabindex",
|
|
858
|
+
"tablevalues",
|
|
859
|
+
"targetx",
|
|
860
|
+
"targety",
|
|
861
|
+
"transform",
|
|
862
|
+
"transform-origin",
|
|
863
|
+
"text-anchor",
|
|
864
|
+
"text-decoration",
|
|
865
|
+
"text-orientation",
|
|
866
|
+
"text-rendering",
|
|
867
|
+
"textlength",
|
|
868
|
+
"type",
|
|
869
|
+
"u1",
|
|
870
|
+
"u2",
|
|
871
|
+
"unicode",
|
|
872
|
+
"values",
|
|
873
|
+
"viewbox",
|
|
874
|
+
"visibility",
|
|
875
|
+
"version",
|
|
876
|
+
"vert-adv-y",
|
|
877
|
+
"vert-origin-x",
|
|
878
|
+
"vert-origin-y",
|
|
879
|
+
"width",
|
|
880
|
+
"word-spacing",
|
|
881
|
+
"wrap",
|
|
882
|
+
"writing-mode",
|
|
883
|
+
"xchannelselector",
|
|
884
|
+
"ychannelselector",
|
|
885
|
+
"x",
|
|
886
|
+
"x1",
|
|
887
|
+
"x2",
|
|
888
|
+
"xmlns",
|
|
889
|
+
"y",
|
|
890
|
+
"y1",
|
|
891
|
+
"y2",
|
|
892
|
+
"z",
|
|
893
|
+
"zoomandpan"
|
|
894
|
+
]);
|
|
895
|
+
var mathMl = freeze([
|
|
896
|
+
"accent",
|
|
897
|
+
"accentunder",
|
|
898
|
+
"align",
|
|
899
|
+
"bevelled",
|
|
900
|
+
"close",
|
|
901
|
+
"columnalign",
|
|
902
|
+
"columnlines",
|
|
903
|
+
"columnspacing",
|
|
904
|
+
"columnspan",
|
|
905
|
+
"denomalign",
|
|
906
|
+
"depth",
|
|
907
|
+
"dir",
|
|
908
|
+
"display",
|
|
909
|
+
"displaystyle",
|
|
910
|
+
"encoding",
|
|
911
|
+
"fence",
|
|
912
|
+
"frame",
|
|
913
|
+
"height",
|
|
914
|
+
"href",
|
|
915
|
+
"id",
|
|
916
|
+
"largeop",
|
|
917
|
+
"length",
|
|
918
|
+
"linethickness",
|
|
919
|
+
"lquote",
|
|
920
|
+
"lspace",
|
|
921
|
+
"mathbackground",
|
|
922
|
+
"mathcolor",
|
|
923
|
+
"mathsize",
|
|
924
|
+
"mathvariant",
|
|
925
|
+
"maxsize",
|
|
926
|
+
"minsize",
|
|
927
|
+
"movablelimits",
|
|
928
|
+
"notation",
|
|
929
|
+
"numalign",
|
|
930
|
+
"open",
|
|
931
|
+
"rowalign",
|
|
932
|
+
"rowlines",
|
|
933
|
+
"rowspacing",
|
|
934
|
+
"rowspan",
|
|
935
|
+
"rspace",
|
|
936
|
+
"rquote",
|
|
937
|
+
"scriptlevel",
|
|
938
|
+
"scriptminsize",
|
|
939
|
+
"scriptsizemultiplier",
|
|
940
|
+
"selection",
|
|
941
|
+
"separator",
|
|
942
|
+
"separators",
|
|
943
|
+
"stretchy",
|
|
944
|
+
"subscriptshift",
|
|
945
|
+
"supscriptshift",
|
|
946
|
+
"symmetric",
|
|
947
|
+
"voffset",
|
|
948
|
+
"width",
|
|
949
|
+
"xmlns"
|
|
950
|
+
]);
|
|
951
|
+
var xml = freeze([
|
|
952
|
+
"xlink:href",
|
|
953
|
+
"xml:id",
|
|
954
|
+
"xlink:title",
|
|
955
|
+
"xml:space",
|
|
956
|
+
"xmlns:xlink"
|
|
957
|
+
]);
|
|
958
|
+
var MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
|
|
959
|
+
var ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
|
|
960
|
+
var TMPLIT_EXPR = seal(/\${[\w\W]*/g);
|
|
961
|
+
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
|
|
962
|
+
var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
|
963
|
+
var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
|
|
964
|
+
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
965
|
+
var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g);
|
|
966
|
+
var DOCTYPE_NAME = seal(/^html$/i);
|
|
967
|
+
var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
968
|
+
var ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
|
|
969
|
+
var COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
|
|
970
|
+
var FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
|
|
971
|
+
var SELF_CLOSING_TAG = seal(/\/>/i);
|
|
972
|
+
var NODE_TYPE = {
|
|
973
|
+
element: 1,
|
|
974
|
+
attribute: 2,
|
|
975
|
+
text: 3,
|
|
976
|
+
cdataSection: 4,
|
|
977
|
+
entityReference: 5,
|
|
978
|
+
entityNode: 6,
|
|
979
|
+
processingInstruction: 7,
|
|
980
|
+
comment: 8,
|
|
981
|
+
document: 9,
|
|
982
|
+
documentType: 10,
|
|
983
|
+
documentFragment: 11,
|
|
984
|
+
notation: 12
|
|
985
|
+
};
|
|
986
|
+
var getGlobal = function getGlobal() {
|
|
987
|
+
return typeof window === "undefined" ? null : window;
|
|
988
|
+
};
|
|
989
|
+
/**
|
|
990
|
+
* Creates a no-op policy for internal use only.
|
|
991
|
+
* Don't export this function outside this module!
|
|
992
|
+
* @param trustedTypes The policy factory.
|
|
993
|
+
* @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
|
|
994
|
+
* @return The policy created (or null, if Trusted Types
|
|
995
|
+
* are not supported or creating the policy failed).
|
|
996
|
+
*/
|
|
997
|
+
var _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
|
|
998
|
+
if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") return null;
|
|
999
|
+
let suffix = null;
|
|
1000
|
+
const ATTR_NAME = "data-tt-policy-suffix";
|
|
1001
|
+
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
|
1002
|
+
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
|
1003
|
+
try {
|
|
1004
|
+
return trustedTypes.createPolicy(policyName, {
|
|
1005
|
+
createHTML(html) {
|
|
1006
|
+
return html;
|
|
1007
|
+
},
|
|
1008
|
+
createScriptURL(scriptUrl) {
|
|
1009
|
+
return scriptUrl;
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
} catch (_) {
|
|
1013
|
+
console.warn("TrustedTypes policy " + policyName + " could not be created.");
|
|
1014
|
+
return null;
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
var _createHooksMap = function _createHooksMap() {
|
|
1018
|
+
return {
|
|
1019
|
+
afterSanitizeAttributes: [],
|
|
1020
|
+
afterSanitizeElements: [],
|
|
1021
|
+
afterSanitizeShadowDOM: [],
|
|
1022
|
+
beforeSanitizeAttributes: [],
|
|
1023
|
+
beforeSanitizeElements: [],
|
|
1024
|
+
beforeSanitizeShadowDOM: [],
|
|
1025
|
+
uponSanitizeAttribute: [],
|
|
1026
|
+
uponSanitizeElement: [],
|
|
1027
|
+
uponSanitizeShadowNode: []
|
|
1028
|
+
};
|
|
1029
|
+
};
|
|
1030
|
+
/**
|
|
1031
|
+
* Resolve a set-valued configuration option: a fresh set built from
|
|
1032
|
+
* cfg[key] when it is an own array property (seeded with a clone of
|
|
1033
|
+
* options.base when given, case-normalized via options.transform),
|
|
1034
|
+
* the fallback set otherwise.
|
|
1035
|
+
*
|
|
1036
|
+
* @param cfg the cloned, prototype-free configuration object
|
|
1037
|
+
* @param key the configuration property to read
|
|
1038
|
+
* @param fallback the set to use when the option is absent or not an array
|
|
1039
|
+
* @param options transform and optional base set to merge into
|
|
1040
|
+
* @returns the resolved set
|
|
1041
|
+
*/
|
|
1042
|
+
var _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
|
|
1043
|
+
return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
|
|
1044
|
+
};
|
|
1045
|
+
function createDOMPurify() {
|
|
1046
|
+
let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
1047
|
+
const DOMPurify = (root) => createDOMPurify(root);
|
|
1048
|
+
DOMPurify.version = "3.4.12";
|
|
1049
|
+
DOMPurify.removed = [];
|
|
1050
|
+
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
|
|
1051
|
+
DOMPurify.isSupported = false;
|
|
1052
|
+
return DOMPurify;
|
|
1053
|
+
}
|
|
1054
|
+
let document = window.document;
|
|
1055
|
+
const originalDocument = document;
|
|
1056
|
+
const currentScript = originalDocument.currentScript;
|
|
1057
|
+
window.DocumentFragment;
|
|
1058
|
+
const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter;
|
|
1059
|
+
window.NamedNodeMap === void 0 && (window.NamedNodeMap || window.MozNamedAttrMap);
|
|
1060
|
+
window.HTMLFormElement;
|
|
1061
|
+
const DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
|
|
1062
|
+
const ElementPrototype = Element.prototype;
|
|
1063
|
+
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
|
1064
|
+
const remove = lookupGetter(ElementPrototype, "remove");
|
|
1065
|
+
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
|
1066
|
+
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
|
1067
|
+
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
|
1068
|
+
const getShadowRoot = lookupGetter(ElementPrototype, "shadowRoot");
|
|
1069
|
+
const getAttributes = lookupGetter(ElementPrototype, "attributes");
|
|
1070
|
+
const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeType") : null;
|
|
1071
|
+
const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeName") : null;
|
|
1072
|
+
if (typeof HTMLTemplateElement === "function") {
|
|
1073
|
+
const template = document.createElement("template");
|
|
1074
|
+
if (template.content && template.content.ownerDocument) document = template.content.ownerDocument;
|
|
1075
|
+
}
|
|
1076
|
+
let trustedTypesPolicy;
|
|
1077
|
+
let emptyHTML = "";
|
|
1078
|
+
let defaultTrustedTypesPolicy;
|
|
1079
|
+
let defaultTrustedTypesPolicyResolved = false;
|
|
1080
|
+
let IN_TRUSTED_TYPES_POLICY = 0;
|
|
1081
|
+
const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
|
|
1082
|
+
if (IN_TRUSTED_TYPES_POLICY > 0) 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.");
|
|
1083
|
+
};
|
|
1084
|
+
const _createTrustedHTML = function _createTrustedHTML(html) {
|
|
1085
|
+
_assertNotInTrustedTypesPolicy();
|
|
1086
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
1087
|
+
try {
|
|
1088
|
+
return trustedTypesPolicy.createHTML(html);
|
|
1089
|
+
} finally {
|
|
1090
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
|
|
1094
|
+
_assertNotInTrustedTypesPolicy();
|
|
1095
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
1096
|
+
try {
|
|
1097
|
+
return trustedTypesPolicy.createScriptURL(scriptUrl);
|
|
1098
|
+
} finally {
|
|
1099
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
|
|
1103
|
+
if (!defaultTrustedTypesPolicyResolved) {
|
|
1104
|
+
defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
1105
|
+
defaultTrustedTypesPolicyResolved = true;
|
|
1106
|
+
}
|
|
1107
|
+
return defaultTrustedTypesPolicy;
|
|
1108
|
+
};
|
|
1109
|
+
const _document = document, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
|
|
1110
|
+
const importNode = originalDocument.importNode;
|
|
1111
|
+
let hooks = _createHooksMap();
|
|
1112
|
+
/**
|
|
1113
|
+
* Expose whether this browser supports running the full DOMPurify.
|
|
1114
|
+
*/
|
|
1115
|
+
DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
|
1116
|
+
const MUSTACHE_EXPR$1 = MUSTACHE_EXPR, ERB_EXPR$1 = ERB_EXPR, TMPLIT_EXPR$1 = TMPLIT_EXPR, DATA_ATTR$1 = DATA_ATTR, ARIA_ATTR$1 = ARIA_ATTR, IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA, ATTR_WHITESPACE$1 = ATTR_WHITESPACE, CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
|
|
1117
|
+
let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
|
|
1118
|
+
/**
|
|
1119
|
+
* We consider the elements and attributes below to be safe. Ideally
|
|
1120
|
+
* don't add any new ones but feel free to remove unwanted ones.
|
|
1121
|
+
*/
|
|
1122
|
+
let ALLOWED_TAGS = null;
|
|
1123
|
+
const DEFAULT_ALLOWED_TAGS = addToSet({}, [
|
|
1124
|
+
...html$1,
|
|
1125
|
+
...svg$1,
|
|
1126
|
+
...svgFilters,
|
|
1127
|
+
...mathMl$1,
|
|
1128
|
+
...text
|
|
1129
|
+
]);
|
|
1130
|
+
let ALLOWED_ATTR = null;
|
|
1131
|
+
const DEFAULT_ALLOWED_ATTR = addToSet({}, [
|
|
1132
|
+
...html,
|
|
1133
|
+
...svg,
|
|
1134
|
+
...mathMl,
|
|
1135
|
+
...xml
|
|
1136
|
+
]);
|
|
1137
|
+
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
1138
|
+
tagNameCheck: {
|
|
1139
|
+
writable: true,
|
|
1140
|
+
configurable: false,
|
|
1141
|
+
enumerable: true,
|
|
1142
|
+
value: null
|
|
1143
|
+
},
|
|
1144
|
+
attributeNameCheck: {
|
|
1145
|
+
writable: true,
|
|
1146
|
+
configurable: false,
|
|
1147
|
+
enumerable: true,
|
|
1148
|
+
value: null
|
|
1149
|
+
},
|
|
1150
|
+
allowCustomizedBuiltInElements: {
|
|
1151
|
+
writable: true,
|
|
1152
|
+
configurable: false,
|
|
1153
|
+
enumerable: true,
|
|
1154
|
+
value: false
|
|
1155
|
+
}
|
|
1156
|
+
}));
|
|
1157
|
+
let FORBID_TAGS = null;
|
|
1158
|
+
let FORBID_ATTR = null;
|
|
1159
|
+
const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
1160
|
+
tagCheck: {
|
|
1161
|
+
writable: true,
|
|
1162
|
+
configurable: false,
|
|
1163
|
+
enumerable: true,
|
|
1164
|
+
value: null
|
|
1165
|
+
},
|
|
1166
|
+
attributeCheck: {
|
|
1167
|
+
writable: true,
|
|
1168
|
+
configurable: false,
|
|
1169
|
+
enumerable: true,
|
|
1170
|
+
value: null
|
|
1171
|
+
}
|
|
1172
|
+
}));
|
|
1173
|
+
let ALLOW_ARIA_ATTR = true;
|
|
1174
|
+
let ALLOW_DATA_ATTR = true;
|
|
1175
|
+
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
1176
|
+
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
1177
|
+
let SAFE_FOR_TEMPLATES = false;
|
|
1178
|
+
let SAFE_FOR_XML = true;
|
|
1179
|
+
let WHOLE_DOCUMENT = false;
|
|
1180
|
+
let SET_CONFIG = false;
|
|
1181
|
+
let SET_CONFIG_ALLOWED_TAGS = null;
|
|
1182
|
+
let SET_CONFIG_ALLOWED_ATTR = null;
|
|
1183
|
+
let FORCE_BODY = false;
|
|
1184
|
+
let RETURN_DOM = false;
|
|
1185
|
+
let RETURN_DOM_FRAGMENT = false;
|
|
1186
|
+
let RETURN_TRUSTED_TYPE = false;
|
|
1187
|
+
let SANITIZE_DOM = true;
|
|
1188
|
+
let SANITIZE_NAMED_PROPS = false;
|
|
1189
|
+
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
|
1190
|
+
let KEEP_CONTENT = true;
|
|
1191
|
+
let IN_PLACE = false;
|
|
1192
|
+
let USE_PROFILES = {};
|
|
1193
|
+
let FORBID_CONTENTS = null;
|
|
1194
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, [
|
|
1195
|
+
"annotation-xml",
|
|
1196
|
+
"audio",
|
|
1197
|
+
"colgroup",
|
|
1198
|
+
"desc",
|
|
1199
|
+
"foreignobject",
|
|
1200
|
+
"head",
|
|
1201
|
+
"iframe",
|
|
1202
|
+
"math",
|
|
1203
|
+
"mi",
|
|
1204
|
+
"mn",
|
|
1205
|
+
"mo",
|
|
1206
|
+
"ms",
|
|
1207
|
+
"mtext",
|
|
1208
|
+
"noembed",
|
|
1209
|
+
"noframes",
|
|
1210
|
+
"noscript",
|
|
1211
|
+
"plaintext",
|
|
1212
|
+
"script",
|
|
1213
|
+
"selectedcontent",
|
|
1214
|
+
"style",
|
|
1215
|
+
"svg",
|
|
1216
|
+
"template",
|
|
1217
|
+
"thead",
|
|
1218
|
+
"title",
|
|
1219
|
+
"video",
|
|
1220
|
+
"xmp"
|
|
1221
|
+
]);
|
|
1222
|
+
let DATA_URI_TAGS = null;
|
|
1223
|
+
const DEFAULT_DATA_URI_TAGS = addToSet({}, [
|
|
1224
|
+
"audio",
|
|
1225
|
+
"video",
|
|
1226
|
+
"img",
|
|
1227
|
+
"source",
|
|
1228
|
+
"image",
|
|
1229
|
+
"track"
|
|
1230
|
+
]);
|
|
1231
|
+
let URI_SAFE_ATTRIBUTES = null;
|
|
1232
|
+
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
|
|
1233
|
+
"alt",
|
|
1234
|
+
"class",
|
|
1235
|
+
"for",
|
|
1236
|
+
"id",
|
|
1237
|
+
"label",
|
|
1238
|
+
"name",
|
|
1239
|
+
"pattern",
|
|
1240
|
+
"placeholder",
|
|
1241
|
+
"role",
|
|
1242
|
+
"summary",
|
|
1243
|
+
"title",
|
|
1244
|
+
"value",
|
|
1245
|
+
"style",
|
|
1246
|
+
"xmlns"
|
|
1247
|
+
]);
|
|
1248
|
+
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
|
1249
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
1250
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
1251
|
+
let NAMESPACE = HTML_NAMESPACE;
|
|
1252
|
+
let IS_EMPTY_INPUT = false;
|
|
1253
|
+
let ALLOWED_NAMESPACES = null;
|
|
1254
|
+
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [
|
|
1255
|
+
MATHML_NAMESPACE,
|
|
1256
|
+
SVG_NAMESPACE,
|
|
1257
|
+
HTML_NAMESPACE
|
|
1258
|
+
], stringToString);
|
|
1259
|
+
const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze([
|
|
1260
|
+
"mi",
|
|
1261
|
+
"mo",
|
|
1262
|
+
"mn",
|
|
1263
|
+
"ms",
|
|
1264
|
+
"mtext"
|
|
1265
|
+
]);
|
|
1266
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
|
|
1267
|
+
const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
|
|
1268
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
|
|
1269
|
+
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
|
|
1270
|
+
"title",
|
|
1271
|
+
"style",
|
|
1272
|
+
"font",
|
|
1273
|
+
"a",
|
|
1274
|
+
"script"
|
|
1275
|
+
]);
|
|
1276
|
+
let PARSER_MEDIA_TYPE = null;
|
|
1277
|
+
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
|
1278
|
+
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
|
1279
|
+
let transformCaseFunc = null;
|
|
1280
|
+
let CONFIG = null;
|
|
1281
|
+
const formElement = document.createElement("form");
|
|
1282
|
+
const isRegexOrFunction = function isRegexOrFunction(testValue) {
|
|
1283
|
+
return testValue instanceof RegExp || testValue instanceof Function;
|
|
1284
|
+
};
|
|
1285
|
+
/**
|
|
1286
|
+
* _parseConfig
|
|
1287
|
+
*
|
|
1288
|
+
* @param cfg optional config literal
|
|
1289
|
+
*/
|
|
1290
|
+
const _parseConfig = function _parseConfig() {
|
|
1291
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1292
|
+
if (CONFIG && CONFIG === cfg) return;
|
|
1293
|
+
if (!cfg || typeof cfg !== "object") cfg = {};
|
|
1294
|
+
cfg = clone(cfg);
|
|
1295
|
+
PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
1296
|
+
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
|
1297
|
+
ALLOWED_TAGS = _resolveSetOption(cfg, "ALLOWED_TAGS", DEFAULT_ALLOWED_TAGS, { transform: transformCaseFunc });
|
|
1298
|
+
ALLOWED_ATTR = _resolveSetOption(cfg, "ALLOWED_ATTR", DEFAULT_ALLOWED_ATTR, { transform: transformCaseFunc });
|
|
1299
|
+
ALLOWED_NAMESPACES = _resolveSetOption(cfg, "ALLOWED_NAMESPACES", DEFAULT_ALLOWED_NAMESPACES, { transform: stringToString });
|
|
1300
|
+
URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, "ADD_URI_SAFE_ATTR", DEFAULT_URI_SAFE_ATTRIBUTES, {
|
|
1301
|
+
transform: transformCaseFunc,
|
|
1302
|
+
base: DEFAULT_URI_SAFE_ATTRIBUTES
|
|
1303
|
+
});
|
|
1304
|
+
DATA_URI_TAGS = _resolveSetOption(cfg, "ADD_DATA_URI_TAGS", DEFAULT_DATA_URI_TAGS, {
|
|
1305
|
+
transform: transformCaseFunc,
|
|
1306
|
+
base: DEFAULT_DATA_URI_TAGS
|
|
1307
|
+
});
|
|
1308
|
+
FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
|
|
1309
|
+
FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", clone({}), { transform: transformCaseFunc });
|
|
1310
|
+
FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", clone({}), { transform: transformCaseFunc });
|
|
1311
|
+
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
|
|
1312
|
+
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
|
1313
|
+
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
|
1314
|
+
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
|
1315
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
|
1316
|
+
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
|
1317
|
+
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
|
1318
|
+
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
|
1319
|
+
RETURN_DOM = cfg.RETURN_DOM || false;
|
|
1320
|
+
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
|
1321
|
+
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
|
1322
|
+
FORCE_BODY = cfg.FORCE_BODY || false;
|
|
1323
|
+
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
|
1324
|
+
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
|
1325
|
+
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
|
1326
|
+
IN_PLACE = cfg.IN_PLACE || false;
|
|
1327
|
+
IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
|
|
1328
|
+
NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
|
|
1329
|
+
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);
|
|
1330
|
+
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);
|
|
1331
|
+
const customElementHandling = objectHasOwnProperty(cfg, "CUSTOM_ELEMENT_HANDLING") && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === "object" ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
|
|
1332
|
+
CUSTOM_ELEMENT_HANDLING = create(null);
|
|
1333
|
+
if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
|
|
1334
|
+
if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
|
|
1335
|
+
if (objectHasOwnProperty(customElementHandling, "allowCustomizedBuiltInElements") && typeof customElementHandling.allowCustomizedBuiltInElements === "boolean") CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements;
|
|
1336
|
+
seal(CUSTOM_ELEMENT_HANDLING);
|
|
1337
|
+
if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
|
|
1338
|
+
if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
|
|
1339
|
+
if (USE_PROFILES) {
|
|
1340
|
+
ALLOWED_TAGS = addToSet({}, text);
|
|
1341
|
+
ALLOWED_ATTR = create(null);
|
|
1342
|
+
if (USE_PROFILES.html === true) {
|
|
1343
|
+
addToSet(ALLOWED_TAGS, html$1);
|
|
1344
|
+
addToSet(ALLOWED_ATTR, html);
|
|
1345
|
+
}
|
|
1346
|
+
if (USE_PROFILES.svg === true) {
|
|
1347
|
+
addToSet(ALLOWED_TAGS, svg$1);
|
|
1348
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
1349
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1350
|
+
}
|
|
1351
|
+
if (USE_PROFILES.svgFilters === true) {
|
|
1352
|
+
addToSet(ALLOWED_TAGS, svgFilters);
|
|
1353
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
1354
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1355
|
+
}
|
|
1356
|
+
if (USE_PROFILES.mathMl === true) {
|
|
1357
|
+
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
1358
|
+
addToSet(ALLOWED_ATTR, mathMl);
|
|
1359
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
EXTRA_ELEMENT_HANDLING.tagCheck = null;
|
|
1363
|
+
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
|
|
1364
|
+
if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
|
|
1365
|
+
if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
1366
|
+
else if (arrayIsArray(cfg.ADD_TAGS)) {
|
|
1367
|
+
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
1368
|
+
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
|
|
1372
|
+
if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
1373
|
+
else if (arrayIsArray(cfg.ADD_ATTR)) {
|
|
1374
|
+
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
1375
|
+
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
if (objectHasOwnProperty(cfg, "ADD_URI_SAFE_ATTR") && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
1379
|
+
if (objectHasOwnProperty(cfg, "FORBID_CONTENTS") && arrayIsArray(cfg.FORBID_CONTENTS)) {
|
|
1380
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
1381
|
+
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
1382
|
+
}
|
|
1383
|
+
if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
|
|
1384
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
1385
|
+
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
1386
|
+
}
|
|
1387
|
+
if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
|
|
1388
|
+
if (WHOLE_DOCUMENT) addToSet(ALLOWED_TAGS, [
|
|
1389
|
+
"html",
|
|
1390
|
+
"head",
|
|
1391
|
+
"body"
|
|
1392
|
+
]);
|
|
1393
|
+
if (ALLOWED_TAGS.table) {
|
|
1394
|
+
addToSet(ALLOWED_TAGS, ["tbody"]);
|
|
1395
|
+
delete FORBID_TAGS.tbody;
|
|
1396
|
+
}
|
|
1397
|
+
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
1398
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.");
|
|
1399
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.");
|
|
1400
|
+
const previousTrustedTypesPolicy = trustedTypesPolicy;
|
|
1401
|
+
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
1402
|
+
try {
|
|
1403
|
+
emptyHTML = _createTrustedHTML("");
|
|
1404
|
+
} catch (error) {
|
|
1405
|
+
trustedTypesPolicy = previousTrustedTypesPolicy;
|
|
1406
|
+
throw error;
|
|
1407
|
+
}
|
|
1408
|
+
} else if (cfg.TRUSTED_TYPES_POLICY === null) {
|
|
1409
|
+
trustedTypesPolicy = void 0;
|
|
1410
|
+
emptyHTML = "";
|
|
1411
|
+
} else {
|
|
1412
|
+
if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
|
|
1413
|
+
if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
|
|
1414
|
+
}
|
|
1415
|
+
if (freeze) freeze(cfg);
|
|
1416
|
+
CONFIG = cfg;
|
|
1417
|
+
};
|
|
1418
|
+
const ALL_SVG_TAGS = addToSet({}, [
|
|
1419
|
+
...svg$1,
|
|
1420
|
+
...svgFilters,
|
|
1421
|
+
...svgDisallowed
|
|
1422
|
+
]);
|
|
1423
|
+
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
1424
|
+
/**
|
|
1425
|
+
* Namespace rules for an element in the SVG namespace.
|
|
1426
|
+
*
|
|
1427
|
+
* @param tagName the element's lowercase tag name
|
|
1428
|
+
* @param parent the (possibly simulated) parent node
|
|
1429
|
+
* @param parentTagName the parent's lowercase tag name
|
|
1430
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
1431
|
+
*/
|
|
1432
|
+
const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
|
|
1433
|
+
if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "svg";
|
|
1434
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
1435
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
1436
|
+
};
|
|
1437
|
+
/**
|
|
1438
|
+
* Namespace rules for an element in the MathML namespace.
|
|
1439
|
+
*
|
|
1440
|
+
* @param tagName the element's lowercase tag name
|
|
1441
|
+
* @param parent the (possibly simulated) parent node
|
|
1442
|
+
* @param parentTagName the parent's lowercase tag name
|
|
1443
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
1444
|
+
*/
|
|
1445
|
+
const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
|
|
1446
|
+
if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "math";
|
|
1447
|
+
if (parent.namespaceURI === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
|
1448
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
1449
|
+
};
|
|
1450
|
+
/**
|
|
1451
|
+
* Namespace rules for an element in the HTML namespace.
|
|
1452
|
+
*
|
|
1453
|
+
* @param tagName the element's lowercase tag name
|
|
1454
|
+
* @param parent the (possibly simulated) parent node
|
|
1455
|
+
* @param parentTagName the parent's lowercase tag name
|
|
1456
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
1457
|
+
*/
|
|
1458
|
+
const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
|
|
1459
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
|
|
1460
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
|
|
1461
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
1462
|
+
};
|
|
1463
|
+
/**
|
|
1464
|
+
* @param element a DOM element whose namespace is being checked
|
|
1465
|
+
* @returns Return false if the element has a
|
|
1466
|
+
* namespace that a spec-compliant parser would never
|
|
1467
|
+
* return. Return true otherwise.
|
|
1468
|
+
*/
|
|
1469
|
+
const _checkValidNamespace = function _checkValidNamespace(element) {
|
|
1470
|
+
let parent = getParentNode(element);
|
|
1471
|
+
if (!parent || !parent.tagName) parent = {
|
|
1472
|
+
namespaceURI: NAMESPACE,
|
|
1473
|
+
tagName: "template"
|
|
1474
|
+
};
|
|
1475
|
+
const tagName = stringToLowerCase(element.tagName);
|
|
1476
|
+
const parentTagName = stringToLowerCase(parent.tagName);
|
|
1477
|
+
if (!ALLOWED_NAMESPACES[element.namespaceURI]) return false;
|
|
1478
|
+
if (element.namespaceURI === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
|
|
1479
|
+
if (element.namespaceURI === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
|
|
1480
|
+
if (element.namespaceURI === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
|
|
1481
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) return true;
|
|
1482
|
+
return false;
|
|
1483
|
+
};
|
|
1484
|
+
/**
|
|
1485
|
+
* _forceRemove
|
|
1486
|
+
*
|
|
1487
|
+
* @param node a DOM node
|
|
1488
|
+
*/
|
|
1489
|
+
const _forceRemove = function _forceRemove(node) {
|
|
1490
|
+
arrayPush(DOMPurify.removed, { element: node });
|
|
1491
|
+
try {
|
|
1492
|
+
getParentNode(node).removeChild(node);
|
|
1493
|
+
} catch (_) {
|
|
1494
|
+
remove(node);
|
|
1495
|
+
if (!getParentNode(node)) throw typeErrorCreate("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place");
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
/**
|
|
1499
|
+
* _neutralizeRoot
|
|
1500
|
+
*
|
|
1501
|
+
* Fail-closed teardown of an in-place root after the sanitize walk aborts
|
|
1502
|
+
* (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
|
|
1503
|
+
* custom element's reaction detaches a node so `_forceRemove`'s deliberate
|
|
1504
|
+
* parentless guard throws, or any other re-entrant engine mutation — would
|
|
1505
|
+
* otherwise leave the caller's *live* tree half-sanitized, with everything
|
|
1506
|
+
* after the abort point still carrying its handlers. There is no safe way
|
|
1507
|
+
* to resume the walk (the tree mutated under us), so we strip the root bare:
|
|
1508
|
+
* remove every child and every attribute, then let the caller's catch see
|
|
1509
|
+
* the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
|
|
1510
|
+
* getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
|
|
1511
|
+
*
|
|
1512
|
+
* @param root the in-place root to empty
|
|
1513
|
+
*/
|
|
1514
|
+
const _neutralizeRoot = function _neutralizeRoot(root) {
|
|
1515
|
+
_neutralizeSubtree(root);
|
|
1516
|
+
const childNodes = getChildNodes(root);
|
|
1517
|
+
if (childNodes) {
|
|
1518
|
+
const snapshot = [];
|
|
1519
|
+
arrayForEach(childNodes, (child) => {
|
|
1520
|
+
arrayPush(snapshot, child);
|
|
1521
|
+
});
|
|
1522
|
+
arrayForEach(snapshot, (child) => {
|
|
1523
|
+
try {
|
|
1524
|
+
remove(child);
|
|
1525
|
+
} catch (_) {}
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
const attributes = getAttributes(root);
|
|
1529
|
+
if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
|
|
1530
|
+
const attribute = attributes[i];
|
|
1531
|
+
const name = attribute && attribute.name;
|
|
1532
|
+
if (typeof name === "string") try {
|
|
1533
|
+
root.removeAttribute(name);
|
|
1534
|
+
} catch (_) {}
|
|
1535
|
+
}
|
|
1536
|
+
};
|
|
1537
|
+
/**
|
|
1538
|
+
* _removeAttribute
|
|
1539
|
+
*
|
|
1540
|
+
* @param name an Attribute name
|
|
1541
|
+
* @param element a DOM node
|
|
1542
|
+
*/
|
|
1543
|
+
const _removeAttribute = function _removeAttribute(name, element) {
|
|
1544
|
+
try {
|
|
1545
|
+
arrayPush(DOMPurify.removed, {
|
|
1546
|
+
attribute: element.getAttributeNode(name),
|
|
1547
|
+
from: element
|
|
1548
|
+
});
|
|
1549
|
+
} catch (_) {
|
|
1550
|
+
arrayPush(DOMPurify.removed, {
|
|
1551
|
+
attribute: null,
|
|
1552
|
+
from: element
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
element.removeAttribute(name);
|
|
1556
|
+
if (name === "is") if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
|
|
1557
|
+
_forceRemove(element);
|
|
1558
|
+
} catch (_) {}
|
|
1559
|
+
else try {
|
|
1560
|
+
element.setAttribute(name, "");
|
|
1561
|
+
} catch (_) {}
|
|
1562
|
+
};
|
|
1563
|
+
/**
|
|
1564
|
+
* _stripDisallowedAttributes
|
|
1565
|
+
*
|
|
1566
|
+
* Removes every attribute the active configuration does not allow from a
|
|
1567
|
+
* single element, using the same allowlist as the main attribute pass (so
|
|
1568
|
+
* `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
|
|
1569
|
+
* neutralise nodes that are being discarded from an in-place tree.
|
|
1570
|
+
*
|
|
1571
|
+
* @param element the element to strip
|
|
1572
|
+
*/
|
|
1573
|
+
const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
|
|
1574
|
+
const attributes = getAttributes(element);
|
|
1575
|
+
if (!attributes) return;
|
|
1576
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
1577
|
+
const attribute = attributes[i];
|
|
1578
|
+
const name = attribute && attribute.name;
|
|
1579
|
+
if (typeof name !== "string" || ALLOWED_ATTR[transformCaseFunc(name)]) continue;
|
|
1580
|
+
try {
|
|
1581
|
+
element.removeAttribute(name);
|
|
1582
|
+
} catch (_) {}
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
/**
|
|
1586
|
+
* _neutralizeSubtree
|
|
1587
|
+
*
|
|
1588
|
+
* Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
|
|
1589
|
+
* move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
|
|
1590
|
+
* namespace, comment, processing-instruction and KEEP_CONTENT:false removals
|
|
1591
|
+
* all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
|
|
1592
|
+
* those dropped nodes are detached from the caller's LIVE tree but a
|
|
1593
|
+
* handler-bearing original among them (an `<img onerror>`/`<video>` that was
|
|
1594
|
+
* loading) keeps its queued resource event, which fires in page scope after
|
|
1595
|
+
* sanitize returns. This walks a removed subtree and strips every attribute
|
|
1596
|
+
* the active configuration does not allow — so `on*` handlers are cancelled
|
|
1597
|
+
* through the SAME allowlist that governs kept nodes, not a separate `/^on/`
|
|
1598
|
+
* blocklist. Run synchronously before sanitize returns, i.e. before any
|
|
1599
|
+
* queued event can fire. Hook-free by design: these nodes leave the output,
|
|
1600
|
+
* so firing attribute hooks for them would be surprising. Clobber-safe reads;
|
|
1601
|
+
* a doomed clobbered node may shadow `removeAttribute` (its own attributes are
|
|
1602
|
+
* irrelevant — it is discarded — while its non-clobbered descendants, e.g.
|
|
1603
|
+
* the `<img>`, are reached and scrubbed).
|
|
1604
|
+
*
|
|
1605
|
+
* @param root the root of a removed subtree to neutralise
|
|
1606
|
+
*/
|
|
1607
|
+
const _neutralizeSubtree = function _neutralizeSubtree(root) {
|
|
1608
|
+
const stack = [root];
|
|
1609
|
+
while (stack.length > 0) {
|
|
1610
|
+
const node = stack.pop();
|
|
1611
|
+
if ((getNodeType ? getNodeType(node) : node.nodeType) === NODE_TYPE.element) _stripDisallowedAttributes(node);
|
|
1612
|
+
const childNodes = getChildNodes(node);
|
|
1613
|
+
if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
/**
|
|
1617
|
+
* _neutralizePatchLinkage
|
|
1618
|
+
*
|
|
1619
|
+
* IN_PLACE entry pre-pass (declarative-partial-updates / streaming
|
|
1620
|
+
* hardening, https://github.com/WICG/declarative-partial-updates).
|
|
1621
|
+
*
|
|
1622
|
+
* The main walk strips patch linkage (`for`/`patchsrc`) and removes range
|
|
1623
|
+
* markers (PIs / markup comments) node-by-node, in document order, AS it
|
|
1624
|
+
* reaches each node. On a live in-place root that leaves a window: from the
|
|
1625
|
+
* moment the root is connected until the walk arrives at a given node, that
|
|
1626
|
+
* node's linkage is live. A patch applied on connection/stream can fire as
|
|
1627
|
+
* a microtask during the walk and inject or teleport an unsanitized DOM
|
|
1628
|
+
* range into a region the iterator has already passed and will not revisit,
|
|
1629
|
+
* so the post-return "tree is sanitized" contract is violated. Sweep the
|
|
1630
|
+
* whole tree once up front and sever every linkage before the walk begins,
|
|
1631
|
+
* closing that window.
|
|
1632
|
+
*
|
|
1633
|
+
* This CANNOT undo a patch that already fired before sanitize ran — that is
|
|
1634
|
+
* the irreducible "do not IN_PLACE a live-connected attacker tree" caveat —
|
|
1635
|
+
* but it closes everything from sanitize-start onward. Gated on SAFE_FOR_XML
|
|
1636
|
+
* to group with the rest of the declarative-partial-updates handling and
|
|
1637
|
+
* stay overridable, consistent with the codebase.
|
|
1638
|
+
*
|
|
1639
|
+
* Clobber-safe traversal (cached childNodes getter); per-node try/catch so a
|
|
1640
|
+
* clobbered root cannot defeat the sweep of its non-clobbered descendants.
|
|
1641
|
+
*
|
|
1642
|
+
* NOTE (pending real-Chrome confirmation, see test/declarative-patch-probe
|
|
1643
|
+
* .html Q1): this mirrors the existing policy of keeping `for` on
|
|
1644
|
+
* <label>/<output>. If the shipping feature can drive a patch through a
|
|
1645
|
+
* surviving `for`-on-label/output + `id` pair, this pre-pass and the
|
|
1646
|
+
* attribute check at _isBasicCustomElement's caller must additionally drop
|
|
1647
|
+
* that pair on the IN_PLACE path. Left as-is until the taxonomy is verified.
|
|
1648
|
+
*
|
|
1649
|
+
* @param root the in-place root to sweep
|
|
1650
|
+
*/
|
|
1651
|
+
const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
|
|
1652
|
+
if (!SAFE_FOR_XML) return;
|
|
1653
|
+
const stack = [root];
|
|
1654
|
+
while (stack.length > 0) {
|
|
1655
|
+
const node = stack.pop();
|
|
1656
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
1657
|
+
if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
|
|
1658
|
+
try {
|
|
1659
|
+
remove(node);
|
|
1660
|
+
} catch (_) {}
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
if (nodeType === NODE_TYPE.element) {
|
|
1664
|
+
const element = node;
|
|
1665
|
+
const lcTag = transformCaseFunc(getNodeName ? getNodeName(node) : node.nodeName);
|
|
1666
|
+
try {
|
|
1667
|
+
if (element.hasAttribute && element.hasAttribute("patchsrc")) element.removeAttribute("patchsrc");
|
|
1668
|
+
if (element.hasAttribute && element.hasAttribute("for") && lcTag !== "label" && lcTag !== "output") element.removeAttribute("for");
|
|
1669
|
+
} catch (_) {}
|
|
1670
|
+
}
|
|
1671
|
+
const childNodes = getChildNodes(node);
|
|
1672
|
+
if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
/**
|
|
1676
|
+
* _initDocument
|
|
1677
|
+
*
|
|
1678
|
+
* @param dirty - a string of dirty markup
|
|
1679
|
+
* @return a DOM, filled with the dirty markup
|
|
1680
|
+
*/
|
|
1681
|
+
const _initDocument = function _initDocument(dirty) {
|
|
1682
|
+
let doc = null;
|
|
1683
|
+
let leadingWhitespace = null;
|
|
1684
|
+
if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
|
|
1685
|
+
else {
|
|
1686
|
+
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
|
1687
|
+
leadingWhitespace = matches && matches[0];
|
|
1688
|
+
}
|
|
1689
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) dirty = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body>" + dirty + "</body></html>";
|
|
1690
|
+
const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
|
|
1691
|
+
if (NAMESPACE === HTML_NAMESPACE) try {
|
|
1692
|
+
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
1693
|
+
} catch (_) {}
|
|
1694
|
+
if (!doc || !doc.documentElement) {
|
|
1695
|
+
doc = implementation.createDocument(NAMESPACE, "template", null);
|
|
1696
|
+
try {
|
|
1697
|
+
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
1698
|
+
} catch (_) {}
|
|
1699
|
+
}
|
|
1700
|
+
const body = doc.body || doc.documentElement;
|
|
1701
|
+
if (dirty && leadingWhitespace) body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
1702
|
+
if (NAMESPACE === HTML_NAMESPACE) return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
|
1703
|
+
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
1704
|
+
};
|
|
1705
|
+
/**
|
|
1706
|
+
* Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
|
|
1707
|
+
*
|
|
1708
|
+
* @param root The root element or node to start traversing on.
|
|
1709
|
+
* @return The created NodeIterator
|
|
1710
|
+
*/
|
|
1711
|
+
const _createNodeIterator = function _createNodeIterator(root) {
|
|
1712
|
+
return createNodeIterator.call(root.ownerDocument || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
1713
|
+
};
|
|
1714
|
+
/**
|
|
1715
|
+
* Replace template expression syntax (mustache, ERB, template
|
|
1716
|
+
* literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
|
|
1717
|
+
* sites. Order matters: mustache, then ERB, then template literal.
|
|
1718
|
+
*
|
|
1719
|
+
* @param value the string to scrub
|
|
1720
|
+
* @returns the scrubbed string
|
|
1721
|
+
*/
|
|
1722
|
+
const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
|
|
1723
|
+
value = stringReplace(value, MUSTACHE_EXPR$1, " ");
|
|
1724
|
+
value = stringReplace(value, ERB_EXPR$1, " ");
|
|
1725
|
+
value = stringReplace(value, TMPLIT_EXPR$1, " ");
|
|
1726
|
+
return value;
|
|
1727
|
+
};
|
|
1728
|
+
/**
|
|
1729
|
+
* Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
|
|
1730
|
+
* character data of an element subtree. Used as the final safety net for
|
|
1731
|
+
* SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
|
|
1732
|
+
* which only form after text-node normalization (e.g. fragments split across
|
|
1733
|
+
* stripped elements) cannot survive into a template-evaluating framework.
|
|
1734
|
+
*
|
|
1735
|
+
* Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
|
|
1736
|
+
* in place rather than round-tripping through innerHTML. This preserves
|
|
1737
|
+
* descendant node references (important for IN_PLACE callers), avoids a
|
|
1738
|
+
* serialize/reparse cycle, and reads literal character data — which means
|
|
1739
|
+
* `<%...%>` in text content matches the ERB regex against its real bytes
|
|
1740
|
+
* instead of the HTML-entity-escaped form innerHTML would produce.
|
|
1741
|
+
*
|
|
1742
|
+
* Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
|
|
1743
|
+
* attributes is performed during the per-node `_sanitizeAttributes` pass.
|
|
1744
|
+
*
|
|
1745
|
+
* @param node The root element whose character data should be scrubbed.
|
|
1746
|
+
*/
|
|
1747
|
+
const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
|
|
1748
|
+
var _node$querySelectorAl;
|
|
1749
|
+
node.normalize();
|
|
1750
|
+
const walker = createNodeIterator.call(node.ownerDocument || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
|
|
1751
|
+
let currentNode = walker.nextNode();
|
|
1752
|
+
while (currentNode) {
|
|
1753
|
+
currentNode.data = _stripTemplateExpressions(currentNode.data);
|
|
1754
|
+
currentNode = walker.nextNode();
|
|
1755
|
+
}
|
|
1756
|
+
const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, "template");
|
|
1757
|
+
if (templates) arrayForEach(templates, (tmpl) => {
|
|
1758
|
+
if (_isDocumentFragment(tmpl.content)) _scrubTemplateExpressions2(tmpl.content);
|
|
1759
|
+
});
|
|
1760
|
+
};
|
|
1761
|
+
/**
|
|
1762
|
+
* _isClobbered
|
|
1763
|
+
*
|
|
1764
|
+
* Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
|
|
1765
|
+
* interface with [LegacyOverrideBuiltIns]; a descendant element with a
|
|
1766
|
+
* `name` attribute matching a prototype property shadows that property
|
|
1767
|
+
* on direct reads. We use this check at the IN_PLACE entry-point and
|
|
1768
|
+
* during attribute sanitization to refuse clobbered forms.
|
|
1769
|
+
*
|
|
1770
|
+
* @param element element to check for clobbering attacks
|
|
1771
|
+
* @return true if clobbered, false if safe
|
|
1772
|
+
*/
|
|
1773
|
+
const _isClobbered = function _isClobbered(element) {
|
|
1774
|
+
const realTagName = getNodeName ? getNodeName(element) : null;
|
|
1775
|
+
if (typeof realTagName !== "string") return false;
|
|
1776
|
+
if (transformCaseFunc(realTagName) !== "form") return false;
|
|
1777
|
+
return typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || element.attributes !== getAttributes(element) || typeof element.removeAttribute !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function" || element.nodeType !== getNodeType(element) || element.childNodes !== getChildNodes(element);
|
|
1778
|
+
};
|
|
1779
|
+
/**
|
|
1780
|
+
* Checks whether the given value is a DocumentFragment from any realm.
|
|
1781
|
+
*
|
|
1782
|
+
* The realm-independent replacement reads `nodeType` through the cached
|
|
1783
|
+
* Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
|
|
1784
|
+
* constant (11). nodeType is a numeric value resolved from the node's
|
|
1785
|
+
* internal slot, identical across realms for the same kind of node.
|
|
1786
|
+
*
|
|
1787
|
+
* @param value object to check
|
|
1788
|
+
* @return true if value is a DocumentFragment-shaped node from any realm
|
|
1789
|
+
*/
|
|
1790
|
+
const _isDocumentFragment = function _isDocumentFragment(value) {
|
|
1791
|
+
if (!getNodeType || typeof value !== "object" || value === null) return false;
|
|
1792
|
+
try {
|
|
1793
|
+
return getNodeType(value) === NODE_TYPE.documentFragment;
|
|
1794
|
+
} catch (_) {
|
|
1795
|
+
return false;
|
|
1796
|
+
}
|
|
1797
|
+
};
|
|
1798
|
+
/**
|
|
1799
|
+
* Checks whether the given object is a DOM node, including nodes that
|
|
1800
|
+
* originate from a different window/realm (e.g. an iframe's
|
|
1801
|
+
* contentDocument). The previous `value instanceof Node` check was
|
|
1802
|
+
* realm-bound: nodes from a different window failed it, causing
|
|
1803
|
+
* sanitize() to silently stringify them and reset IN_PLACE to false,
|
|
1804
|
+
* returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
|
|
1805
|
+
*
|
|
1806
|
+
* @param value object to check whether it's a DOM node
|
|
1807
|
+
* @return true if value is a DOM node from any realm
|
|
1808
|
+
*/
|
|
1809
|
+
const _isNode = function _isNode(value) {
|
|
1810
|
+
if (!getNodeType || typeof value !== "object" || value === null) return false;
|
|
1811
|
+
try {
|
|
1812
|
+
return typeof getNodeType(value) === "number";
|
|
1813
|
+
} catch (_) {
|
|
1814
|
+
return false;
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
function _executeHooks(hooks, currentNode, data) {
|
|
1818
|
+
if (hooks.length === 0) return;
|
|
1819
|
+
arrayForEach(hooks, (hook) => {
|
|
1820
|
+
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
/**
|
|
1824
|
+
* Structural-threat checks that condemn a node regardless of the
|
|
1825
|
+
* allowlists: mXSS via namespace confusion, risky CSS construction,
|
|
1826
|
+
* processing instructions, markup-bearing comments. Pure predicate;
|
|
1827
|
+
* the caller removes. Check order is load-bearing.
|
|
1828
|
+
*
|
|
1829
|
+
* @param currentNode the node to inspect
|
|
1830
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
1831
|
+
* @return true if the node must be removed
|
|
1832
|
+
*/
|
|
1833
|
+
const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
|
|
1834
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
|
|
1835
|
+
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === "style" && _isNode(currentNode.firstElementChild)) return true;
|
|
1836
|
+
if (currentNode.nodeType === NODE_TYPE.processingInstruction) return true;
|
|
1837
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
|
|
1838
|
+
return false;
|
|
1839
|
+
};
|
|
1840
|
+
/**
|
|
1841
|
+
* Handle a node whose tag is forbidden or not allowlisted: keep
|
|
1842
|
+
* allowed custom elements (false return exits _sanitizeElements
|
|
1843
|
+
* early - the namespace and fallback-tag removal checks are
|
|
1844
|
+
* intentionally skipped for kept custom elements), else hoist
|
|
1845
|
+
* content per KEEP_CONTENT and remove.
|
|
1846
|
+
*
|
|
1847
|
+
* A kept custom element is the ONLY case in which this function
|
|
1848
|
+
* returns false, so the caller uses that return value to run the
|
|
1849
|
+
* afterSanitizeElements hook on the kept element and keep the
|
|
1850
|
+
* element-hook lifecycle consistent with normal allowlisted
|
|
1851
|
+
* elements (GHSA-c2j3-45gr-mqc4).
|
|
1852
|
+
*
|
|
1853
|
+
* @param currentNode the disallowed node
|
|
1854
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
1855
|
+
* @return true if the node was removed, false if kept
|
|
1856
|
+
*/
|
|
1857
|
+
const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
|
|
1858
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
1859
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
|
|
1860
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
|
|
1861
|
+
}
|
|
1862
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
1863
|
+
const parentNode = getParentNode(currentNode);
|
|
1864
|
+
const childNodes = getChildNodes(currentNode);
|
|
1865
|
+
if (childNodes && parentNode) {
|
|
1866
|
+
const childCount = childNodes.length;
|
|
1867
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
1868
|
+
const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
|
|
1869
|
+
parentNode.insertBefore(hoisted, getNextSibling(currentNode));
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
_forceRemove(currentNode);
|
|
1874
|
+
return true;
|
|
1875
|
+
};
|
|
1876
|
+
/**
|
|
1877
|
+
* _sanitizeElements
|
|
1878
|
+
*
|
|
1879
|
+
* @protect nodeName
|
|
1880
|
+
* @protect textContent
|
|
1881
|
+
* @protect removeChild
|
|
1882
|
+
* @param currentNode to check for permission to exist
|
|
1883
|
+
* @return true if node was killed, false if left alive
|
|
1884
|
+
*/
|
|
1885
|
+
const _sanitizeElements = function _sanitizeElements(currentNode, root) {
|
|
1886
|
+
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
1887
|
+
if (currentNode !== root && getParentNode(currentNode) === null) return true;
|
|
1888
|
+
if (_isClobbered(currentNode)) {
|
|
1889
|
+
_forceRemove(currentNode);
|
|
1890
|
+
return true;
|
|
1891
|
+
}
|
|
1892
|
+
const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
|
|
1893
|
+
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
1894
|
+
tagName,
|
|
1895
|
+
allowedTags: ALLOWED_TAGS
|
|
1896
|
+
});
|
|
1897
|
+
if (currentNode !== root && getParentNode(currentNode) === null) return true;
|
|
1898
|
+
if (_isUnsafeNode(currentNode, tagName)) {
|
|
1899
|
+
_forceRemove(currentNode);
|
|
1900
|
+
return true;
|
|
1901
|
+
}
|
|
1902
|
+
if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
|
|
1903
|
+
const removed = _sanitizeDisallowedNode(currentNode, tagName);
|
|
1904
|
+
if (removed === false) _executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
1905
|
+
return removed;
|
|
1906
|
+
}
|
|
1907
|
+
if ((getNodeType ? getNodeType(currentNode) : currentNode.nodeType) === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
|
|
1908
|
+
_forceRemove(currentNode);
|
|
1909
|
+
return true;
|
|
1910
|
+
}
|
|
1911
|
+
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
|
|
1912
|
+
_forceRemove(currentNode);
|
|
1913
|
+
return true;
|
|
1914
|
+
}
|
|
1915
|
+
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
1916
|
+
const content = _stripTemplateExpressions(currentNode.textContent);
|
|
1917
|
+
if (currentNode.textContent !== content) {
|
|
1918
|
+
arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
|
|
1919
|
+
currentNode.textContent = content;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
_executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
1923
|
+
return false;
|
|
1924
|
+
};
|
|
1925
|
+
/**
|
|
1926
|
+
* _isValidAttribute
|
|
1927
|
+
*
|
|
1928
|
+
* @param lcTag Lowercase tag name of containing element.
|
|
1929
|
+
* @param lcName Lowercase attribute name.
|
|
1930
|
+
* @param value Attribute value.
|
|
1931
|
+
* @return Returns true if `value` is valid, otherwise false.
|
|
1932
|
+
*/
|
|
1933
|
+
const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
|
|
1934
|
+
if (FORBID_ATTR[lcName]) return false;
|
|
1935
|
+
if (SAFE_FOR_XML && lcName === "patchsrc") return false;
|
|
1936
|
+
if (SAFE_FOR_XML && lcName === "for" && lcTag !== "label" && lcTag !== "output") return false;
|
|
1937
|
+
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document || value in formElement)) return false;
|
|
1938
|
+
const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
|
|
1939
|
+
if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName));
|
|
1940
|
+
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName));
|
|
1941
|
+
else if (!nameIsPermitted) if (_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) || lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value)));
|
|
1942
|
+
else return false;
|
|
1943
|
+
else if (URI_SAFE_ATTRIBUTES[lcName]);
|
|
1944
|
+
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, "")));
|
|
1945
|
+
else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]);
|
|
1946
|
+
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, "")));
|
|
1947
|
+
else if (value) return false;
|
|
1948
|
+
return true;
|
|
1949
|
+
};
|
|
1950
|
+
const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
|
|
1951
|
+
"annotation-xml",
|
|
1952
|
+
"color-profile",
|
|
1953
|
+
"font-face",
|
|
1954
|
+
"font-face-format",
|
|
1955
|
+
"font-face-name",
|
|
1956
|
+
"font-face-src",
|
|
1957
|
+
"font-face-uri",
|
|
1958
|
+
"missing-glyph"
|
|
1959
|
+
]);
|
|
1960
|
+
/**
|
|
1961
|
+
* _isBasicCustomElement
|
|
1962
|
+
* checks if at least one dash is included in tagName, and it's not the first char
|
|
1963
|
+
* for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
|
|
1964
|
+
*
|
|
1965
|
+
* @param tagName name of the tag of the node to sanitize
|
|
1966
|
+
* @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
|
|
1967
|
+
*/
|
|
1968
|
+
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
|
|
1969
|
+
return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
|
|
1970
|
+
};
|
|
1971
|
+
/**
|
|
1972
|
+
* Wrap an attribute value in the matching Trusted Types object when
|
|
1973
|
+
* the active policy requires it. Namespaced attributes pass through
|
|
1974
|
+
* unchanged (no TT support yet, see
|
|
1975
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
|
|
1976
|
+
*
|
|
1977
|
+
* @param lcTag lowercase tag name of the containing element
|
|
1978
|
+
* @param lcName lowercase attribute name
|
|
1979
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
1980
|
+
* @param value the attribute value to wrap
|
|
1981
|
+
* @return the value, wrapped when Trusted Types demand it
|
|
1982
|
+
*/
|
|
1983
|
+
const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
|
|
1984
|
+
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function" && !namespaceURI) switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
1985
|
+
case "TrustedHTML": return _createTrustedHTML(value);
|
|
1986
|
+
case "TrustedScriptURL": return _createTrustedScriptURL(value);
|
|
1987
|
+
}
|
|
1988
|
+
return value;
|
|
1989
|
+
};
|
|
1990
|
+
/**
|
|
1991
|
+
* Write a modified attribute value back onto the element. On
|
|
1992
|
+
* success, re-probe for clobbering introduced by the new value and
|
|
1993
|
+
* remove the element when found; otherwise pop the removal entry
|
|
1994
|
+
* recorded by the earlier _removeAttribute (long-standing pairing
|
|
1995
|
+
* with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
|
|
1996
|
+
* failure, remove the attribute instead.
|
|
1997
|
+
*
|
|
1998
|
+
* @param currentNode the element carrying the attribute
|
|
1999
|
+
* @param name the attribute name as present on the element
|
|
2000
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
2001
|
+
* @param value the new attribute value
|
|
2002
|
+
*/
|
|
2003
|
+
const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
|
|
2004
|
+
try {
|
|
2005
|
+
if (namespaceURI) currentNode.setAttributeNS(namespaceURI, name, value);
|
|
2006
|
+
else currentNode.setAttribute(name, value);
|
|
2007
|
+
if (_isClobbered(currentNode)) _forceRemove(currentNode);
|
|
2008
|
+
else arrayPop(DOMPurify.removed);
|
|
2009
|
+
} catch (_) {
|
|
2010
|
+
_removeAttribute(name, currentNode);
|
|
2011
|
+
}
|
|
2012
|
+
};
|
|
2013
|
+
/**
|
|
2014
|
+
* _sanitizeAttributes
|
|
2015
|
+
*
|
|
2016
|
+
* @protect attributes
|
|
2017
|
+
* @protect nodeName
|
|
2018
|
+
* @protect removeAttribute
|
|
2019
|
+
* @protect setAttribute
|
|
2020
|
+
*
|
|
2021
|
+
* @param currentNode to sanitize
|
|
2022
|
+
*/
|
|
2023
|
+
const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
|
2024
|
+
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
2025
|
+
const attributes = currentNode.attributes;
|
|
2026
|
+
if (!attributes || _isClobbered(currentNode)) return;
|
|
2027
|
+
const hookEvent = {
|
|
2028
|
+
attrName: "",
|
|
2029
|
+
attrValue: "",
|
|
2030
|
+
keepAttr: true,
|
|
2031
|
+
allowedAttributes: ALLOWED_ATTR,
|
|
2032
|
+
forceKeepAttr: void 0
|
|
2033
|
+
};
|
|
2034
|
+
let l = attributes.length;
|
|
2035
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
2036
|
+
while (l--) {
|
|
2037
|
+
const attr = attributes[l];
|
|
2038
|
+
const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
|
|
2039
|
+
const lcName = transformCaseFunc(name);
|
|
2040
|
+
const initValue = attrValue;
|
|
2041
|
+
let value = name === "value" ? initValue : stringTrim(initValue);
|
|
2042
|
+
hookEvent.attrName = lcName;
|
|
2043
|
+
hookEvent.attrValue = value;
|
|
2044
|
+
hookEvent.keepAttr = true;
|
|
2045
|
+
hookEvent.forceKeepAttr = void 0;
|
|
2046
|
+
_executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
|
|
2047
|
+
value = hookEvent.attrValue;
|
|
2048
|
+
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name") && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
|
|
2049
|
+
_removeAttribute(name, currentNode);
|
|
2050
|
+
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
2051
|
+
}
|
|
2052
|
+
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
|
|
2053
|
+
_removeAttribute(name, currentNode);
|
|
2054
|
+
continue;
|
|
2055
|
+
}
|
|
2056
|
+
if (lcName === "attributename" && stringMatch(value, "href")) {
|
|
2057
|
+
_removeAttribute(name, currentNode);
|
|
2058
|
+
continue;
|
|
2059
|
+
}
|
|
2060
|
+
if (hookEvent.forceKeepAttr) continue;
|
|
2061
|
+
if (!hookEvent.keepAttr) {
|
|
2062
|
+
_removeAttribute(name, currentNode);
|
|
2063
|
+
continue;
|
|
2064
|
+
}
|
|
2065
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
|
|
2066
|
+
_removeAttribute(name, currentNode);
|
|
2067
|
+
continue;
|
|
2068
|
+
}
|
|
2069
|
+
if (SAFE_FOR_TEMPLATES) value = _stripTemplateExpressions(value);
|
|
2070
|
+
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
2071
|
+
_removeAttribute(name, currentNode);
|
|
2072
|
+
continue;
|
|
2073
|
+
}
|
|
2074
|
+
value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
|
|
2075
|
+
if (value !== initValue) _setAttributeValue(currentNode, name, namespaceURI, value);
|
|
2076
|
+
}
|
|
2077
|
+
_executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
|
|
2078
|
+
};
|
|
2079
|
+
/**
|
|
2080
|
+
* _sanitizeShadowDOM
|
|
2081
|
+
*
|
|
2082
|
+
* @param fragment to iterate over recursively
|
|
2083
|
+
*/
|
|
2084
|
+
const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
|
|
2085
|
+
let shadowNode = null;
|
|
2086
|
+
const shadowIterator = _createNodeIterator(fragment);
|
|
2087
|
+
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
2088
|
+
while (shadowNode = shadowIterator.nextNode()) {
|
|
2089
|
+
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
2090
|
+
_sanitizeElements(shadowNode, fragment);
|
|
2091
|
+
_sanitizeAttributes(shadowNode);
|
|
2092
|
+
if (_isDocumentFragment(shadowNode.content)) _sanitizeShadowDOM2(shadowNode.content);
|
|
2093
|
+
if ((getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType) === NODE_TYPE.element) {
|
|
2094
|
+
const innerSr = getShadowRoot(shadowNode);
|
|
2095
|
+
if (_isDocumentFragment(innerSr)) {
|
|
2096
|
+
_sanitizeAttachedShadowRoots(innerSr);
|
|
2097
|
+
_sanitizeShadowDOM2(innerSr);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
2102
|
+
};
|
|
2103
|
+
/**
|
|
2104
|
+
* _sanitizeAttachedShadowRoots
|
|
2105
|
+
*
|
|
2106
|
+
* Walks `root` and feeds every attached shadow root we encounter into
|
|
2107
|
+
* the existing _sanitizeShadowDOM pipeline. The default node iterator
|
|
2108
|
+
* does not descend into shadow trees, so nodes inside an attached
|
|
2109
|
+
* shadow root would otherwise be skipped entirely.
|
|
2110
|
+
*
|
|
2111
|
+
* Two real input paths put attached shadow roots in front of us:
|
|
2112
|
+
* 1. IN_PLACE on a DOM node that already has shadow roots attached.
|
|
2113
|
+
* 2. DOM-node input where importNode(dirty, true) deep-clones the
|
|
2114
|
+
* shadow root because it was created with `clonable: true`.
|
|
2115
|
+
*
|
|
2116
|
+
* This pass runs once, up front, so the main iteration loop (and the
|
|
2117
|
+
* existing _sanitizeShadowDOM template-content recursion) stay
|
|
2118
|
+
* untouched — string-input paths are not affected.
|
|
2119
|
+
*
|
|
2120
|
+
* @param root the subtree root to walk for attached shadow roots
|
|
2121
|
+
*/
|
|
2122
|
+
const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
|
|
2123
|
+
const stack = [{
|
|
2124
|
+
node: root,
|
|
2125
|
+
shadow: null
|
|
2126
|
+
}];
|
|
2127
|
+
while (stack.length > 0) {
|
|
2128
|
+
const item = stack.pop();
|
|
2129
|
+
if (item.shadow) {
|
|
2130
|
+
_sanitizeShadowDOM2(item.shadow);
|
|
2131
|
+
continue;
|
|
2132
|
+
}
|
|
2133
|
+
const node = item.node;
|
|
2134
|
+
const isElement = (getNodeType ? getNodeType(node) : node.nodeType) === NODE_TYPE.element;
|
|
2135
|
+
const childNodes = getChildNodes(node);
|
|
2136
|
+
if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push({
|
|
2137
|
+
node: childNodes[i],
|
|
2138
|
+
shadow: null
|
|
2139
|
+
});
|
|
2140
|
+
if (isElement) {
|
|
2141
|
+
const rootName = getNodeName ? getNodeName(node) : null;
|
|
2142
|
+
if (typeof rootName === "string" && transformCaseFunc(rootName) === "template") {
|
|
2143
|
+
const content = node.content;
|
|
2144
|
+
if (_isDocumentFragment(content)) stack.push({
|
|
2145
|
+
node: content,
|
|
2146
|
+
shadow: null
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
if (isElement) {
|
|
2151
|
+
const sr = getShadowRoot(node);
|
|
2152
|
+
if (_isDocumentFragment(sr)) stack.push({
|
|
2153
|
+
node: null,
|
|
2154
|
+
shadow: sr
|
|
2155
|
+
}, {
|
|
2156
|
+
node: sr,
|
|
2157
|
+
shadow: null
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
};
|
|
2162
|
+
DOMPurify.sanitize = function(dirty) {
|
|
2163
|
+
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2164
|
+
let body = null;
|
|
2165
|
+
let importedNode = null;
|
|
2166
|
+
let currentNode = null;
|
|
2167
|
+
let returnNode = null;
|
|
2168
|
+
IS_EMPTY_INPUT = !dirty;
|
|
2169
|
+
if (IS_EMPTY_INPUT) dirty = "<!-->";
|
|
2170
|
+
if (typeof dirty !== "string" && !_isNode(dirty)) {
|
|
2171
|
+
dirty = stringifyValue(dirty);
|
|
2172
|
+
if (typeof dirty !== "string") throw typeErrorCreate("dirty is not a string, aborting");
|
|
2173
|
+
}
|
|
2174
|
+
if (!DOMPurify.isSupported) return dirty;
|
|
2175
|
+
if (SET_CONFIG) {
|
|
2176
|
+
ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
|
|
2177
|
+
ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
|
|
2178
|
+
} else _parseConfig(cfg);
|
|
2179
|
+
if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
2180
|
+
if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
2181
|
+
DOMPurify.removed = [];
|
|
2182
|
+
const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
|
|
2183
|
+
if (inPlace) {
|
|
2184
|
+
_neutralizePatchLinkage(dirty);
|
|
2185
|
+
const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
|
|
2186
|
+
if (typeof nn === "string") {
|
|
2187
|
+
const tagName = transformCaseFunc(nn);
|
|
2188
|
+
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
2189
|
+
_neutralizeRoot(dirty);
|
|
2190
|
+
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
if (_isClobbered(dirty)) {
|
|
2194
|
+
_neutralizeRoot(dirty);
|
|
2195
|
+
throw typeErrorCreate("root node is clobbered and cannot be sanitized in-place");
|
|
2196
|
+
}
|
|
2197
|
+
try {
|
|
2198
|
+
_sanitizeAttachedShadowRoots(dirty);
|
|
2199
|
+
} catch (error) {
|
|
2200
|
+
_neutralizeRoot(dirty);
|
|
2201
|
+
throw error;
|
|
2202
|
+
}
|
|
2203
|
+
} else if (_isNode(dirty)) {
|
|
2204
|
+
body = _initDocument("<!---->");
|
|
2205
|
+
importedNode = body.ownerDocument.importNode(dirty, true);
|
|
2206
|
+
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") body = importedNode;
|
|
2207
|
+
else if (importedNode.nodeName === "HTML") body = importedNode;
|
|
2208
|
+
else body.appendChild(importedNode);
|
|
2209
|
+
_sanitizeAttachedShadowRoots(importedNode);
|
|
2210
|
+
} else {
|
|
2211
|
+
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
|
|
2212
|
+
body = _initDocument(dirty);
|
|
2213
|
+
if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
|
2214
|
+
}
|
|
2215
|
+
if (body && FORCE_BODY) _forceRemove(body.firstChild);
|
|
2216
|
+
const walkRoot = inPlace ? dirty : body;
|
|
2217
|
+
const nodeIterator = _createNodeIterator(walkRoot);
|
|
2218
|
+
try {
|
|
2219
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
2220
|
+
_sanitizeElements(currentNode, walkRoot);
|
|
2221
|
+
_sanitizeAttributes(currentNode);
|
|
2222
|
+
if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
|
|
2223
|
+
}
|
|
2224
|
+
} catch (error) {
|
|
2225
|
+
if (inPlace) {
|
|
2226
|
+
_neutralizeRoot(dirty);
|
|
2227
|
+
arrayForEach(DOMPurify.removed, (entry) => {
|
|
2228
|
+
if (entry.element) _neutralizeSubtree(entry.element);
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
throw error;
|
|
2232
|
+
}
|
|
2233
|
+
if (inPlace) {
|
|
2234
|
+
arrayForEach(DOMPurify.removed, (entry) => {
|
|
2235
|
+
if (entry.element) _neutralizeSubtree(entry.element);
|
|
2236
|
+
});
|
|
2237
|
+
if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(dirty);
|
|
2238
|
+
return dirty;
|
|
2239
|
+
}
|
|
2240
|
+
if (RETURN_DOM) {
|
|
2241
|
+
if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(body);
|
|
2242
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
2243
|
+
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
2244
|
+
while (body.firstChild) returnNode.appendChild(body.firstChild);
|
|
2245
|
+
} else returnNode = body;
|
|
2246
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
|
|
2247
|
+
return returnNode;
|
|
2248
|
+
}
|
|
2249
|
+
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
2250
|
+
if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
|
2251
|
+
if (SAFE_FOR_TEMPLATES) serializedHTML = _stripTemplateExpressions(serializedHTML);
|
|
2252
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
|
|
2253
|
+
};
|
|
2254
|
+
DOMPurify.setConfig = function() {
|
|
2255
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2256
|
+
_parseConfig(cfg);
|
|
2257
|
+
SET_CONFIG = true;
|
|
2258
|
+
SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
|
|
2259
|
+
SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
|
|
2260
|
+
};
|
|
2261
|
+
DOMPurify.clearConfig = function() {
|
|
2262
|
+
CONFIG = null;
|
|
2263
|
+
SET_CONFIG = false;
|
|
2264
|
+
SET_CONFIG_ALLOWED_TAGS = null;
|
|
2265
|
+
SET_CONFIG_ALLOWED_ATTR = null;
|
|
2266
|
+
trustedTypesPolicy = defaultTrustedTypesPolicy;
|
|
2267
|
+
emptyHTML = "";
|
|
2268
|
+
};
|
|
2269
|
+
DOMPurify.isValidAttribute = function(tag, attr, value) {
|
|
2270
|
+
if (!CONFIG) _parseConfig({});
|
|
2271
|
+
const lcTag = transformCaseFunc(tag);
|
|
2272
|
+
const lcName = transformCaseFunc(attr);
|
|
2273
|
+
return _isValidAttribute(lcTag, lcName, value);
|
|
2274
|
+
};
|
|
2275
|
+
DOMPurify.addHook = function(entryPoint, hookFunction) {
|
|
2276
|
+
if (typeof hookFunction !== "function") return;
|
|
2277
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) return;
|
|
2278
|
+
arrayPush(hooks[entryPoint], hookFunction);
|
|
2279
|
+
};
|
|
2280
|
+
DOMPurify.removeHook = function(entryPoint, hookFunction) {
|
|
2281
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) return;
|
|
2282
|
+
if (hookFunction !== void 0) {
|
|
2283
|
+
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
2284
|
+
return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
2285
|
+
}
|
|
2286
|
+
return arrayPop(hooks[entryPoint]);
|
|
2287
|
+
};
|
|
2288
|
+
DOMPurify.removeHooks = function(entryPoint) {
|
|
2289
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) return;
|
|
2290
|
+
hooks[entryPoint] = [];
|
|
2291
|
+
};
|
|
2292
|
+
DOMPurify.removeAllHooks = function() {
|
|
2293
|
+
hooks = _createHooksMap();
|
|
2294
|
+
};
|
|
2295
|
+
return DOMPurify;
|
|
2296
|
+
}
|
|
2297
|
+
var purify = createDOMPurify();
|
|
2298
|
+
//#endregion
|
|
2299
|
+
//#region src/plugin-vue/sanitizeMarkdownHtml.ts
|
|
2300
|
+
var ALLOWED_IFRAME_SRC = /^https:\/\/www\.youtube-nocookie\.com\/embed\/[A-Za-z0-9_-]{11}$/;
|
|
2301
|
+
var hookInstalled = false;
|
|
2302
|
+
function ensureHook() {
|
|
2303
|
+
if (hookInstalled) return;
|
|
2304
|
+
hookInstalled = true;
|
|
2305
|
+
purify.addHook("uponSanitizeElement", (node, data) => {
|
|
2306
|
+
if (data.tagName !== "iframe") return;
|
|
2307
|
+
const src = node.getAttribute("src") ?? "";
|
|
2308
|
+
if (!ALLOWED_IFRAME_SRC.test(src)) node.parentNode?.removeChild(node);
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
var SANITIZE_CONFIG = {
|
|
2312
|
+
ADD_TAGS: ["iframe"],
|
|
2313
|
+
ADD_ATTR: [
|
|
2314
|
+
"allow",
|
|
2315
|
+
"allowfullscreen",
|
|
2316
|
+
"frameborder",
|
|
2317
|
+
"loading",
|
|
2318
|
+
"referrerpolicy"
|
|
2319
|
+
]
|
|
2320
|
+
};
|
|
2321
|
+
/** Sanitize HTML produced by `marked.parse`. Strips everything DOMPurify would
|
|
2322
|
+
* normally strip; additionally permits the one YouTube-embed iframe shape. */
|
|
2323
|
+
function sanitizeMarkdownHtml(html) {
|
|
2324
|
+
ensureHook();
|
|
2325
|
+
return purify.sanitize(html, SANITIZE_CONFIG);
|
|
2326
|
+
}
|
|
2327
|
+
/** Test seam — undoes the global DOMPurify hook so an isolated test can verify
|
|
2328
|
+
* the no-hook baseline. Production code never calls this. */
|
|
2329
|
+
function _resetSanitizeForTests() {
|
|
2330
|
+
purify.removeAllHooks();
|
|
2331
|
+
hookInstalled = false;
|
|
2332
|
+
}
|
|
2333
|
+
//#endregion
|
|
2334
|
+
export { _resetSanitizeForTests, buildMarkdownDocView, formatScalarField, nextFileVersion, sanitizeMarkdownHtml, useClipboardCopy, useFileVersion, useFileWatch, useMarkdownDoc };
|
|
90
2335
|
|
|
91
2336
|
//# sourceMappingURL=index.js.map
|