@threadlabs/looma 0.15.3 → 0.15.4
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/editor/chunks/extensions.js +2440 -40
- package/editor/extensions/smart-paste.d.ts +4 -4
- package/package.json +2 -1
- package/tokens.css +2 -1
- package/vue/components.css +1 -1
|
@@ -6079,66 +6079,2469 @@ function createLoomaMentionExtension(options = {}) {
|
|
|
6079
6079
|
});
|
|
6080
6080
|
}
|
|
6081
6081
|
//#endregion
|
|
6082
|
-
//#region
|
|
6083
|
-
|
|
6082
|
+
//#region ../../node_modules/.pnpm/dompurify@3.4.15/node_modules/dompurify/dist/purify.es.mjs
|
|
6083
|
+
/*! @license DOMPurify 3.4.15 | (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.15/LICENSE */
|
|
6084
|
+
function _arrayLikeToArray(r, a) {
|
|
6085
|
+
(null == a || a > r.length) && (a = r.length);
|
|
6086
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6087
|
+
return n;
|
|
6088
|
+
}
|
|
6089
|
+
function _arrayWithHoles(r) {
|
|
6090
|
+
if (Array.isArray(r)) return r;
|
|
6091
|
+
}
|
|
6092
|
+
function _iterableToArrayLimit(r, l) {
|
|
6093
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
6094
|
+
if (null != t) {
|
|
6095
|
+
var e, n, i, u, a = [], f = true, o = false;
|
|
6096
|
+
try {
|
|
6097
|
+
if (i = (t = t.call(r)).next, 0 === l);
|
|
6098
|
+
else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
6099
|
+
} catch (r) {
|
|
6100
|
+
o = true, n = r;
|
|
6101
|
+
} finally {
|
|
6102
|
+
try {
|
|
6103
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
6104
|
+
} finally {
|
|
6105
|
+
if (o) throw n;
|
|
6106
|
+
}
|
|
6107
|
+
}
|
|
6108
|
+
return a;
|
|
6109
|
+
}
|
|
6110
|
+
}
|
|
6111
|
+
function _nonIterableRest() {
|
|
6112
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
6113
|
+
}
|
|
6114
|
+
function _slicedToArray(r, e) {
|
|
6115
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
6116
|
+
}
|
|
6117
|
+
function _unsupportedIterableToArray(r, a) {
|
|
6118
|
+
if (r) {
|
|
6119
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
6120
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
6121
|
+
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;
|
|
6122
|
+
}
|
|
6123
|
+
}
|
|
6124
|
+
var entries = Object.entries;
|
|
6125
|
+
var setPrototypeOf = Object.setPrototypeOf;
|
|
6126
|
+
var isFrozen = Object.isFrozen;
|
|
6127
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
6128
|
+
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
6129
|
+
var freeze = Object.freeze;
|
|
6130
|
+
var seal = Object.seal;
|
|
6131
|
+
var create = Object.create;
|
|
6132
|
+
var _ref = typeof Reflect !== "undefined" && Reflect;
|
|
6133
|
+
var apply = _ref.apply;
|
|
6134
|
+
var construct = _ref.construct;
|
|
6135
|
+
if (!freeze) freeze = function freeze(x) {
|
|
6136
|
+
return x;
|
|
6137
|
+
};
|
|
6138
|
+
if (!seal) seal = function seal(x) {
|
|
6139
|
+
return x;
|
|
6140
|
+
};
|
|
6141
|
+
if (!apply) apply = function apply(func, thisArg) {
|
|
6142
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
|
|
6143
|
+
return func.apply(thisArg, args);
|
|
6144
|
+
};
|
|
6145
|
+
if (!construct) construct = function construct(Func) {
|
|
6146
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) args[_key2 - 1] = arguments[_key2];
|
|
6147
|
+
return new Func(...args);
|
|
6148
|
+
};
|
|
6149
|
+
var arrayForEach = unapply(Array.prototype.forEach);
|
|
6150
|
+
var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
|
|
6151
|
+
var arrayPop = unapply(Array.prototype.pop);
|
|
6152
|
+
var arrayPush = unapply(Array.prototype.push);
|
|
6153
|
+
var arraySplice = unapply(Array.prototype.splice);
|
|
6154
|
+
var arrayIsArray = Array.isArray;
|
|
6155
|
+
var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
6156
|
+
var stringToString = unapply(String.prototype.toString);
|
|
6157
|
+
var stringMatch = unapply(String.prototype.match);
|
|
6158
|
+
var stringReplace = unapply(String.prototype.replace);
|
|
6159
|
+
var stringIndexOf = unapply(String.prototype.indexOf);
|
|
6160
|
+
var stringTrim = unapply(String.prototype.trim);
|
|
6161
|
+
var numberToString = unapply(Number.prototype.toString);
|
|
6162
|
+
var booleanToString = unapply(Boolean.prototype.toString);
|
|
6163
|
+
var bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.prototype.toString);
|
|
6164
|
+
var symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
|
|
6165
|
+
var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
6166
|
+
var objectToString = unapply(Object.prototype.toString);
|
|
6167
|
+
var regExpTest = unapply(RegExp.prototype.test);
|
|
6168
|
+
var typeErrorCreate = unconstruct(TypeError);
|
|
6169
|
+
/**
|
|
6170
|
+
* Creates a new function that calls the given function with a specified thisArg and arguments.
|
|
6171
|
+
*
|
|
6172
|
+
* @param func - The function to be wrapped and called.
|
|
6173
|
+
* @returns A new function that calls the given function with a specified thisArg and arguments.
|
|
6174
|
+
*/
|
|
6175
|
+
function unapply(func) {
|
|
6176
|
+
return function(thisArg) {
|
|
6177
|
+
if (thisArg instanceof RegExp) thisArg.lastIndex = 0;
|
|
6178
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
|
|
6179
|
+
return apply(func, thisArg, args);
|
|
6180
|
+
};
|
|
6181
|
+
}
|
|
6182
|
+
/**
|
|
6183
|
+
* Creates a new function that constructs an instance of the given constructor function with the provided arguments.
|
|
6184
|
+
*
|
|
6185
|
+
* @param func - The constructor function to be wrapped and called.
|
|
6186
|
+
* @returns A new function that constructs an instance of the given constructor function with the provided arguments.
|
|
6187
|
+
*/
|
|
6188
|
+
function unconstruct(Func) {
|
|
6189
|
+
return function() {
|
|
6190
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) args[_key4] = arguments[_key4];
|
|
6191
|
+
return construct(Func, args);
|
|
6192
|
+
};
|
|
6193
|
+
}
|
|
6194
|
+
/**
|
|
6195
|
+
* Add properties to a lookup table
|
|
6196
|
+
*
|
|
6197
|
+
* @param set - The set to which elements will be added.
|
|
6198
|
+
* @param array - The array containing elements to be added to the set.
|
|
6199
|
+
* @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
|
|
6200
|
+
* @returns The modified set with added elements.
|
|
6201
|
+
*/
|
|
6202
|
+
function addToSet(set, array) {
|
|
6203
|
+
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
|
6204
|
+
if (setPrototypeOf) setPrototypeOf(set, null);
|
|
6205
|
+
if (!arrayIsArray(array)) return set;
|
|
6206
|
+
let l = array.length;
|
|
6207
|
+
while (l--) {
|
|
6208
|
+
let element = array[l];
|
|
6209
|
+
if (typeof element === "string") {
|
|
6210
|
+
const lcElement = transformCaseFunc(element);
|
|
6211
|
+
if (lcElement !== element) {
|
|
6212
|
+
if (!isFrozen(array)) array[l] = lcElement;
|
|
6213
|
+
element = lcElement;
|
|
6214
|
+
}
|
|
6215
|
+
}
|
|
6216
|
+
set[element] = true;
|
|
6217
|
+
}
|
|
6218
|
+
return set;
|
|
6219
|
+
}
|
|
6220
|
+
/**
|
|
6221
|
+
* Clean up an array to harden against CSPP
|
|
6222
|
+
*
|
|
6223
|
+
* @param array - The array to be cleaned.
|
|
6224
|
+
* @returns The cleaned version of the array
|
|
6225
|
+
*/
|
|
6226
|
+
function cleanArray(array) {
|
|
6227
|
+
for (let index = 0; index < array.length; index++) if (!objectHasOwnProperty(array, index)) array[index] = null;
|
|
6228
|
+
return array;
|
|
6229
|
+
}
|
|
6230
|
+
/**
|
|
6231
|
+
* Shallow clone an object
|
|
6232
|
+
*
|
|
6233
|
+
* @param object - The object to be cloned.
|
|
6234
|
+
* @returns A new object that copies the original.
|
|
6235
|
+
*/
|
|
6236
|
+
function clone(object) {
|
|
6237
|
+
const newObject = create(null);
|
|
6238
|
+
for (const _ref2 of entries(object)) {
|
|
6239
|
+
var _ref3 = _slicedToArray(_ref2, 2);
|
|
6240
|
+
const property = _ref3[0];
|
|
6241
|
+
const value = _ref3[1];
|
|
6242
|
+
if (objectHasOwnProperty(object, property)) {
|
|
6243
|
+
if (arrayIsArray(value)) newObject[property] = cleanArray(value);
|
|
6244
|
+
else if (value && typeof value === "object" && value.constructor === Object) newObject[property] = clone(value);
|
|
6245
|
+
else newObject[property] = value;
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
6248
|
+
return newObject;
|
|
6249
|
+
}
|
|
6250
|
+
/**
|
|
6251
|
+
* Convert non-node values into strings without depending on direct property access.
|
|
6252
|
+
*
|
|
6253
|
+
* @param value - The value to stringify.
|
|
6254
|
+
* @returns A string representation of the provided value.
|
|
6255
|
+
*/
|
|
6256
|
+
function stringifyValue(value) {
|
|
6257
|
+
switch (typeof value) {
|
|
6258
|
+
case "string": return value;
|
|
6259
|
+
case "number": return numberToString(value);
|
|
6260
|
+
case "boolean": return booleanToString(value);
|
|
6261
|
+
case "bigint": return bigintToString ? bigintToString(value) : "0";
|
|
6262
|
+
case "symbol": return symbolToString ? symbolToString(value) : "Symbol()";
|
|
6263
|
+
case "undefined": return objectToString(value);
|
|
6264
|
+
case "function":
|
|
6265
|
+
case "object": {
|
|
6266
|
+
if (value === null) return objectToString(value);
|
|
6267
|
+
const valueAsRecord = value;
|
|
6268
|
+
const valueToString = lookupGetter(valueAsRecord, "toString");
|
|
6269
|
+
if (typeof valueToString === "function") {
|
|
6270
|
+
const stringified = valueToString(valueAsRecord);
|
|
6271
|
+
return typeof stringified === "string" ? stringified : objectToString(stringified);
|
|
6272
|
+
}
|
|
6273
|
+
return objectToString(value);
|
|
6274
|
+
}
|
|
6275
|
+
default: return objectToString(value);
|
|
6276
|
+
}
|
|
6277
|
+
}
|
|
6278
|
+
/**
|
|
6279
|
+
* This method automatically checks if the prop is function or getter and behaves accordingly.
|
|
6280
|
+
*
|
|
6281
|
+
* @param object - The object to look up the getter function in its prototype chain.
|
|
6282
|
+
* @param prop - The property name for which to find the getter function.
|
|
6283
|
+
* @returns The getter function found in the prototype chain or a fallback function.
|
|
6284
|
+
*/
|
|
6285
|
+
function lookupGetter(object, prop) {
|
|
6286
|
+
while (object !== null) {
|
|
6287
|
+
const desc = getOwnPropertyDescriptor(object, prop);
|
|
6288
|
+
if (desc) {
|
|
6289
|
+
if (desc.get) return unapply(desc.get);
|
|
6290
|
+
if (typeof desc.value === "function") return unapply(desc.value);
|
|
6291
|
+
}
|
|
6292
|
+
object = getPrototypeOf(object);
|
|
6293
|
+
}
|
|
6294
|
+
function fallbackValue() {
|
|
6295
|
+
return null;
|
|
6296
|
+
}
|
|
6297
|
+
return fallbackValue;
|
|
6298
|
+
}
|
|
6299
|
+
function isRegex(value) {
|
|
6300
|
+
try {
|
|
6301
|
+
regExpTest(value, "");
|
|
6302
|
+
return true;
|
|
6303
|
+
} catch (_unused) {
|
|
6304
|
+
return false;
|
|
6305
|
+
}
|
|
6306
|
+
}
|
|
6307
|
+
var html$1 = freeze([
|
|
6308
|
+
"a",
|
|
6309
|
+
"abbr",
|
|
6310
|
+
"acronym",
|
|
6311
|
+
"address",
|
|
6312
|
+
"area",
|
|
6313
|
+
"article",
|
|
6314
|
+
"aside",
|
|
6315
|
+
"audio",
|
|
6316
|
+
"b",
|
|
6317
|
+
"bdi",
|
|
6318
|
+
"bdo",
|
|
6319
|
+
"big",
|
|
6320
|
+
"blink",
|
|
6321
|
+
"blockquote",
|
|
6322
|
+
"body",
|
|
6323
|
+
"br",
|
|
6324
|
+
"button",
|
|
6325
|
+
"canvas",
|
|
6326
|
+
"caption",
|
|
6327
|
+
"center",
|
|
6328
|
+
"cite",
|
|
6329
|
+
"code",
|
|
6330
|
+
"col",
|
|
6331
|
+
"colgroup",
|
|
6332
|
+
"content",
|
|
6333
|
+
"data",
|
|
6334
|
+
"datalist",
|
|
6335
|
+
"dd",
|
|
6336
|
+
"decorator",
|
|
6337
|
+
"del",
|
|
6338
|
+
"details",
|
|
6339
|
+
"dfn",
|
|
6340
|
+
"dialog",
|
|
6341
|
+
"dir",
|
|
6342
|
+
"div",
|
|
6343
|
+
"dl",
|
|
6344
|
+
"dt",
|
|
6345
|
+
"element",
|
|
6346
|
+
"em",
|
|
6347
|
+
"fieldset",
|
|
6348
|
+
"figcaption",
|
|
6349
|
+
"figure",
|
|
6350
|
+
"font",
|
|
6351
|
+
"footer",
|
|
6352
|
+
"form",
|
|
6353
|
+
"h1",
|
|
6354
|
+
"h2",
|
|
6355
|
+
"h3",
|
|
6356
|
+
"h4",
|
|
6357
|
+
"h5",
|
|
6358
|
+
"h6",
|
|
6359
|
+
"head",
|
|
6360
|
+
"header",
|
|
6361
|
+
"hgroup",
|
|
6362
|
+
"hr",
|
|
6084
6363
|
"html",
|
|
6085
|
-
"
|
|
6086
|
-
"
|
|
6087
|
-
"
|
|
6364
|
+
"i",
|
|
6365
|
+
"img",
|
|
6366
|
+
"input",
|
|
6367
|
+
"ins",
|
|
6368
|
+
"kbd",
|
|
6369
|
+
"label",
|
|
6370
|
+
"legend",
|
|
6371
|
+
"li",
|
|
6372
|
+
"main",
|
|
6373
|
+
"map",
|
|
6374
|
+
"mark",
|
|
6375
|
+
"marquee",
|
|
6376
|
+
"menu",
|
|
6377
|
+
"menuitem",
|
|
6378
|
+
"meter",
|
|
6379
|
+
"nav",
|
|
6380
|
+
"nobr",
|
|
6381
|
+
"ol",
|
|
6382
|
+
"optgroup",
|
|
6383
|
+
"option",
|
|
6384
|
+
"output",
|
|
6385
|
+
"p",
|
|
6386
|
+
"picture",
|
|
6387
|
+
"pre",
|
|
6388
|
+
"progress",
|
|
6389
|
+
"q",
|
|
6390
|
+
"rp",
|
|
6391
|
+
"rt",
|
|
6392
|
+
"ruby",
|
|
6393
|
+
"s",
|
|
6394
|
+
"samp",
|
|
6395
|
+
"search",
|
|
6396
|
+
"section",
|
|
6397
|
+
"select",
|
|
6398
|
+
"shadow",
|
|
6399
|
+
"slot",
|
|
6400
|
+
"small",
|
|
6401
|
+
"source",
|
|
6402
|
+
"spacer",
|
|
6403
|
+
"span",
|
|
6404
|
+
"strike",
|
|
6405
|
+
"strong",
|
|
6406
|
+
"style",
|
|
6407
|
+
"sub",
|
|
6408
|
+
"summary",
|
|
6409
|
+
"sup",
|
|
6410
|
+
"table",
|
|
6411
|
+
"tbody",
|
|
6412
|
+
"td",
|
|
6413
|
+
"template",
|
|
6414
|
+
"textarea",
|
|
6415
|
+
"tfoot",
|
|
6416
|
+
"th",
|
|
6417
|
+
"thead",
|
|
6418
|
+
"time",
|
|
6419
|
+
"tr",
|
|
6420
|
+
"track",
|
|
6421
|
+
"tt",
|
|
6422
|
+
"u",
|
|
6423
|
+
"ul",
|
|
6424
|
+
"var",
|
|
6425
|
+
"video",
|
|
6426
|
+
"wbr"
|
|
6088
6427
|
]);
|
|
6089
|
-
var
|
|
6090
|
-
"
|
|
6091
|
-
"
|
|
6092
|
-
"
|
|
6428
|
+
var svg$1 = freeze([
|
|
6429
|
+
"svg",
|
|
6430
|
+
"a",
|
|
6431
|
+
"altglyph",
|
|
6432
|
+
"altglyphdef",
|
|
6433
|
+
"altglyphitem",
|
|
6434
|
+
"animatecolor",
|
|
6435
|
+
"animatemotion",
|
|
6436
|
+
"animatetransform",
|
|
6437
|
+
"circle",
|
|
6438
|
+
"clippath",
|
|
6439
|
+
"defs",
|
|
6440
|
+
"desc",
|
|
6441
|
+
"ellipse",
|
|
6442
|
+
"enterkeyhint",
|
|
6443
|
+
"exportparts",
|
|
6444
|
+
"filter",
|
|
6445
|
+
"font",
|
|
6446
|
+
"g",
|
|
6447
|
+
"glyph",
|
|
6448
|
+
"glyphref",
|
|
6449
|
+
"hkern",
|
|
6450
|
+
"image",
|
|
6451
|
+
"inputmode",
|
|
6452
|
+
"line",
|
|
6453
|
+
"lineargradient",
|
|
6454
|
+
"marker",
|
|
6455
|
+
"mask",
|
|
6456
|
+
"metadata",
|
|
6457
|
+
"mpath",
|
|
6458
|
+
"part",
|
|
6459
|
+
"path",
|
|
6460
|
+
"pattern",
|
|
6461
|
+
"polygon",
|
|
6462
|
+
"polyline",
|
|
6463
|
+
"radialgradient",
|
|
6464
|
+
"rect",
|
|
6465
|
+
"stop",
|
|
6466
|
+
"style",
|
|
6467
|
+
"switch",
|
|
6468
|
+
"symbol",
|
|
6469
|
+
"text",
|
|
6470
|
+
"textpath",
|
|
6471
|
+
"title",
|
|
6472
|
+
"tref",
|
|
6473
|
+
"tspan",
|
|
6474
|
+
"view",
|
|
6475
|
+
"vkern"
|
|
6093
6476
|
]);
|
|
6094
|
-
var
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6477
|
+
var svgFilters = freeze([
|
|
6478
|
+
"feBlend",
|
|
6479
|
+
"feColorMatrix",
|
|
6480
|
+
"feComponentTransfer",
|
|
6481
|
+
"feComposite",
|
|
6482
|
+
"feConvolveMatrix",
|
|
6483
|
+
"feDiffuseLighting",
|
|
6484
|
+
"feDisplacementMap",
|
|
6485
|
+
"feDistantLight",
|
|
6486
|
+
"feDropShadow",
|
|
6487
|
+
"feFlood",
|
|
6488
|
+
"feFuncA",
|
|
6489
|
+
"feFuncB",
|
|
6490
|
+
"feFuncG",
|
|
6491
|
+
"feFuncR",
|
|
6492
|
+
"feGaussianBlur",
|
|
6493
|
+
"feImage",
|
|
6494
|
+
"feMerge",
|
|
6495
|
+
"feMergeNode",
|
|
6496
|
+
"feMorphology",
|
|
6497
|
+
"feOffset",
|
|
6498
|
+
"fePointLight",
|
|
6499
|
+
"feSpecularLighting",
|
|
6500
|
+
"feSpotLight",
|
|
6501
|
+
"feTile",
|
|
6502
|
+
"feTurbulence"
|
|
6503
|
+
]);
|
|
6504
|
+
var svgDisallowed = freeze([
|
|
6505
|
+
"animate",
|
|
6506
|
+
"color-profile",
|
|
6507
|
+
"cursor",
|
|
6508
|
+
"discard",
|
|
6509
|
+
"font-face",
|
|
6510
|
+
"font-face-format",
|
|
6511
|
+
"font-face-name",
|
|
6512
|
+
"font-face-src",
|
|
6513
|
+
"font-face-uri",
|
|
6514
|
+
"foreignobject",
|
|
6515
|
+
"hatch",
|
|
6516
|
+
"hatchpath",
|
|
6517
|
+
"mesh",
|
|
6518
|
+
"meshgradient",
|
|
6519
|
+
"meshpatch",
|
|
6520
|
+
"meshrow",
|
|
6521
|
+
"missing-glyph",
|
|
6522
|
+
"script",
|
|
6523
|
+
"set",
|
|
6524
|
+
"solidcolor",
|
|
6525
|
+
"unknown",
|
|
6526
|
+
"use"
|
|
6527
|
+
]);
|
|
6528
|
+
var mathMl$1 = freeze([
|
|
6529
|
+
"math",
|
|
6530
|
+
"menclose",
|
|
6531
|
+
"merror",
|
|
6532
|
+
"mfenced",
|
|
6533
|
+
"mfrac",
|
|
6534
|
+
"mglyph",
|
|
6535
|
+
"mi",
|
|
6536
|
+
"mlabeledtr",
|
|
6537
|
+
"mmultiscripts",
|
|
6538
|
+
"mn",
|
|
6539
|
+
"mo",
|
|
6540
|
+
"mover",
|
|
6541
|
+
"mpadded",
|
|
6542
|
+
"mphantom",
|
|
6543
|
+
"mroot",
|
|
6544
|
+
"mrow",
|
|
6545
|
+
"ms",
|
|
6546
|
+
"mspace",
|
|
6547
|
+
"msqrt",
|
|
6548
|
+
"mstyle",
|
|
6549
|
+
"msub",
|
|
6550
|
+
"msup",
|
|
6551
|
+
"msubsup",
|
|
6552
|
+
"mtable",
|
|
6553
|
+
"mtd",
|
|
6554
|
+
"mtext",
|
|
6555
|
+
"mtr",
|
|
6556
|
+
"munder",
|
|
6557
|
+
"munderover",
|
|
6558
|
+
"mprescripts"
|
|
6559
|
+
]);
|
|
6560
|
+
var mathMlDisallowed = freeze([
|
|
6561
|
+
"maction",
|
|
6562
|
+
"maligngroup",
|
|
6563
|
+
"malignmark",
|
|
6564
|
+
"mlongdiv",
|
|
6565
|
+
"mscarries",
|
|
6566
|
+
"mscarry",
|
|
6567
|
+
"msgroup",
|
|
6568
|
+
"mstack",
|
|
6569
|
+
"msline",
|
|
6570
|
+
"msrow",
|
|
6571
|
+
"semantics",
|
|
6572
|
+
"annotation",
|
|
6573
|
+
"annotation-xml",
|
|
6574
|
+
"mprescripts",
|
|
6575
|
+
"none"
|
|
6576
|
+
]);
|
|
6577
|
+
var text = freeze(["#text"]);
|
|
6578
|
+
var html = freeze([
|
|
6579
|
+
"accept",
|
|
6580
|
+
"action",
|
|
6581
|
+
"align",
|
|
6582
|
+
"alt",
|
|
6583
|
+
"autocapitalize",
|
|
6584
|
+
"autocomplete",
|
|
6585
|
+
"autopictureinpicture",
|
|
6586
|
+
"autoplay",
|
|
6587
|
+
"background",
|
|
6588
|
+
"bgcolor",
|
|
6589
|
+
"border",
|
|
6590
|
+
"capture",
|
|
6591
|
+
"cellpadding",
|
|
6592
|
+
"cellspacing",
|
|
6593
|
+
"checked",
|
|
6594
|
+
"cite",
|
|
6595
|
+
"class",
|
|
6596
|
+
"clear",
|
|
6597
|
+
"color",
|
|
6598
|
+
"cols",
|
|
6599
|
+
"colspan",
|
|
6600
|
+
"command",
|
|
6601
|
+
"commandfor",
|
|
6602
|
+
"controls",
|
|
6603
|
+
"controlslist",
|
|
6604
|
+
"coords",
|
|
6605
|
+
"crossorigin",
|
|
6606
|
+
"datetime",
|
|
6607
|
+
"decoding",
|
|
6608
|
+
"default",
|
|
6609
|
+
"dir",
|
|
6610
|
+
"disabled",
|
|
6611
|
+
"disablepictureinpicture",
|
|
6612
|
+
"disableremoteplayback",
|
|
6613
|
+
"download",
|
|
6614
|
+
"draggable",
|
|
6615
|
+
"enctype",
|
|
6616
|
+
"enterkeyhint",
|
|
6617
|
+
"exportparts",
|
|
6618
|
+
"face",
|
|
6619
|
+
"for",
|
|
6620
|
+
"headers",
|
|
6621
|
+
"height",
|
|
6622
|
+
"hidden",
|
|
6623
|
+
"high",
|
|
6624
|
+
"href",
|
|
6625
|
+
"hreflang",
|
|
6626
|
+
"id",
|
|
6627
|
+
"inert",
|
|
6628
|
+
"inputmode",
|
|
6629
|
+
"integrity",
|
|
6630
|
+
"ismap",
|
|
6631
|
+
"kind",
|
|
6632
|
+
"label",
|
|
6633
|
+
"lang",
|
|
6634
|
+
"list",
|
|
6635
|
+
"loading",
|
|
6636
|
+
"loop",
|
|
6637
|
+
"low",
|
|
6638
|
+
"max",
|
|
6639
|
+
"maxlength",
|
|
6640
|
+
"media",
|
|
6641
|
+
"method",
|
|
6642
|
+
"min",
|
|
6643
|
+
"minlength",
|
|
6644
|
+
"multiple",
|
|
6645
|
+
"muted",
|
|
6646
|
+
"name",
|
|
6647
|
+
"nonce",
|
|
6648
|
+
"noshade",
|
|
6649
|
+
"novalidate",
|
|
6650
|
+
"nowrap",
|
|
6651
|
+
"open",
|
|
6652
|
+
"optimum",
|
|
6653
|
+
"part",
|
|
6654
|
+
"pattern",
|
|
6655
|
+
"placeholder",
|
|
6656
|
+
"playsinline",
|
|
6657
|
+
"popover",
|
|
6658
|
+
"popovertarget",
|
|
6659
|
+
"popovertargetaction",
|
|
6660
|
+
"poster",
|
|
6661
|
+
"preload",
|
|
6662
|
+
"pubdate",
|
|
6663
|
+
"radiogroup",
|
|
6664
|
+
"readonly",
|
|
6665
|
+
"rel",
|
|
6666
|
+
"required",
|
|
6667
|
+
"rev",
|
|
6668
|
+
"reversed",
|
|
6669
|
+
"role",
|
|
6670
|
+
"rows",
|
|
6671
|
+
"rowspan",
|
|
6672
|
+
"spellcheck",
|
|
6673
|
+
"scope",
|
|
6674
|
+
"selected",
|
|
6675
|
+
"shape",
|
|
6676
|
+
"size",
|
|
6677
|
+
"sizes",
|
|
6678
|
+
"slot",
|
|
6679
|
+
"span",
|
|
6680
|
+
"srclang",
|
|
6681
|
+
"start",
|
|
6682
|
+
"src",
|
|
6683
|
+
"srcset",
|
|
6684
|
+
"step",
|
|
6685
|
+
"style",
|
|
6686
|
+
"summary",
|
|
6687
|
+
"tabindex",
|
|
6688
|
+
"title",
|
|
6689
|
+
"translate",
|
|
6690
|
+
"type",
|
|
6691
|
+
"usemap",
|
|
6692
|
+
"valign",
|
|
6693
|
+
"value",
|
|
6694
|
+
"width",
|
|
6695
|
+
"wrap",
|
|
6696
|
+
"xmlns"
|
|
6697
|
+
]);
|
|
6698
|
+
var svg = freeze([
|
|
6699
|
+
"accent-height",
|
|
6700
|
+
"accumulate",
|
|
6701
|
+
"additive",
|
|
6702
|
+
"alignment-baseline",
|
|
6703
|
+
"amplitude",
|
|
6704
|
+
"ascent",
|
|
6705
|
+
"attributename",
|
|
6706
|
+
"attributetype",
|
|
6707
|
+
"azimuth",
|
|
6708
|
+
"basefrequency",
|
|
6709
|
+
"baseline-shift",
|
|
6710
|
+
"begin",
|
|
6711
|
+
"bias",
|
|
6712
|
+
"by",
|
|
6713
|
+
"class",
|
|
6714
|
+
"clip",
|
|
6715
|
+
"clippathunits",
|
|
6716
|
+
"clip-path",
|
|
6717
|
+
"clip-rule",
|
|
6718
|
+
"color",
|
|
6719
|
+
"color-interpolation",
|
|
6720
|
+
"color-interpolation-filters",
|
|
6721
|
+
"color-profile",
|
|
6722
|
+
"color-rendering",
|
|
6723
|
+
"cx",
|
|
6724
|
+
"cy",
|
|
6725
|
+
"d",
|
|
6726
|
+
"dx",
|
|
6727
|
+
"dy",
|
|
6728
|
+
"diffuseconstant",
|
|
6729
|
+
"direction",
|
|
6730
|
+
"display",
|
|
6731
|
+
"divisor",
|
|
6732
|
+
"dominant-baseline",
|
|
6733
|
+
"dur",
|
|
6734
|
+
"edgemode",
|
|
6735
|
+
"elevation",
|
|
6736
|
+
"end",
|
|
6737
|
+
"exponent",
|
|
6738
|
+
"fill",
|
|
6739
|
+
"fill-opacity",
|
|
6740
|
+
"fill-rule",
|
|
6741
|
+
"filter",
|
|
6742
|
+
"filterunits",
|
|
6743
|
+
"flood-color",
|
|
6744
|
+
"flood-opacity",
|
|
6745
|
+
"font-family",
|
|
6746
|
+
"font-size",
|
|
6747
|
+
"font-size-adjust",
|
|
6748
|
+
"font-stretch",
|
|
6749
|
+
"font-style",
|
|
6750
|
+
"font-variant",
|
|
6751
|
+
"font-weight",
|
|
6752
|
+
"fx",
|
|
6753
|
+
"fy",
|
|
6754
|
+
"g1",
|
|
6755
|
+
"g2",
|
|
6756
|
+
"glyph-name",
|
|
6757
|
+
"glyphref",
|
|
6758
|
+
"gradientunits",
|
|
6759
|
+
"gradienttransform",
|
|
6760
|
+
"height",
|
|
6761
|
+
"href",
|
|
6762
|
+
"id",
|
|
6763
|
+
"image-rendering",
|
|
6764
|
+
"in",
|
|
6765
|
+
"in2",
|
|
6766
|
+
"intercept",
|
|
6767
|
+
"k",
|
|
6768
|
+
"k1",
|
|
6769
|
+
"k2",
|
|
6770
|
+
"k3",
|
|
6771
|
+
"k4",
|
|
6772
|
+
"kerning",
|
|
6773
|
+
"keypoints",
|
|
6774
|
+
"keysplines",
|
|
6775
|
+
"keytimes",
|
|
6776
|
+
"lang",
|
|
6777
|
+
"lengthadjust",
|
|
6778
|
+
"letter-spacing",
|
|
6779
|
+
"kernelmatrix",
|
|
6780
|
+
"kernelunitlength",
|
|
6781
|
+
"lighting-color",
|
|
6782
|
+
"local",
|
|
6783
|
+
"marker-end",
|
|
6784
|
+
"marker-mid",
|
|
6785
|
+
"marker-start",
|
|
6786
|
+
"markerheight",
|
|
6787
|
+
"markerunits",
|
|
6788
|
+
"markerwidth",
|
|
6789
|
+
"maskcontentunits",
|
|
6790
|
+
"maskunits",
|
|
6791
|
+
"max",
|
|
6792
|
+
"mask",
|
|
6793
|
+
"mask-type",
|
|
6794
|
+
"media",
|
|
6795
|
+
"method",
|
|
6796
|
+
"mode",
|
|
6797
|
+
"min",
|
|
6798
|
+
"name",
|
|
6799
|
+
"numoctaves",
|
|
6800
|
+
"offset",
|
|
6801
|
+
"operator",
|
|
6802
|
+
"opacity",
|
|
6803
|
+
"order",
|
|
6804
|
+
"orient",
|
|
6805
|
+
"orientation",
|
|
6806
|
+
"origin",
|
|
6807
|
+
"overflow",
|
|
6808
|
+
"paint-order",
|
|
6809
|
+
"path",
|
|
6810
|
+
"pathlength",
|
|
6811
|
+
"patterncontentunits",
|
|
6812
|
+
"patterntransform",
|
|
6813
|
+
"patternunits",
|
|
6814
|
+
"pointer-events",
|
|
6815
|
+
"points",
|
|
6816
|
+
"preservealpha",
|
|
6817
|
+
"preserveaspectratio",
|
|
6818
|
+
"primitiveunits",
|
|
6819
|
+
"r",
|
|
6820
|
+
"rx",
|
|
6821
|
+
"ry",
|
|
6822
|
+
"radius",
|
|
6823
|
+
"refx",
|
|
6824
|
+
"refy",
|
|
6825
|
+
"repeatcount",
|
|
6826
|
+
"repeatdur",
|
|
6827
|
+
"restart",
|
|
6828
|
+
"result",
|
|
6829
|
+
"rotate",
|
|
6830
|
+
"scale",
|
|
6831
|
+
"seed",
|
|
6832
|
+
"shape-rendering",
|
|
6833
|
+
"slope",
|
|
6834
|
+
"specularconstant",
|
|
6835
|
+
"specularexponent",
|
|
6836
|
+
"spreadmethod",
|
|
6837
|
+
"startoffset",
|
|
6838
|
+
"stddeviation",
|
|
6839
|
+
"stitchtiles",
|
|
6840
|
+
"stop-color",
|
|
6841
|
+
"stop-opacity",
|
|
6842
|
+
"stroke-dasharray",
|
|
6843
|
+
"stroke-dashoffset",
|
|
6844
|
+
"stroke-linecap",
|
|
6845
|
+
"stroke-linejoin",
|
|
6846
|
+
"stroke-miterlimit",
|
|
6847
|
+
"stroke-opacity",
|
|
6848
|
+
"stroke",
|
|
6849
|
+
"stroke-width",
|
|
6850
|
+
"style",
|
|
6851
|
+
"surfacescale",
|
|
6852
|
+
"systemlanguage",
|
|
6853
|
+
"tabindex",
|
|
6854
|
+
"tablevalues",
|
|
6855
|
+
"targetx",
|
|
6856
|
+
"targety",
|
|
6857
|
+
"transform",
|
|
6858
|
+
"transform-origin",
|
|
6859
|
+
"text-anchor",
|
|
6860
|
+
"text-decoration",
|
|
6861
|
+
"text-orientation",
|
|
6862
|
+
"text-rendering",
|
|
6863
|
+
"textlength",
|
|
6864
|
+
"type",
|
|
6865
|
+
"u1",
|
|
6866
|
+
"u2",
|
|
6867
|
+
"unicode",
|
|
6868
|
+
"values",
|
|
6869
|
+
"vector-effect",
|
|
6870
|
+
"viewbox",
|
|
6871
|
+
"visibility",
|
|
6872
|
+
"version",
|
|
6873
|
+
"vert-adv-y",
|
|
6874
|
+
"vert-origin-x",
|
|
6875
|
+
"vert-origin-y",
|
|
6876
|
+
"width",
|
|
6877
|
+
"word-spacing",
|
|
6878
|
+
"wrap",
|
|
6879
|
+
"writing-mode",
|
|
6880
|
+
"xchannelselector",
|
|
6881
|
+
"ychannelselector",
|
|
6882
|
+
"x",
|
|
6883
|
+
"x1",
|
|
6884
|
+
"x2",
|
|
6885
|
+
"xmlns",
|
|
6886
|
+
"y",
|
|
6887
|
+
"y1",
|
|
6888
|
+
"y2",
|
|
6889
|
+
"z",
|
|
6890
|
+
"zoomandpan"
|
|
6891
|
+
]);
|
|
6892
|
+
var mathMl = freeze([
|
|
6893
|
+
"accent",
|
|
6894
|
+
"accentunder",
|
|
6895
|
+
"align",
|
|
6896
|
+
"bevelled",
|
|
6897
|
+
"close",
|
|
6898
|
+
"columnalign",
|
|
6899
|
+
"columnlines",
|
|
6900
|
+
"columnspacing",
|
|
6901
|
+
"columnspan",
|
|
6902
|
+
"denomalign",
|
|
6903
|
+
"depth",
|
|
6904
|
+
"dir",
|
|
6905
|
+
"display",
|
|
6906
|
+
"displaystyle",
|
|
6907
|
+
"encoding",
|
|
6908
|
+
"fence",
|
|
6909
|
+
"frame",
|
|
6910
|
+
"height",
|
|
6911
|
+
"href",
|
|
6912
|
+
"id",
|
|
6913
|
+
"largeop",
|
|
6914
|
+
"length",
|
|
6915
|
+
"linethickness",
|
|
6916
|
+
"lquote",
|
|
6917
|
+
"lspace",
|
|
6918
|
+
"mathbackground",
|
|
6919
|
+
"mathcolor",
|
|
6920
|
+
"mathsize",
|
|
6921
|
+
"mathvariant",
|
|
6922
|
+
"maxsize",
|
|
6923
|
+
"minsize",
|
|
6924
|
+
"movablelimits",
|
|
6925
|
+
"notation",
|
|
6926
|
+
"numalign",
|
|
6927
|
+
"open",
|
|
6928
|
+
"rowalign",
|
|
6929
|
+
"rowlines",
|
|
6930
|
+
"rowspacing",
|
|
6931
|
+
"rowspan",
|
|
6932
|
+
"rspace",
|
|
6933
|
+
"rquote",
|
|
6934
|
+
"scriptlevel",
|
|
6935
|
+
"scriptminsize",
|
|
6936
|
+
"scriptsizemultiplier",
|
|
6937
|
+
"selection",
|
|
6938
|
+
"separator",
|
|
6939
|
+
"separators",
|
|
6940
|
+
"stretchy",
|
|
6941
|
+
"subscriptshift",
|
|
6942
|
+
"supscriptshift",
|
|
6943
|
+
"symmetric",
|
|
6944
|
+
"voffset",
|
|
6945
|
+
"width",
|
|
6946
|
+
"xmlns"
|
|
6947
|
+
]);
|
|
6948
|
+
var xml = freeze([
|
|
6949
|
+
"xlink:href",
|
|
6950
|
+
"xml:id",
|
|
6951
|
+
"xlink:title",
|
|
6952
|
+
"xml:space",
|
|
6953
|
+
"xmlns:xlink"
|
|
6954
|
+
]);
|
|
6955
|
+
var MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
|
|
6956
|
+
var ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
|
|
6957
|
+
var TMPLIT_EXPR = seal(/\${[\w\W]*/g);
|
|
6958
|
+
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
|
|
6959
|
+
var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
|
6960
|
+
var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
|
|
6961
|
+
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
6962
|
+
var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g);
|
|
6963
|
+
var DOCTYPE_NAME = seal(/^html$/i);
|
|
6964
|
+
var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
6965
|
+
var ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
|
|
6966
|
+
var COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
|
|
6967
|
+
var FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
|
|
6968
|
+
var SELF_CLOSING_TAG = seal(/\/>/i);
|
|
6969
|
+
var NODE_TYPE = {
|
|
6970
|
+
element: 1,
|
|
6971
|
+
attribute: 2,
|
|
6972
|
+
text: 3,
|
|
6973
|
+
cdataSection: 4,
|
|
6974
|
+
entityReference: 5,
|
|
6975
|
+
entityNode: 6,
|
|
6976
|
+
processingInstruction: 7,
|
|
6977
|
+
comment: 8,
|
|
6978
|
+
document: 9,
|
|
6979
|
+
documentType: 10,
|
|
6980
|
+
documentFragment: 11,
|
|
6981
|
+
notation: 12
|
|
6982
|
+
};
|
|
6983
|
+
var LITERAL_TEXT_ELEMENT_NAMES = [
|
|
6984
|
+
"style",
|
|
6985
|
+
"script",
|
|
6986
|
+
"xmp",
|
|
6987
|
+
"iframe",
|
|
6988
|
+
"noembed",
|
|
6989
|
+
"noframes",
|
|
6990
|
+
"plaintext",
|
|
6991
|
+
"noscript"
|
|
6992
|
+
];
|
|
6993
|
+
var LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, LITERAL_TEXT_ELEMENT_NAMES));
|
|
6994
|
+
var LITERAL_TEXT_CLOSE = function() {
|
|
6995
|
+
const map = {};
|
|
6996
|
+
arrayForEach(LITERAL_TEXT_ELEMENT_NAMES, (name) => {
|
|
6997
|
+
map[name] = seal(new RegExp("</" + name + "(?=[\\t\\n\\f\\r />])", "i"));
|
|
6998
|
+
});
|
|
6999
|
+
return freeze(map);
|
|
7000
|
+
}();
|
|
7001
|
+
var getGlobal = function getGlobal() {
|
|
7002
|
+
return typeof window === "undefined" ? null : window;
|
|
7003
|
+
};
|
|
7004
|
+
/**
|
|
7005
|
+
* Creates a no-op policy for internal use only.
|
|
7006
|
+
* Don't export this function outside this module!
|
|
7007
|
+
* @param trustedTypes The policy factory.
|
|
7008
|
+
* @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
|
|
7009
|
+
* @return The policy created (or null, if Trusted Types
|
|
7010
|
+
* are not supported or creating the policy failed).
|
|
7011
|
+
*/
|
|
7012
|
+
var _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
|
|
7013
|
+
if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") return null;
|
|
7014
|
+
let suffix = null;
|
|
7015
|
+
const ATTR_NAME = "data-tt-policy-suffix";
|
|
7016
|
+
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
|
7017
|
+
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
|
6105
7018
|
try {
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
7019
|
+
return trustedTypes.createPolicy(policyName, {
|
|
7020
|
+
createHTML(html) {
|
|
7021
|
+
return html;
|
|
7022
|
+
},
|
|
7023
|
+
createScriptURL(scriptUrl) {
|
|
7024
|
+
return scriptUrl;
|
|
7025
|
+
}
|
|
7026
|
+
});
|
|
7027
|
+
} catch (_) {
|
|
7028
|
+
console.warn("TrustedTypes policy " + policyName + " could not be created.");
|
|
6109
7029
|
return null;
|
|
6110
7030
|
}
|
|
7031
|
+
};
|
|
7032
|
+
var _createHooksMap = function _createHooksMap() {
|
|
7033
|
+
return {
|
|
7034
|
+
afterSanitizeAttributes: [],
|
|
7035
|
+
afterSanitizeElements: [],
|
|
7036
|
+
afterSanitizeShadowDOM: [],
|
|
7037
|
+
beforeSanitizeAttributes: [],
|
|
7038
|
+
beforeSanitizeElements: [],
|
|
7039
|
+
beforeSanitizeShadowDOM: [],
|
|
7040
|
+
uponSanitizeAttribute: [],
|
|
7041
|
+
uponSanitizeElement: [],
|
|
7042
|
+
uponSanitizeShadowNode: []
|
|
7043
|
+
};
|
|
7044
|
+
};
|
|
7045
|
+
/**
|
|
7046
|
+
* Resolve a set-valued configuration option: a fresh set built from
|
|
7047
|
+
* cfg[key] when it is an own array property (seeded with a clone of
|
|
7048
|
+
* options.base when given, case-normalized via options.transform),
|
|
7049
|
+
* the fallback set otherwise.
|
|
7050
|
+
*
|
|
7051
|
+
* @param cfg the cloned, prototype-free configuration object
|
|
7052
|
+
* @param key the configuration property to read
|
|
7053
|
+
* @param fallback the set to use when the option is absent or not an array
|
|
7054
|
+
* @param options transform and optional base set to merge into
|
|
7055
|
+
* @returns the resolved set
|
|
7056
|
+
*/
|
|
7057
|
+
var _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
|
|
7058
|
+
return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
|
|
7059
|
+
};
|
|
7060
|
+
/**
|
|
7061
|
+
* Resolve an object-valued configuration option: a prototype-free clone
|
|
7062
|
+
* of cfg[key] when it is an own, truthy object property, else a fresh
|
|
7063
|
+
* fallback built by makeFallback (fresh on every parse, so a previous
|
|
7064
|
+
* parse can never leak state into the next one).
|
|
7065
|
+
*
|
|
7066
|
+
* @param cfg the cloned, prototype-free configuration object
|
|
7067
|
+
* @param key the configuration property to read
|
|
7068
|
+
* @param makeFallback builds the fallback value when the option is absent
|
|
7069
|
+
* @returns the resolved object
|
|
7070
|
+
*/
|
|
7071
|
+
var _resolveObjectOption = function _resolveObjectOption(cfg, key, makeFallback) {
|
|
7072
|
+
const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
|
|
7073
|
+
return value && typeof value === "object" ? clone(value) : makeFallback();
|
|
7074
|
+
};
|
|
7075
|
+
function createDOMPurify() {
|
|
7076
|
+
let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
7077
|
+
const DOMPurify = (root) => createDOMPurify(root);
|
|
7078
|
+
DOMPurify.version = "3.4.15";
|
|
7079
|
+
DOMPurify.removed = [];
|
|
7080
|
+
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
|
|
7081
|
+
DOMPurify.isSupported = false;
|
|
7082
|
+
return DOMPurify;
|
|
7083
|
+
}
|
|
7084
|
+
let document = window.document;
|
|
7085
|
+
const originalDocument = document;
|
|
7086
|
+
const currentScript = originalDocument.currentScript;
|
|
7087
|
+
window.DocumentFragment;
|
|
7088
|
+
const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter;
|
|
7089
|
+
window.NamedNodeMap === void 0 && (window.NamedNodeMap || window.MozNamedAttrMap);
|
|
7090
|
+
window.HTMLFormElement;
|
|
7091
|
+
const DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
|
|
7092
|
+
const ElementPrototype = Element.prototype;
|
|
7093
|
+
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
|
7094
|
+
const remove = lookupGetter(ElementPrototype, "remove");
|
|
7095
|
+
const removeAttributeNode = lookupGetter(ElementPrototype, "removeAttributeNode");
|
|
7096
|
+
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
|
7097
|
+
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
|
7098
|
+
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
|
7099
|
+
const getShadowRoot = lookupGetter(ElementPrototype, "shadowRoot");
|
|
7100
|
+
const getAttributes = lookupGetter(ElementPrototype, "attributes");
|
|
7101
|
+
const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeType") : null;
|
|
7102
|
+
const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeName") : null;
|
|
7103
|
+
const getOwnerDocument = Node && Node.prototype ? lookupGetter(Node.prototype, "ownerDocument") : null;
|
|
7104
|
+
const _readNodeType = function _readNodeType(node) {
|
|
7105
|
+
return getNodeType ? getNodeType(node) : node.nodeType;
|
|
7106
|
+
};
|
|
7107
|
+
const _readNodeName = function _readNodeName(node) {
|
|
7108
|
+
return getNodeName ? getNodeName(node) : node.nodeName;
|
|
7109
|
+
};
|
|
7110
|
+
if (typeof HTMLTemplateElement === "function") {
|
|
7111
|
+
const template = document.createElement("template");
|
|
7112
|
+
if (template.content && template.content.ownerDocument) document = template.content.ownerDocument;
|
|
7113
|
+
}
|
|
7114
|
+
let trustedTypesPolicy;
|
|
7115
|
+
let emptyHTML = "";
|
|
7116
|
+
let defaultTrustedTypesPolicy;
|
|
7117
|
+
let defaultTrustedTypesPolicyResolved = false;
|
|
7118
|
+
let IN_TRUSTED_TYPES_POLICY = 0;
|
|
7119
|
+
const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
|
|
7120
|
+
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.");
|
|
7121
|
+
};
|
|
7122
|
+
const _createTrustedHTML = function _createTrustedHTML(html) {
|
|
7123
|
+
_assertNotInTrustedTypesPolicy();
|
|
7124
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
7125
|
+
try {
|
|
7126
|
+
return trustedTypesPolicy.createHTML(html);
|
|
7127
|
+
} finally {
|
|
7128
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
7129
|
+
}
|
|
7130
|
+
};
|
|
7131
|
+
const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
|
|
7132
|
+
_assertNotInTrustedTypesPolicy();
|
|
7133
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
7134
|
+
try {
|
|
7135
|
+
return trustedTypesPolicy.createScriptURL(scriptUrl);
|
|
7136
|
+
} finally {
|
|
7137
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
7138
|
+
}
|
|
7139
|
+
};
|
|
7140
|
+
const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
|
|
7141
|
+
if (!defaultTrustedTypesPolicyResolved) {
|
|
7142
|
+
defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
7143
|
+
defaultTrustedTypesPolicyResolved = true;
|
|
7144
|
+
}
|
|
7145
|
+
return defaultTrustedTypesPolicy;
|
|
7146
|
+
};
|
|
7147
|
+
const _document = document, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
|
|
7148
|
+
const importNode = originalDocument.importNode;
|
|
7149
|
+
let hooks = _createHooksMap();
|
|
7150
|
+
/**
|
|
7151
|
+
* Expose whether this browser supports running the full DOMPurify.
|
|
7152
|
+
*/
|
|
7153
|
+
DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
|
7154
|
+
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;
|
|
7155
|
+
let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
|
|
7156
|
+
/**
|
|
7157
|
+
* We consider the elements and attributes below to be safe. Ideally
|
|
7158
|
+
* don't add any new ones but feel free to remove unwanted ones.
|
|
7159
|
+
*/
|
|
7160
|
+
let ALLOWED_TAGS = null;
|
|
7161
|
+
const DEFAULT_ALLOWED_TAGS = addToSet({}, [
|
|
7162
|
+
...html$1,
|
|
7163
|
+
...svg$1,
|
|
7164
|
+
...svgFilters,
|
|
7165
|
+
...mathMl$1,
|
|
7166
|
+
...text
|
|
7167
|
+
]);
|
|
7168
|
+
let ALLOWED_ATTR = null;
|
|
7169
|
+
const DEFAULT_ALLOWED_ATTR = addToSet({}, [
|
|
7170
|
+
...html,
|
|
7171
|
+
...svg,
|
|
7172
|
+
...mathMl,
|
|
7173
|
+
...xml
|
|
7174
|
+
]);
|
|
7175
|
+
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
7176
|
+
tagNameCheck: {
|
|
7177
|
+
writable: true,
|
|
7178
|
+
configurable: false,
|
|
7179
|
+
enumerable: true,
|
|
7180
|
+
value: null
|
|
7181
|
+
},
|
|
7182
|
+
attributeNameCheck: {
|
|
7183
|
+
writable: true,
|
|
7184
|
+
configurable: false,
|
|
7185
|
+
enumerable: true,
|
|
7186
|
+
value: null
|
|
7187
|
+
},
|
|
7188
|
+
allowCustomizedBuiltInElements: {
|
|
7189
|
+
writable: true,
|
|
7190
|
+
configurable: false,
|
|
7191
|
+
enumerable: true,
|
|
7192
|
+
value: false
|
|
7193
|
+
}
|
|
7194
|
+
}));
|
|
7195
|
+
let FORBID_TAGS = null;
|
|
7196
|
+
let FORBID_ATTR = null;
|
|
7197
|
+
const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
7198
|
+
tagCheck: {
|
|
7199
|
+
writable: true,
|
|
7200
|
+
configurable: false,
|
|
7201
|
+
enumerable: true,
|
|
7202
|
+
value: null
|
|
7203
|
+
},
|
|
7204
|
+
attributeCheck: {
|
|
7205
|
+
writable: true,
|
|
7206
|
+
configurable: false,
|
|
7207
|
+
enumerable: true,
|
|
7208
|
+
value: null
|
|
7209
|
+
}
|
|
7210
|
+
}));
|
|
7211
|
+
let ALLOW_ARIA_ATTR = true;
|
|
7212
|
+
let ALLOW_DATA_ATTR = true;
|
|
7213
|
+
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
7214
|
+
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
7215
|
+
let SAFE_FOR_TEMPLATES = false;
|
|
7216
|
+
let SAFE_FOR_XML = true;
|
|
7217
|
+
let WHOLE_DOCUMENT = false;
|
|
7218
|
+
let SET_CONFIG = false;
|
|
7219
|
+
let SET_CONFIG_ALLOWED_TAGS = null;
|
|
7220
|
+
let SET_CONFIG_ALLOWED_ATTR = null;
|
|
7221
|
+
let FORCE_BODY = false;
|
|
7222
|
+
let RETURN_DOM = false;
|
|
7223
|
+
let RETURN_DOM_FRAGMENT = false;
|
|
7224
|
+
let RETURN_TRUSTED_TYPE = false;
|
|
7225
|
+
let SANITIZE_DOM = true;
|
|
7226
|
+
let SANITIZE_NAMED_PROPS = false;
|
|
7227
|
+
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
|
7228
|
+
let KEEP_CONTENT = true;
|
|
7229
|
+
let IN_PLACE = false;
|
|
7230
|
+
let USE_PROFILES = {};
|
|
7231
|
+
let FORBID_CONTENTS = null;
|
|
7232
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, [
|
|
7233
|
+
"annotation-xml",
|
|
7234
|
+
"audio",
|
|
7235
|
+
"colgroup",
|
|
7236
|
+
"desc",
|
|
7237
|
+
"foreignobject",
|
|
7238
|
+
"head",
|
|
7239
|
+
"iframe",
|
|
7240
|
+
"math",
|
|
7241
|
+
"mi",
|
|
7242
|
+
"mn",
|
|
7243
|
+
"mo",
|
|
7244
|
+
"ms",
|
|
7245
|
+
"mtext",
|
|
7246
|
+
"noembed",
|
|
7247
|
+
"noframes",
|
|
7248
|
+
"noscript",
|
|
7249
|
+
"plaintext",
|
|
7250
|
+
"script",
|
|
7251
|
+
"selectedcontent",
|
|
7252
|
+
"style",
|
|
7253
|
+
"svg",
|
|
7254
|
+
"template",
|
|
7255
|
+
"thead",
|
|
7256
|
+
"title",
|
|
7257
|
+
"video",
|
|
7258
|
+
"xmp"
|
|
7259
|
+
]);
|
|
7260
|
+
let DATA_URI_TAGS = null;
|
|
7261
|
+
const DEFAULT_DATA_URI_TAGS = addToSet({}, [
|
|
7262
|
+
"audio",
|
|
7263
|
+
"video",
|
|
7264
|
+
"img",
|
|
7265
|
+
"source",
|
|
7266
|
+
"image",
|
|
7267
|
+
"track"
|
|
7268
|
+
]);
|
|
7269
|
+
let URI_SAFE_ATTRIBUTES = null;
|
|
7270
|
+
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
|
|
7271
|
+
"alt",
|
|
7272
|
+
"class",
|
|
7273
|
+
"for",
|
|
7274
|
+
"id",
|
|
7275
|
+
"label",
|
|
7276
|
+
"name",
|
|
7277
|
+
"pattern",
|
|
7278
|
+
"placeholder",
|
|
7279
|
+
"role",
|
|
7280
|
+
"summary",
|
|
7281
|
+
"title",
|
|
7282
|
+
"value",
|
|
7283
|
+
"style",
|
|
7284
|
+
"xmlns"
|
|
7285
|
+
]);
|
|
7286
|
+
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
|
7287
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
7288
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
7289
|
+
let NAMESPACE = HTML_NAMESPACE;
|
|
7290
|
+
let IS_EMPTY_INPUT = false;
|
|
7291
|
+
let ALLOWED_NAMESPACES = null;
|
|
7292
|
+
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [
|
|
7293
|
+
MATHML_NAMESPACE,
|
|
7294
|
+
SVG_NAMESPACE,
|
|
7295
|
+
HTML_NAMESPACE
|
|
7296
|
+
], stringToString);
|
|
7297
|
+
const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze([
|
|
7298
|
+
"mi",
|
|
7299
|
+
"mo",
|
|
7300
|
+
"mn",
|
|
7301
|
+
"ms",
|
|
7302
|
+
"mtext"
|
|
7303
|
+
]);
|
|
7304
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
|
|
7305
|
+
const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
|
|
7306
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
|
|
7307
|
+
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
|
|
7308
|
+
"title",
|
|
7309
|
+
"style",
|
|
7310
|
+
"font",
|
|
7311
|
+
"a",
|
|
7312
|
+
"script"
|
|
7313
|
+
]);
|
|
7314
|
+
let PARSER_MEDIA_TYPE = null;
|
|
7315
|
+
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
|
7316
|
+
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
|
7317
|
+
let transformCaseFunc = null;
|
|
7318
|
+
let CONFIG = null;
|
|
7319
|
+
const formElement = document.createElement("form");
|
|
7320
|
+
const isRegexOrFunction = function isRegexOrFunction(testValue) {
|
|
7321
|
+
return testValue instanceof RegExp || testValue instanceof Function;
|
|
7322
|
+
};
|
|
7323
|
+
/**
|
|
7324
|
+
* _parseConfig
|
|
7325
|
+
*
|
|
7326
|
+
* @param cfg optional config literal
|
|
7327
|
+
*/
|
|
7328
|
+
const _parseConfig = function _parseConfig() {
|
|
7329
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
7330
|
+
if (CONFIG && CONFIG === cfg) return;
|
|
7331
|
+
if (!cfg || typeof cfg !== "object") cfg = {};
|
|
7332
|
+
cfg = clone(cfg);
|
|
7333
|
+
PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
7334
|
+
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
|
7335
|
+
ALLOWED_TAGS = _resolveSetOption(cfg, "ALLOWED_TAGS", DEFAULT_ALLOWED_TAGS, { transform: transformCaseFunc });
|
|
7336
|
+
ALLOWED_ATTR = _resolveSetOption(cfg, "ALLOWED_ATTR", DEFAULT_ALLOWED_ATTR, { transform: transformCaseFunc });
|
|
7337
|
+
ALLOWED_NAMESPACES = _resolveSetOption(cfg, "ALLOWED_NAMESPACES", DEFAULT_ALLOWED_NAMESPACES, { transform: stringToString });
|
|
7338
|
+
URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, "ADD_URI_SAFE_ATTR", DEFAULT_URI_SAFE_ATTRIBUTES, {
|
|
7339
|
+
transform: transformCaseFunc,
|
|
7340
|
+
base: DEFAULT_URI_SAFE_ATTRIBUTES
|
|
7341
|
+
});
|
|
7342
|
+
DATA_URI_TAGS = _resolveSetOption(cfg, "ADD_DATA_URI_TAGS", DEFAULT_DATA_URI_TAGS, {
|
|
7343
|
+
transform: transformCaseFunc,
|
|
7344
|
+
base: DEFAULT_DATA_URI_TAGS
|
|
7345
|
+
});
|
|
7346
|
+
FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
|
|
7347
|
+
FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", clone({}), { transform: transformCaseFunc });
|
|
7348
|
+
FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", clone({}), { transform: transformCaseFunc });
|
|
7349
|
+
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
|
|
7350
|
+
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
|
7351
|
+
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
|
7352
|
+
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
|
7353
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
|
7354
|
+
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
|
7355
|
+
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
|
7356
|
+
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
|
7357
|
+
RETURN_DOM = cfg.RETURN_DOM || false;
|
|
7358
|
+
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
|
7359
|
+
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
|
7360
|
+
FORCE_BODY = cfg.FORCE_BODY || false;
|
|
7361
|
+
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
|
7362
|
+
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
|
7363
|
+
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
|
7364
|
+
IN_PLACE = cfg.IN_PLACE || false;
|
|
7365
|
+
IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
|
|
7366
|
+
NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
|
|
7367
|
+
MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS));
|
|
7368
|
+
HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS));
|
|
7369
|
+
const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", () => create(null));
|
|
7370
|
+
CUSTOM_ELEMENT_HANDLING = create(null);
|
|
7371
|
+
if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
|
|
7372
|
+
if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
|
|
7373
|
+
if (objectHasOwnProperty(customElementHandling, "allowCustomizedBuiltInElements") && typeof customElementHandling.allowCustomizedBuiltInElements === "boolean") CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements;
|
|
7374
|
+
seal(CUSTOM_ELEMENT_HANDLING);
|
|
7375
|
+
if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
|
|
7376
|
+
if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
|
|
7377
|
+
if (USE_PROFILES) {
|
|
7378
|
+
ALLOWED_TAGS = addToSet({}, text);
|
|
7379
|
+
ALLOWED_ATTR = create(null);
|
|
7380
|
+
if (USE_PROFILES.html === true) {
|
|
7381
|
+
addToSet(ALLOWED_TAGS, html$1);
|
|
7382
|
+
addToSet(ALLOWED_ATTR, html);
|
|
7383
|
+
}
|
|
7384
|
+
if (USE_PROFILES.svg === true) {
|
|
7385
|
+
addToSet(ALLOWED_TAGS, svg$1);
|
|
7386
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
7387
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
7388
|
+
}
|
|
7389
|
+
if (USE_PROFILES.svgFilters === true) {
|
|
7390
|
+
addToSet(ALLOWED_TAGS, svgFilters);
|
|
7391
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
7392
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
7393
|
+
}
|
|
7394
|
+
if (USE_PROFILES.mathMl === true) {
|
|
7395
|
+
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
7396
|
+
addToSet(ALLOWED_ATTR, mathMl);
|
|
7397
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
7398
|
+
}
|
|
7399
|
+
}
|
|
7400
|
+
EXTRA_ELEMENT_HANDLING.tagCheck = null;
|
|
7401
|
+
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
|
|
7402
|
+
if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
|
|
7403
|
+
if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
7404
|
+
else if (arrayIsArray(cfg.ADD_TAGS)) {
|
|
7405
|
+
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
7406
|
+
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
7407
|
+
}
|
|
7408
|
+
}
|
|
7409
|
+
if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
|
|
7410
|
+
if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
7411
|
+
else if (arrayIsArray(cfg.ADD_ATTR)) {
|
|
7412
|
+
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
7413
|
+
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
7414
|
+
}
|
|
7415
|
+
}
|
|
7416
|
+
if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
|
|
7417
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
7418
|
+
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
7419
|
+
}
|
|
7420
|
+
if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
|
|
7421
|
+
if (WHOLE_DOCUMENT) addToSet(ALLOWED_TAGS, [
|
|
7422
|
+
"html",
|
|
7423
|
+
"head",
|
|
7424
|
+
"body"
|
|
7425
|
+
]);
|
|
7426
|
+
if (ALLOWED_TAGS.table) {
|
|
7427
|
+
addToSet(ALLOWED_TAGS, ["tbody"]);
|
|
7428
|
+
delete FORBID_TAGS.tbody;
|
|
7429
|
+
}
|
|
7430
|
+
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
7431
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.");
|
|
7432
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.");
|
|
7433
|
+
const previousTrustedTypesPolicy = trustedTypesPolicy;
|
|
7434
|
+
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
7435
|
+
try {
|
|
7436
|
+
emptyHTML = _createTrustedHTML("");
|
|
7437
|
+
} catch (error) {
|
|
7438
|
+
trustedTypesPolicy = previousTrustedTypesPolicy;
|
|
7439
|
+
throw error;
|
|
7440
|
+
}
|
|
7441
|
+
} else if (cfg.TRUSTED_TYPES_POLICY === null) {
|
|
7442
|
+
trustedTypesPolicy = void 0;
|
|
7443
|
+
emptyHTML = "";
|
|
7444
|
+
} else {
|
|
7445
|
+
if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
|
|
7446
|
+
if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
|
|
7447
|
+
}
|
|
7448
|
+
if (freeze) freeze(cfg);
|
|
7449
|
+
CONFIG = cfg;
|
|
7450
|
+
};
|
|
7451
|
+
const ALL_SVG_TAGS = addToSet({}, [
|
|
7452
|
+
...svg$1,
|
|
7453
|
+
...svgFilters,
|
|
7454
|
+
...svgDisallowed
|
|
7455
|
+
]);
|
|
7456
|
+
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
7457
|
+
/**
|
|
7458
|
+
* Namespace rules for an element in the SVG namespace.
|
|
7459
|
+
*
|
|
7460
|
+
* @param tagName the element's lowercase tag name
|
|
7461
|
+
* @param parent the (possibly simulated) parent node
|
|
7462
|
+
* @param parentTagName the parent's lowercase tag name
|
|
7463
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
7464
|
+
*/
|
|
7465
|
+
const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
|
|
7466
|
+
if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "svg";
|
|
7467
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
7468
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
7469
|
+
};
|
|
7470
|
+
/**
|
|
7471
|
+
* Namespace rules for an element in the MathML namespace.
|
|
7472
|
+
*
|
|
7473
|
+
* @param tagName the element's lowercase tag name
|
|
7474
|
+
* @param parent the (possibly simulated) parent node
|
|
7475
|
+
* @param parentTagName the parent's lowercase tag name
|
|
7476
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
7477
|
+
*/
|
|
7478
|
+
const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
|
|
7479
|
+
if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "math";
|
|
7480
|
+
if (parent.namespaceURI === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
|
7481
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
7482
|
+
};
|
|
7483
|
+
/**
|
|
7484
|
+
* Namespace rules for an element in the HTML namespace.
|
|
7485
|
+
*
|
|
7486
|
+
* @param tagName the element's lowercase tag name
|
|
7487
|
+
* @param parent the (possibly simulated) parent node
|
|
7488
|
+
* @param parentTagName the parent's lowercase tag name
|
|
7489
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
7490
|
+
*/
|
|
7491
|
+
const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
|
|
7492
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
|
|
7493
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
|
|
7494
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
7495
|
+
};
|
|
7496
|
+
/**
|
|
7497
|
+
* @param element a DOM element whose namespace is being checked
|
|
7498
|
+
* @returns Return false if the element has a
|
|
7499
|
+
* namespace that a spec-compliant parser would never
|
|
7500
|
+
* return. Return true otherwise.
|
|
7501
|
+
*/
|
|
7502
|
+
const _checkValidNamespace = function _checkValidNamespace(element) {
|
|
7503
|
+
let parent = getParentNode(element);
|
|
7504
|
+
if (!parent || !parent.tagName) parent = {
|
|
7505
|
+
namespaceURI: NAMESPACE,
|
|
7506
|
+
tagName: "template"
|
|
7507
|
+
};
|
|
7508
|
+
const tagName = stringToLowerCase(element.tagName);
|
|
7509
|
+
const parentTagName = stringToLowerCase(parent.tagName);
|
|
7510
|
+
if (!ALLOWED_NAMESPACES[element.namespaceURI]) return false;
|
|
7511
|
+
if (element.namespaceURI === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
|
|
7512
|
+
if (element.namespaceURI === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
|
|
7513
|
+
if (element.namespaceURI === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
|
|
7514
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) return true;
|
|
7515
|
+
return false;
|
|
7516
|
+
};
|
|
7517
|
+
/**
|
|
7518
|
+
* _forceRemove
|
|
7519
|
+
*
|
|
7520
|
+
* @param node a DOM node
|
|
7521
|
+
*/
|
|
7522
|
+
const _forceRemove = function _forceRemove(node) {
|
|
7523
|
+
arrayPush(DOMPurify.removed, { element: node });
|
|
7524
|
+
try {
|
|
7525
|
+
getParentNode(node).removeChild(node);
|
|
7526
|
+
} catch (_) {
|
|
7527
|
+
remove(node);
|
|
7528
|
+
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");
|
|
7529
|
+
}
|
|
7530
|
+
};
|
|
7531
|
+
/**
|
|
7532
|
+
* _stripAttributeNode
|
|
7533
|
+
*
|
|
7534
|
+
* Remove a single Attr node case/namespace-exactly on an attribute-teardown
|
|
7535
|
+
* path. Name-based removeAttribute() ASCII-lowercases its lookup key for an
|
|
7536
|
+
* HTML element in an HTML document and so silently misses a case-preserved
|
|
7537
|
+
* handler (e.g. `ONERROR` off an XML/XHTML import) - the same defect
|
|
7538
|
+
* _removeAttribute() was fixed for, which a name-based call would reintroduce
|
|
7539
|
+
* on these IN_PLACE teardown paths. Unlike _removeAttribute this does not
|
|
7540
|
+
* record into DOMPurify.removed: the neutralize passes intentionally do not
|
|
7541
|
+
* book-keep. A clobbered/detached node falls back to best-effort name-based
|
|
7542
|
+
* removal.
|
|
7543
|
+
*
|
|
7544
|
+
* @param element the element to strip the attribute from
|
|
7545
|
+
* @param attribute the Attr node to remove
|
|
7546
|
+
* @param name the attribute's name, for the fallback path
|
|
7547
|
+
*/
|
|
7548
|
+
const _stripAttributeNode = function _stripAttributeNode(element, attribute, name) {
|
|
7549
|
+
try {
|
|
7550
|
+
removeAttributeNode(element, attribute);
|
|
7551
|
+
} catch (_) {
|
|
7552
|
+
try {
|
|
7553
|
+
element.removeAttribute(name);
|
|
7554
|
+
} catch (_) {}
|
|
7555
|
+
}
|
|
7556
|
+
};
|
|
7557
|
+
/**
|
|
7558
|
+
* _neutralizeRoot
|
|
7559
|
+
*
|
|
7560
|
+
* Fail-closed teardown of an in-place root after the sanitize walk aborts
|
|
7561
|
+
* (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
|
|
7562
|
+
* custom element's reaction detaches a node so `_forceRemove`'s deliberate
|
|
7563
|
+
* parentless guard throws, or any other re-entrant engine mutation — would
|
|
7564
|
+
* otherwise leave the caller's *live* tree half-sanitized, with everything
|
|
7565
|
+
* after the abort point still carrying its handlers. There is no safe way
|
|
7566
|
+
* to resume the walk (the tree mutated under us), so we strip the root bare:
|
|
7567
|
+
* remove every child and every attribute, then let the caller's catch see
|
|
7568
|
+
* the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
|
|
7569
|
+
* getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
|
|
7570
|
+
*
|
|
7571
|
+
* @param root the in-place root to empty
|
|
7572
|
+
*/
|
|
7573
|
+
const _neutralizeRoot = function _neutralizeRoot(root) {
|
|
7574
|
+
_neutralizeSubtree(root);
|
|
7575
|
+
const childNodes = getChildNodes(root);
|
|
7576
|
+
if (childNodes) {
|
|
7577
|
+
const snapshot = [];
|
|
7578
|
+
arrayForEach(childNodes, (child) => {
|
|
7579
|
+
arrayPush(snapshot, child);
|
|
7580
|
+
});
|
|
7581
|
+
arrayForEach(snapshot, (child) => {
|
|
7582
|
+
try {
|
|
7583
|
+
remove(child);
|
|
7584
|
+
} catch (_) {}
|
|
7585
|
+
});
|
|
7586
|
+
}
|
|
7587
|
+
const attributes = getAttributes(root);
|
|
7588
|
+
if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
|
|
7589
|
+
const attribute = attributes[i];
|
|
7590
|
+
const name = attribute && attribute.name;
|
|
7591
|
+
if (typeof name === "string") _stripAttributeNode(root, attribute, name);
|
|
7592
|
+
}
|
|
7593
|
+
};
|
|
7594
|
+
/**
|
|
7595
|
+
* _removeAttribute
|
|
7596
|
+
*
|
|
7597
|
+
* Name-based getAttributeNode()/removeAttribute() ASCII-lowercase their
|
|
7598
|
+
* lookup key for HTML elements in an HTML document, so they silently miss an
|
|
7599
|
+
* attribute whose stored qualified name still contains uppercase ASCII
|
|
7600
|
+
* letters. That happens when the node came from a case-preserving source
|
|
7601
|
+
* (an XML/XHTML document imported via importNode(), or createAttributeNS()),
|
|
7602
|
+
* where e.g. `ONERROR` survives the walk: the policy check lowercases to
|
|
7603
|
+
* `onerror` and rejects it, but `removeAttribute('ONERROR')` looks up
|
|
7604
|
+
* `onerror` and finds nothing. Remove the exact Attr node instead, which is
|
|
7605
|
+
* case- and namespace-exact, and fall back to name-based removal only when
|
|
7606
|
+
* the caller could not supply the node.
|
|
7607
|
+
*
|
|
7608
|
+
* @param name an Attribute name
|
|
7609
|
+
* @param element a DOM node
|
|
7610
|
+
* @param attr the exact Attr node to remove, when the caller has it
|
|
7611
|
+
*/
|
|
7612
|
+
const _removeAttribute = function _removeAttribute(name, element, attr) {
|
|
7613
|
+
if (!attr) try {
|
|
7614
|
+
attr = element.getAttributeNode(name);
|
|
7615
|
+
} catch (_) {
|
|
7616
|
+
attr = null;
|
|
7617
|
+
}
|
|
7618
|
+
arrayPush(DOMPurify.removed, {
|
|
7619
|
+
attribute: attr || null,
|
|
7620
|
+
from: element
|
|
7621
|
+
});
|
|
7622
|
+
try {
|
|
7623
|
+
if (attr) removeAttributeNode(element, attr);
|
|
7624
|
+
else element.removeAttribute(name);
|
|
7625
|
+
} catch (_) {
|
|
7626
|
+
try {
|
|
7627
|
+
element.removeAttribute(name);
|
|
7628
|
+
} catch (_) {}
|
|
7629
|
+
}
|
|
7630
|
+
if (name === "is") {
|
|
7631
|
+
if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
|
|
7632
|
+
_forceRemove(element);
|
|
7633
|
+
} catch (_) {}
|
|
7634
|
+
else try {
|
|
7635
|
+
element.setAttribute(name, "");
|
|
7636
|
+
} catch (_) {}
|
|
7637
|
+
}
|
|
7638
|
+
};
|
|
7639
|
+
/**
|
|
7640
|
+
* _stripDisallowedAttributes
|
|
7641
|
+
*
|
|
7642
|
+
* Removes every attribute the active configuration does not allow from a
|
|
7643
|
+
* single element, using the same allowlist as the main attribute pass (so
|
|
7644
|
+
* `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
|
|
7645
|
+
* neutralise nodes that are being discarded from an in-place tree.
|
|
7646
|
+
*
|
|
7647
|
+
* @param element the element to strip
|
|
7648
|
+
*/
|
|
7649
|
+
const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
|
|
7650
|
+
const attributes = getAttributes(element);
|
|
7651
|
+
if (!attributes) return;
|
|
7652
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
7653
|
+
const attribute = attributes[i];
|
|
7654
|
+
const name = attribute && attribute.name;
|
|
7655
|
+
if (typeof name !== "string" || ALLOWED_ATTR[transformCaseFunc(name)]) continue;
|
|
7656
|
+
_stripAttributeNode(element, attribute, name);
|
|
7657
|
+
}
|
|
7658
|
+
};
|
|
7659
|
+
/**
|
|
7660
|
+
* _neutralizeSubtree
|
|
7661
|
+
*
|
|
7662
|
+
* Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
|
|
7663
|
+
* move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
|
|
7664
|
+
* namespace, comment, processing-instruction and KEEP_CONTENT:false removals
|
|
7665
|
+
* all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
|
|
7666
|
+
* those dropped nodes are detached from the caller's LIVE tree but a
|
|
7667
|
+
* handler-bearing original among them (an `<img onerror>`/`<video>` that was
|
|
7668
|
+
* loading) keeps its queued resource event, which fires in page scope after
|
|
7669
|
+
* sanitize returns. This walks a removed subtree and strips every attribute
|
|
7670
|
+
* the active configuration does not allow — so `on*` handlers are cancelled
|
|
7671
|
+
* through the SAME allowlist that governs kept nodes, not a separate `/^on/`
|
|
7672
|
+
* blocklist. Run synchronously before sanitize returns, i.e. before any
|
|
7673
|
+
* queued event can fire. Hook-free by design: these nodes leave the output,
|
|
7674
|
+
* so firing attribute hooks for them would be surprising. Clobber-safe reads;
|
|
7675
|
+
* a doomed clobbered node may shadow `removeAttribute` (its own attributes are
|
|
7676
|
+
* irrelevant — it is discarded — while its non-clobbered descendants, e.g.
|
|
7677
|
+
* the `<img>`, are reached and scrubbed).
|
|
7678
|
+
*
|
|
7679
|
+
* @param root the root of a removed subtree to neutralise
|
|
7680
|
+
*/
|
|
7681
|
+
const _neutralizeSubtree = function _neutralizeSubtree(root) {
|
|
7682
|
+
const stack = [root];
|
|
7683
|
+
while (stack.length > 0) {
|
|
7684
|
+
const node = stack.pop();
|
|
7685
|
+
if (_readNodeType(node) === NODE_TYPE.element) _stripDisallowedAttributes(node);
|
|
7686
|
+
const childNodes = getChildNodes(node);
|
|
7687
|
+
if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
|
|
7688
|
+
}
|
|
7689
|
+
};
|
|
7690
|
+
/**
|
|
7691
|
+
* _neutralizePatchLinkage
|
|
7692
|
+
*
|
|
7693
|
+
* IN_PLACE entry pre-pass (declarative-partial-updates / streaming
|
|
7694
|
+
* hardening, https://github.com/WICG/declarative-partial-updates).
|
|
7695
|
+
*
|
|
7696
|
+
* The main walk strips patch linkage (`for`/`patchsrc`) and removes range
|
|
7697
|
+
* markers (PIs / markup comments) node-by-node, in document order, AS it
|
|
7698
|
+
* reaches each node. On a live in-place root that leaves a window: from the
|
|
7699
|
+
* moment the root is connected until the walk arrives at a given node, that
|
|
7700
|
+
* node's linkage is live. A patch applied on connection/stream can fire as
|
|
7701
|
+
* a microtask during the walk and inject or teleport an unsanitized DOM
|
|
7702
|
+
* range into a region the iterator has already passed and will not revisit,
|
|
7703
|
+
* so the post-return "tree is sanitized" contract is violated. Sweep the
|
|
7704
|
+
* whole tree once up front and sever every linkage before the walk begins,
|
|
7705
|
+
* closing that window.
|
|
7706
|
+
*
|
|
7707
|
+
* This CANNOT undo a patch that already fired before sanitize ran — that is
|
|
7708
|
+
* the irreducible "do not IN_PLACE a live-connected attacker tree" caveat —
|
|
7709
|
+
* but it closes everything from sanitize-start onward. Gated on SAFE_FOR_XML
|
|
7710
|
+
* to group with the rest of the declarative-partial-updates handling and
|
|
7711
|
+
* stay overridable, consistent with the codebase.
|
|
7712
|
+
*
|
|
7713
|
+
* Clobber-safe traversal (cached childNodes getter); per-node try/catch so a
|
|
7714
|
+
* clobbered root cannot defeat the sweep of its non-clobbered descendants.
|
|
7715
|
+
*
|
|
7716
|
+
* NOTE (pending real-Chrome confirmation, see test/declarative-patch-probe
|
|
7717
|
+
* .html Q1): this mirrors the existing policy of keeping `for` on
|
|
7718
|
+
* <label>/<output>. If the shipping feature can drive a patch through a
|
|
7719
|
+
* surviving `for`-on-label/output + `id` pair, this pre-pass and the
|
|
7720
|
+
* attribute check at _isBasicCustomElement's caller must additionally drop
|
|
7721
|
+
* that pair on the IN_PLACE path. Left as-is until the taxonomy is verified.
|
|
7722
|
+
*
|
|
7723
|
+
* @param root the in-place root to sweep
|
|
7724
|
+
*/
|
|
7725
|
+
/**
|
|
7726
|
+
* Central policy for declarative-partial-updates patch-linkage attributes,
|
|
7727
|
+
* shared by the _neutralizePatchLinkage pre-pass and _isValidAttribute so
|
|
7728
|
+
* the two sites cannot drift: `patchsrc` always links, `for` links
|
|
7729
|
+
* everywhere except on <label>/<output>, and the whole policy is gated on
|
|
7730
|
+
* SAFE_FOR_XML (see the rationale block in _isValidAttribute).
|
|
7731
|
+
*
|
|
7732
|
+
* @param lcName the transformCaseFunc'd attribute name
|
|
7733
|
+
* @param lcTag the transformCaseFunc'd tag name of the carrying element
|
|
7734
|
+
* @return true if the attribute is patch linkage and must be dropped
|
|
7735
|
+
*/
|
|
7736
|
+
const _isPatchLinkageAttribute = function _isPatchLinkageAttribute(lcName, lcTag) {
|
|
7737
|
+
if (!SAFE_FOR_XML) return false;
|
|
7738
|
+
if (lcName === "patchsrc") return true;
|
|
7739
|
+
return lcName === "for" && lcTag !== "label" && lcTag !== "output";
|
|
7740
|
+
};
|
|
7741
|
+
const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
|
|
7742
|
+
if (!SAFE_FOR_XML) return;
|
|
7743
|
+
const stack = [root];
|
|
7744
|
+
while (stack.length > 0) {
|
|
7745
|
+
const node = stack.pop();
|
|
7746
|
+
const nodeType = _readNodeType(node);
|
|
7747
|
+
if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
|
|
7748
|
+
try {
|
|
7749
|
+
remove(node);
|
|
7750
|
+
} catch (_) {}
|
|
7751
|
+
continue;
|
|
7752
|
+
}
|
|
7753
|
+
if (nodeType === NODE_TYPE.element) {
|
|
7754
|
+
const element = node;
|
|
7755
|
+
const lcTag = transformCaseFunc(_readNodeName(node));
|
|
7756
|
+
try {
|
|
7757
|
+
if (element.hasAttribute && element.hasAttribute("patchsrc")) element.removeAttribute("patchsrc");
|
|
7758
|
+
if (element.hasAttribute && element.hasAttribute("for") && _isPatchLinkageAttribute("for", lcTag)) element.removeAttribute("for");
|
|
7759
|
+
} catch (_) {}
|
|
7760
|
+
}
|
|
7761
|
+
const childNodes = getChildNodes(node);
|
|
7762
|
+
if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
|
|
7763
|
+
}
|
|
7764
|
+
};
|
|
7765
|
+
/**
|
|
7766
|
+
* _initDocument
|
|
7767
|
+
*
|
|
7768
|
+
* @param dirty - a string of dirty markup
|
|
7769
|
+
* @return a DOM, filled with the dirty markup
|
|
7770
|
+
*/
|
|
7771
|
+
const _initDocument = function _initDocument(dirty) {
|
|
7772
|
+
let doc = null;
|
|
7773
|
+
let leadingWhitespace = null;
|
|
7774
|
+
if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
|
|
7775
|
+
else {
|
|
7776
|
+
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
|
7777
|
+
leadingWhitespace = matches && matches[0];
|
|
7778
|
+
}
|
|
7779
|
+
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>";
|
|
7780
|
+
const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
|
|
7781
|
+
if (NAMESPACE === HTML_NAMESPACE) try {
|
|
7782
|
+
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
7783
|
+
} catch (_) {}
|
|
7784
|
+
if (!doc || !doc.documentElement) {
|
|
7785
|
+
doc = implementation.createDocument(NAMESPACE, "template", null);
|
|
7786
|
+
try {
|
|
7787
|
+
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
7788
|
+
} catch (_) {}
|
|
7789
|
+
}
|
|
7790
|
+
const body = doc.body || doc.documentElement;
|
|
7791
|
+
if (dirty && leadingWhitespace) body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
7792
|
+
if (NAMESPACE === HTML_NAMESPACE) return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
|
7793
|
+
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
7794
|
+
};
|
|
7795
|
+
/**
|
|
7796
|
+
* Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
|
|
7797
|
+
*
|
|
7798
|
+
* @param root The root element or node to start traversing on.
|
|
7799
|
+
* @return The created NodeIterator
|
|
7800
|
+
*/
|
|
7801
|
+
const _createNodeIterator = function _createNodeIterator(root) {
|
|
7802
|
+
const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
|
|
7803
|
+
return createNodeIterator.call(doc || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
7804
|
+
};
|
|
7805
|
+
/**
|
|
7806
|
+
* Replace template expression syntax (mustache, ERB, template
|
|
7807
|
+
* literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
|
|
7808
|
+
* sites. Order matters: mustache, then ERB, then template literal.
|
|
7809
|
+
*
|
|
7810
|
+
* @param value the string to scrub
|
|
7811
|
+
* @returns the scrubbed string
|
|
7812
|
+
*/
|
|
7813
|
+
const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
|
|
7814
|
+
value = stringReplace(value, MUSTACHE_EXPR$1, " ");
|
|
7815
|
+
value = stringReplace(value, ERB_EXPR$1, " ");
|
|
7816
|
+
value = stringReplace(value, TMPLIT_EXPR$1, " ");
|
|
7817
|
+
return value;
|
|
7818
|
+
};
|
|
7819
|
+
/**
|
|
7820
|
+
* Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
|
|
7821
|
+
* character data of an element subtree. Used as the final safety net for
|
|
7822
|
+
* SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
|
|
7823
|
+
* which only form after text-node normalization (e.g. fragments split across
|
|
7824
|
+
* stripped elements) cannot survive into a template-evaluating framework.
|
|
7825
|
+
*
|
|
7826
|
+
* Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
|
|
7827
|
+
* in place rather than round-tripping through innerHTML. This preserves
|
|
7828
|
+
* descendant node references (important for IN_PLACE callers), avoids a
|
|
7829
|
+
* serialize/reparse cycle, and reads literal character data — which means
|
|
7830
|
+
* `<%...%>` in text content matches the ERB regex against its real bytes
|
|
7831
|
+
* instead of the HTML-entity-escaped form innerHTML would produce.
|
|
7832
|
+
*
|
|
7833
|
+
* Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
|
|
7834
|
+
* attributes is performed during the per-node `_sanitizeAttributes` pass.
|
|
7835
|
+
*
|
|
7836
|
+
* @param node The root element whose character data should be scrubbed.
|
|
7837
|
+
*/
|
|
7838
|
+
const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
|
|
7839
|
+
var _node$querySelectorAl;
|
|
7840
|
+
node.normalize();
|
|
7841
|
+
const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
|
|
7842
|
+
const walker = createNodeIterator.call(doc || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
|
|
7843
|
+
let currentNode = walker.nextNode();
|
|
7844
|
+
while (currentNode) {
|
|
7845
|
+
currentNode.data = _stripTemplateExpressions(currentNode.data);
|
|
7846
|
+
currentNode = walker.nextNode();
|
|
7847
|
+
}
|
|
7848
|
+
const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, "template");
|
|
7849
|
+
if (templates) arrayForEach(templates, (tmpl) => {
|
|
7850
|
+
if (_isDocumentFragment(tmpl.content)) _scrubTemplateExpressions2(tmpl.content);
|
|
7851
|
+
});
|
|
7852
|
+
};
|
|
7853
|
+
/**
|
|
7854
|
+
* _isClobbered
|
|
7855
|
+
*
|
|
7856
|
+
* Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
|
|
7857
|
+
* interface with [LegacyOverrideBuiltIns]; a descendant element with a
|
|
7858
|
+
* `name` attribute matching a prototype property shadows that property
|
|
7859
|
+
* on direct reads. We use this check at the IN_PLACE entry-point and
|
|
7860
|
+
* during attribute sanitization to refuse clobbered forms.
|
|
7861
|
+
*
|
|
7862
|
+
* @param element element to check for clobbering attacks
|
|
7863
|
+
* @return true if clobbered, false if safe
|
|
7864
|
+
*/
|
|
7865
|
+
const _isClobbered = function _isClobbered(element) {
|
|
7866
|
+
const realTagName = getNodeName ? getNodeName(element) : null;
|
|
7867
|
+
if (typeof realTagName !== "string") return false;
|
|
7868
|
+
if (transformCaseFunc(realTagName) !== "form") return false;
|
|
7869
|
+
return typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || element.attributes !== getAttributes(element) || typeof element.removeAttribute !== "function" || typeof element.removeAttributeNode !== "function" || typeof element.getAttributeNode !== "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);
|
|
7870
|
+
};
|
|
7871
|
+
/**
|
|
7872
|
+
* Checks whether the given value is a DocumentFragment from any realm.
|
|
7873
|
+
*
|
|
7874
|
+
* The realm-independent replacement reads `nodeType` through the cached
|
|
7875
|
+
* Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
|
|
7876
|
+
* constant (11). nodeType is a numeric value resolved from the node's
|
|
7877
|
+
* internal slot, identical across realms for the same kind of node.
|
|
7878
|
+
*
|
|
7879
|
+
* @param value object to check
|
|
7880
|
+
* @return true if value is a DocumentFragment-shaped node from any realm
|
|
7881
|
+
*/
|
|
7882
|
+
const _isDocumentFragment = function _isDocumentFragment(value) {
|
|
7883
|
+
if (!getNodeType || typeof value !== "object" || value === null) return false;
|
|
7884
|
+
try {
|
|
7885
|
+
return getNodeType(value) === NODE_TYPE.documentFragment;
|
|
7886
|
+
} catch (_) {
|
|
7887
|
+
return false;
|
|
7888
|
+
}
|
|
7889
|
+
};
|
|
7890
|
+
/**
|
|
7891
|
+
* Checks whether the given object is a DOM node, including nodes that
|
|
7892
|
+
* originate from a different window/realm (e.g. an iframe's
|
|
7893
|
+
* contentDocument). The previous `value instanceof Node` check was
|
|
7894
|
+
* realm-bound: nodes from a different window failed it, causing
|
|
7895
|
+
* sanitize() to silently stringify them and reset IN_PLACE to false,
|
|
7896
|
+
* returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
|
|
7897
|
+
*
|
|
7898
|
+
* @param value object to check whether it's a DOM node
|
|
7899
|
+
* @return true if value is a DOM node from any realm
|
|
7900
|
+
*/
|
|
7901
|
+
const _isNode = function _isNode(value) {
|
|
7902
|
+
if (!getNodeType || typeof value !== "object" || value === null) return false;
|
|
7903
|
+
try {
|
|
7904
|
+
return typeof getNodeType(value) === "number";
|
|
7905
|
+
} catch (_) {
|
|
7906
|
+
return false;
|
|
7907
|
+
}
|
|
7908
|
+
};
|
|
7909
|
+
function _executeHooks(hooks, currentNode, data) {
|
|
7910
|
+
if (hooks.length === 0) return;
|
|
7911
|
+
arrayForEach(hooks, (hook) => {
|
|
7912
|
+
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
7913
|
+
});
|
|
7914
|
+
}
|
|
7915
|
+
/**
|
|
7916
|
+
* Structural-threat checks that condemn a node regardless of the
|
|
7917
|
+
* allowlists: mXSS via namespace confusion, risky CSS construction,
|
|
7918
|
+
* processing instructions, markup-bearing comments. Pure predicate;
|
|
7919
|
+
* the caller removes. Check order is load-bearing.
|
|
7920
|
+
*
|
|
7921
|
+
* @param currentNode the node to inspect
|
|
7922
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
7923
|
+
* @return true if the node must be removed
|
|
7924
|
+
*/
|
|
7925
|
+
const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
|
|
7926
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
|
|
7927
|
+
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && LITERAL_TEXT_ELEMENTS[tagName] && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(LITERAL_TEXT_CLOSE[tagName], currentNode.textContent))) return true;
|
|
7928
|
+
if (currentNode.nodeType === NODE_TYPE.processingInstruction) return true;
|
|
7929
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
|
|
7930
|
+
return false;
|
|
7931
|
+
};
|
|
7932
|
+
/**
|
|
7933
|
+
* Evaluate a CUSTOM_ELEMENT_HANDLING check (a RegExp or a predicate
|
|
7934
|
+
* function, per the validation in _parseConfig) against a name.
|
|
7935
|
+
* Additional arguments are forwarded to predicate functions - the
|
|
7936
|
+
* attributeNameCheck predicate receives the tag name as its second
|
|
7937
|
+
* argument. A null/absent check never matches.
|
|
7938
|
+
*
|
|
7939
|
+
* @param check the configured tagNameCheck / attributeNameCheck value
|
|
7940
|
+
* @param name the name to test
|
|
7941
|
+
* @param args extra arguments forwarded to a predicate function
|
|
7942
|
+
* @return true if the check matches the name
|
|
7943
|
+
*/
|
|
7944
|
+
const _matchesNameCheck = function _matchesNameCheck(check, name) {
|
|
7945
|
+
if (check instanceof RegExp) return regExpTest(check, name);
|
|
7946
|
+
if (check instanceof Function) {
|
|
7947
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
|
|
7948
|
+
return Boolean(check(name, ...args));
|
|
7949
|
+
}
|
|
7950
|
+
return false;
|
|
7951
|
+
};
|
|
7952
|
+
/**
|
|
7953
|
+
* Handle a node whose tag is forbidden or not allowlisted: keep
|
|
7954
|
+
* allowed custom elements (false return exits _sanitizeElements
|
|
7955
|
+
* early - the namespace and fallback-tag removal checks are
|
|
7956
|
+
* intentionally skipped for kept custom elements), else hoist
|
|
7957
|
+
* content per KEEP_CONTENT and remove.
|
|
7958
|
+
*
|
|
7959
|
+
* A kept custom element is the ONLY case in which this function
|
|
7960
|
+
* returns false, so the caller uses that return value to run the
|
|
7961
|
+
* afterSanitizeElements hook on the kept element and keep the
|
|
7962
|
+
* element-hook lifecycle consistent with normal allowlisted
|
|
7963
|
+
* elements (GHSA-c2j3-45gr-mqc4).
|
|
7964
|
+
*
|
|
7965
|
+
* @param currentNode the disallowed node
|
|
7966
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
7967
|
+
* @return true if the node was removed, false if kept
|
|
7968
|
+
*/
|
|
7969
|
+
const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName, root) {
|
|
7970
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
|
|
7971
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
7972
|
+
const parentNode = getParentNode(currentNode);
|
|
7973
|
+
const childNodes = getChildNodes(currentNode);
|
|
7974
|
+
if (childNodes && parentNode) {
|
|
7975
|
+
const childCount = childNodes.length;
|
|
7976
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
7977
|
+
const hoisted = currentNode === root ? cloneNode(childNodes[i], true) : childNodes[i];
|
|
7978
|
+
parentNode.insertBefore(hoisted, getNextSibling(currentNode));
|
|
7979
|
+
}
|
|
7980
|
+
}
|
|
7981
|
+
}
|
|
7982
|
+
_forceRemove(currentNode);
|
|
7983
|
+
return true;
|
|
7984
|
+
};
|
|
7985
|
+
/**
|
|
7986
|
+
* Fork a hook-mutable allowlist off its shared binding the first time a
|
|
7987
|
+
* (possibly lazily-installed) uponSanitize* hook is about to see it, so the
|
|
7988
|
+
* hook cannot widen the per-instance default or the setConfig binding by
|
|
7989
|
+
* reference and leak past the call. Returns the set unchanged once it is
|
|
7990
|
+
* already call-local, so repeated calls across elements are idempotent.
|
|
7991
|
+
*
|
|
7992
|
+
* @param hookList the uponSanitize* hook array for this event
|
|
7993
|
+
* @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
|
|
7994
|
+
* @param defaultSet the per-instance DEFAULT_ALLOWED_* constant
|
|
7995
|
+
* @param setConfigSet the captured setConfig() binding, or null
|
|
7996
|
+
* @return a call-local clone if a hook is present and set is still shared,
|
|
7997
|
+
* else set unchanged
|
|
7998
|
+
*/
|
|
7999
|
+
const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
|
|
8000
|
+
if (hookList.length === 0) return set;
|
|
8001
|
+
return set === defaultSet || set === setConfigSet ? clone(set) : set;
|
|
8002
|
+
};
|
|
8003
|
+
/**
|
|
8004
|
+
* Shared guard for a node that a hook has detached from the walk tree,
|
|
8005
|
+
* used after each element-hook site in _sanitizeElements. Detaching is a
|
|
8006
|
+
* long-standing user pattern (issue #469; draw.io-style foreignObject
|
|
8007
|
+
* filtering). Per the cached, unclobberable parentNode getter the node is
|
|
8008
|
+
* genuinely out of the tree, so it can reach neither the serialized
|
|
8009
|
+
* output nor an IN_PLACE live tree; treat it as removed and stop
|
|
8010
|
+
* processing it. Without this guard, the unsafe-node / namespace checks
|
|
8011
|
+
* would call _forceRemove on a parentless node and hit the REPORT-3
|
|
8012
|
+
* fail-closed throw — which exists for nodes DOMPurify wants gone but
|
|
8013
|
+
* *cannot* detach (clobbered / parentless roots), the opposite of a node
|
|
8014
|
+
* that is already safely gone. The walk root is exempt: a detached
|
|
8015
|
+
* IN_PLACE root is legitimate input and must still be fully sanitized,
|
|
8016
|
+
* and a kill-decision on it must keep hitting the REPORT-3 throw.
|
|
8017
|
+
*
|
|
8018
|
+
* Nodes detached by hooks stay the hook's responsibility for placement:
|
|
8019
|
+
* they are not recorded in DOMPurify.removed, so the post-walk IN_PLACE
|
|
8020
|
+
* pass (which iterates DOMPurify.removed) does not reach them. But a
|
|
8021
|
+
* hook-detached subtree can still hold a queued resource-event handler -
|
|
8022
|
+
* e.g. an <img onload> that began loading when the caller built the live
|
|
8023
|
+
* tree - which fires in page scope after sanitize returns even though the
|
|
8024
|
+
* handler never reached the returned tree. That is the audit-5 F1 hazard,
|
|
8025
|
+
* and the documented node.remove() hook pattern walks straight into it.
|
|
8026
|
+
* So on the IN_PLACE path we neutralize the detached subtree inline,
|
|
8027
|
+
* stripping its non-allow-listed attributes before returning, exactly as
|
|
8028
|
+
* the post-walk pass does for _forceRemove'd subtrees.
|
|
8029
|
+
*
|
|
8030
|
+
* @param currentNode the node a hook may have detached
|
|
8031
|
+
* @param root the current walk root
|
|
8032
|
+
* @return true if the node is detached and now handled, false otherwise
|
|
8033
|
+
*/
|
|
8034
|
+
const _handleHookDetachedNode = function _handleHookDetachedNode(currentNode, root) {
|
|
8035
|
+
if (currentNode === root || getParentNode(currentNode) !== null) return false;
|
|
8036
|
+
if (IN_PLACE) _neutralizeSubtree(currentNode);
|
|
8037
|
+
return true;
|
|
8038
|
+
};
|
|
8039
|
+
/**
|
|
8040
|
+
* _sanitizeElements
|
|
8041
|
+
*
|
|
8042
|
+
* @protect nodeName
|
|
8043
|
+
* @protect textContent
|
|
8044
|
+
* @protect removeChild
|
|
8045
|
+
* @param currentNode to check for permission to exist
|
|
8046
|
+
* @return true if node was killed, false if left alive
|
|
8047
|
+
*/
|
|
8048
|
+
const _sanitizeElements = function _sanitizeElements(currentNode, root) {
|
|
8049
|
+
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
8050
|
+
if (_handleHookDetachedNode(currentNode, root)) return true;
|
|
8051
|
+
if (_isClobbered(currentNode)) {
|
|
8052
|
+
_forceRemove(currentNode);
|
|
8053
|
+
return true;
|
|
8054
|
+
}
|
|
8055
|
+
const tagName = transformCaseFunc(_readNodeName(currentNode));
|
|
8056
|
+
ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
|
|
8057
|
+
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
8058
|
+
tagName,
|
|
8059
|
+
allowedTags: ALLOWED_TAGS
|
|
8060
|
+
});
|
|
8061
|
+
if (_handleHookDetachedNode(currentNode, root)) return true;
|
|
8062
|
+
if (_isUnsafeNode(currentNode, tagName)) {
|
|
8063
|
+
_forceRemove(currentNode);
|
|
8064
|
+
return true;
|
|
8065
|
+
}
|
|
8066
|
+
if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
|
|
8067
|
+
const removed = _sanitizeDisallowedNode(currentNode, tagName, root);
|
|
8068
|
+
if (removed === false) _executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
8069
|
+
return removed;
|
|
8070
|
+
}
|
|
8071
|
+
if (_readNodeType(currentNode) === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
|
|
8072
|
+
_forceRemove(currentNode);
|
|
8073
|
+
return true;
|
|
8074
|
+
}
|
|
8075
|
+
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
|
|
8076
|
+
_forceRemove(currentNode);
|
|
8077
|
+
return true;
|
|
8078
|
+
}
|
|
8079
|
+
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
8080
|
+
const content = _stripTemplateExpressions(currentNode.textContent);
|
|
8081
|
+
if (currentNode.textContent !== content) {
|
|
8082
|
+
arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
|
|
8083
|
+
currentNode.textContent = content;
|
|
8084
|
+
}
|
|
8085
|
+
}
|
|
8086
|
+
_executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
8087
|
+
return false;
|
|
8088
|
+
};
|
|
8089
|
+
/**
|
|
8090
|
+
* _isValidAttribute
|
|
8091
|
+
*
|
|
8092
|
+
* @param lcTag Lowercase tag name of containing element.
|
|
8093
|
+
* @param lcName Lowercase attribute name.
|
|
8094
|
+
* @param value Attribute value.
|
|
8095
|
+
* @return Returns true if `value` is valid, otherwise false.
|
|
8096
|
+
*/
|
|
8097
|
+
const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
|
|
8098
|
+
if (FORBID_ATTR[lcName]) return false;
|
|
8099
|
+
if (_isPatchLinkageAttribute(lcName, lcTag)) return false;
|
|
8100
|
+
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document || value in formElement)) return false;
|
|
8101
|
+
const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
|
|
8102
|
+
if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) return true;
|
|
8103
|
+
if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) return true;
|
|
8104
|
+
if (!nameIsPermitted) return _isBasicCustomElement(lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName, lcTag) || lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value);
|
|
8105
|
+
if (URI_SAFE_ATTRIBUTES[lcName]) return true;
|
|
8106
|
+
if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
|
|
8107
|
+
if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) return true;
|
|
8108
|
+
if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
|
|
8109
|
+
return !value;
|
|
8110
|
+
};
|
|
8111
|
+
const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
|
|
8112
|
+
"annotation-xml",
|
|
8113
|
+
"color-profile",
|
|
8114
|
+
"font-face",
|
|
8115
|
+
"font-face-format",
|
|
8116
|
+
"font-face-name",
|
|
8117
|
+
"font-face-src",
|
|
8118
|
+
"font-face-uri",
|
|
8119
|
+
"missing-glyph"
|
|
8120
|
+
]);
|
|
8121
|
+
/**
|
|
8122
|
+
* _isBasicCustomElement
|
|
8123
|
+
* checks if at least one dash is included in tagName, and it's not the first char
|
|
8124
|
+
* for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
|
|
8125
|
+
*
|
|
8126
|
+
* @param tagName name of the tag of the node to sanitize
|
|
8127
|
+
* @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
|
|
8128
|
+
*/
|
|
8129
|
+
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
|
|
8130
|
+
return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
|
|
8131
|
+
};
|
|
8132
|
+
/**
|
|
8133
|
+
* Wrap an attribute value in the matching Trusted Types object when
|
|
8134
|
+
* the active policy requires it. Namespaced attributes pass through
|
|
8135
|
+
* unchanged (no TT support yet, see
|
|
8136
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
|
|
8137
|
+
*
|
|
8138
|
+
* @param lcTag lowercase tag name of the containing element
|
|
8139
|
+
* @param lcName lowercase attribute name
|
|
8140
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
8141
|
+
* @param value the attribute value to wrap
|
|
8142
|
+
* @return the value, wrapped when Trusted Types demand it
|
|
8143
|
+
*/
|
|
8144
|
+
const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
|
|
8145
|
+
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function" && !namespaceURI) switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
8146
|
+
case "TrustedHTML": return _createTrustedHTML(value);
|
|
8147
|
+
case "TrustedScriptURL": return _createTrustedScriptURL(value);
|
|
8148
|
+
}
|
|
8149
|
+
return value;
|
|
8150
|
+
};
|
|
8151
|
+
/**
|
|
8152
|
+
* Write a modified attribute value back onto the element. On
|
|
8153
|
+
* success, re-probe for clobbering introduced by the new value and
|
|
8154
|
+
* remove the element when found; otherwise, when this writeback is the
|
|
8155
|
+
* recreate half of the SANITIZE_NAMED_PROPS remove-and-recreate, pop the
|
|
8156
|
+
* removal entry that path recorded so it does not show as removed. On
|
|
8157
|
+
* failure, remove the attribute instead.
|
|
8158
|
+
*
|
|
8159
|
+
* Returns true only on a clean write (the value was set and the new value
|
|
8160
|
+
* introduced no clobbering). The caller uses that, together with its own
|
|
8161
|
+
* knowledge of whether this attribute pushed a DOMPurify.removed record, to
|
|
8162
|
+
* decide whether to pop that record. The pop must happen ONLY for the
|
|
8163
|
+
* named-prop remove-and-recreate; popping on any other value change (trim,
|
|
8164
|
+
* template scrubbing, Trusted Types) would consume an unrelated _forceRemove
|
|
8165
|
+
* subtree-cleanup record and let that detached subtree keep a live event
|
|
8166
|
+
* handler through the IN_PLACE neutralization pass (SO-001).
|
|
8167
|
+
*
|
|
8168
|
+
* @param currentNode the element carrying the attribute
|
|
8169
|
+
* @param name the attribute name as present on the element
|
|
8170
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
8171
|
+
* @param value the new attribute value
|
|
8172
|
+
* @return true if the value was written without introducing clobbering
|
|
8173
|
+
*/
|
|
8174
|
+
const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
|
|
8175
|
+
try {
|
|
8176
|
+
if (namespaceURI) currentNode.setAttributeNS(namespaceURI, name, value);
|
|
8177
|
+
else currentNode.setAttribute(name, value);
|
|
8178
|
+
if (_isClobbered(currentNode)) {
|
|
8179
|
+
_forceRemove(currentNode);
|
|
8180
|
+
return false;
|
|
8181
|
+
}
|
|
8182
|
+
return true;
|
|
8183
|
+
} catch (_) {
|
|
8184
|
+
_removeAttribute(name, currentNode);
|
|
8185
|
+
return false;
|
|
8186
|
+
}
|
|
8187
|
+
};
|
|
8188
|
+
/**
|
|
8189
|
+
* _sanitizeAttributes
|
|
8190
|
+
*
|
|
8191
|
+
* @protect attributes
|
|
8192
|
+
* @protect nodeName
|
|
8193
|
+
* @protect removeAttribute
|
|
8194
|
+
* @protect setAttribute
|
|
8195
|
+
*
|
|
8196
|
+
* @param currentNode to sanitize
|
|
8197
|
+
*/
|
|
8198
|
+
const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
|
8199
|
+
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
8200
|
+
const attributes = currentNode.attributes;
|
|
8201
|
+
if (!attributes || _isClobbered(currentNode)) return;
|
|
8202
|
+
ALLOWED_ATTR = _forkSharedAllowlist(hooks.uponSanitizeAttribute, ALLOWED_ATTR, DEFAULT_ALLOWED_ATTR, SET_CONFIG_ALLOWED_ATTR);
|
|
8203
|
+
const hookEvent = {
|
|
8204
|
+
attrName: "",
|
|
8205
|
+
attrValue: "",
|
|
8206
|
+
keepAttr: true,
|
|
8207
|
+
allowedAttributes: ALLOWED_ATTR,
|
|
8208
|
+
forceKeepAttr: void 0
|
|
8209
|
+
};
|
|
8210
|
+
let l = attributes.length;
|
|
8211
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
8212
|
+
while (l--) {
|
|
8213
|
+
const attr = attributes[l];
|
|
8214
|
+
const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
|
|
8215
|
+
const lcName = transformCaseFunc(name);
|
|
8216
|
+
const initValue = attrValue;
|
|
8217
|
+
let value = name === "value" ? initValue : stringTrim(initValue);
|
|
8218
|
+
let recreatedNamedProp = false;
|
|
8219
|
+
hookEvent.attrName = lcName;
|
|
8220
|
+
hookEvent.attrValue = value;
|
|
8221
|
+
hookEvent.keepAttr = true;
|
|
8222
|
+
hookEvent.forceKeepAttr = void 0;
|
|
8223
|
+
_executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
|
|
8224
|
+
value = hookEvent.attrValue;
|
|
8225
|
+
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name") && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
|
|
8226
|
+
_removeAttribute(name, currentNode, attr);
|
|
8227
|
+
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
8228
|
+
recreatedNamedProp = true;
|
|
8229
|
+
}
|
|
8230
|
+
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
|
|
8231
|
+
_removeAttribute(name, currentNode, attr);
|
|
8232
|
+
continue;
|
|
8233
|
+
}
|
|
8234
|
+
if (lcName === "attributename" && stringMatch(value, "href")) {
|
|
8235
|
+
_removeAttribute(name, currentNode, attr);
|
|
8236
|
+
continue;
|
|
8237
|
+
}
|
|
8238
|
+
if (hookEvent.forceKeepAttr) continue;
|
|
8239
|
+
if (!hookEvent.keepAttr) {
|
|
8240
|
+
_removeAttribute(name, currentNode, attr);
|
|
8241
|
+
continue;
|
|
8242
|
+
}
|
|
8243
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
|
|
8244
|
+
_removeAttribute(name, currentNode, attr);
|
|
8245
|
+
continue;
|
|
8246
|
+
}
|
|
8247
|
+
if (SAFE_FOR_TEMPLATES) value = _stripTemplateExpressions(value);
|
|
8248
|
+
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
8249
|
+
_removeAttribute(name, currentNode, attr);
|
|
8250
|
+
continue;
|
|
8251
|
+
}
|
|
8252
|
+
value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
|
|
8253
|
+
if (value !== initValue) {
|
|
8254
|
+
if (_setAttributeValue(currentNode, name, namespaceURI, value) && recreatedNamedProp) arrayPop(DOMPurify.removed);
|
|
8255
|
+
}
|
|
8256
|
+
}
|
|
8257
|
+
_executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
|
|
8258
|
+
};
|
|
8259
|
+
/**
|
|
8260
|
+
* _sanitizeShadowDOM
|
|
8261
|
+
*
|
|
8262
|
+
* @param fragment to iterate over recursively
|
|
8263
|
+
*/
|
|
8264
|
+
const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
|
|
8265
|
+
let shadowNode = null;
|
|
8266
|
+
const shadowIterator = _createNodeIterator(fragment);
|
|
8267
|
+
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
8268
|
+
while (shadowNode = shadowIterator.nextNode()) {
|
|
8269
|
+
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
8270
|
+
_sanitizeElements(shadowNode, fragment);
|
|
8271
|
+
_sanitizeAttributes(shadowNode);
|
|
8272
|
+
if (_isDocumentFragment(shadowNode.content)) _sanitizeShadowDOM2(shadowNode.content);
|
|
8273
|
+
if (_readNodeType(shadowNode) === NODE_TYPE.element) {
|
|
8274
|
+
const innerSr = getShadowRoot(shadowNode);
|
|
8275
|
+
if (_isDocumentFragment(innerSr)) {
|
|
8276
|
+
_sanitizeAttachedShadowRoots(innerSr);
|
|
8277
|
+
_sanitizeShadowDOM2(innerSr);
|
|
8278
|
+
}
|
|
8279
|
+
}
|
|
8280
|
+
}
|
|
8281
|
+
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
8282
|
+
};
|
|
8283
|
+
/**
|
|
8284
|
+
* _sanitizeAttachedShadowRoots
|
|
8285
|
+
*
|
|
8286
|
+
* Walks `root` and feeds every attached shadow root we encounter into
|
|
8287
|
+
* the existing _sanitizeShadowDOM pipeline. The default node iterator
|
|
8288
|
+
* does not descend into shadow trees, so nodes inside an attached
|
|
8289
|
+
* shadow root would otherwise be skipped entirely.
|
|
8290
|
+
*
|
|
8291
|
+
* Two real input paths put attached shadow roots in front of us:
|
|
8292
|
+
* 1. IN_PLACE on a DOM node that already has shadow roots attached.
|
|
8293
|
+
* 2. DOM-node input where importNode(dirty, true) deep-clones the
|
|
8294
|
+
* shadow root because it was created with `clonable: true`.
|
|
8295
|
+
*
|
|
8296
|
+
* This pass runs once, up front, so the main iteration loop (and the
|
|
8297
|
+
* existing _sanitizeShadowDOM template-content recursion) stay
|
|
8298
|
+
* untouched — string-input paths are not affected.
|
|
8299
|
+
*
|
|
8300
|
+
* @param root the subtree root to walk for attached shadow roots
|
|
8301
|
+
*/
|
|
8302
|
+
const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
|
|
8303
|
+
const stack = [{
|
|
8304
|
+
node: root,
|
|
8305
|
+
shadow: null
|
|
8306
|
+
}];
|
|
8307
|
+
while (stack.length > 0) {
|
|
8308
|
+
const item = stack.pop();
|
|
8309
|
+
if (item.shadow) {
|
|
8310
|
+
_sanitizeShadowDOM2(item.shadow);
|
|
8311
|
+
continue;
|
|
8312
|
+
}
|
|
8313
|
+
const node = item.node;
|
|
8314
|
+
const isElement = _readNodeType(node) === NODE_TYPE.element;
|
|
8315
|
+
const childNodes = getChildNodes(node);
|
|
8316
|
+
if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push({
|
|
8317
|
+
node: childNodes[i],
|
|
8318
|
+
shadow: null
|
|
8319
|
+
});
|
|
8320
|
+
if (isElement) {
|
|
8321
|
+
const rootName = getNodeName ? getNodeName(node) : null;
|
|
8322
|
+
if (typeof rootName === "string" && transformCaseFunc(rootName) === "template") {
|
|
8323
|
+
const content = node.content;
|
|
8324
|
+
if (_isDocumentFragment(content)) stack.push({
|
|
8325
|
+
node: content,
|
|
8326
|
+
shadow: null
|
|
8327
|
+
});
|
|
8328
|
+
}
|
|
8329
|
+
}
|
|
8330
|
+
if (isElement) {
|
|
8331
|
+
const sr = getShadowRoot(node);
|
|
8332
|
+
if (_isDocumentFragment(sr)) stack.push({
|
|
8333
|
+
node: null,
|
|
8334
|
+
shadow: sr
|
|
8335
|
+
}, {
|
|
8336
|
+
node: sr,
|
|
8337
|
+
shadow: null
|
|
8338
|
+
});
|
|
8339
|
+
}
|
|
8340
|
+
}
|
|
8341
|
+
};
|
|
8342
|
+
DOMPurify.sanitize = function(dirty) {
|
|
8343
|
+
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
8344
|
+
let body = null;
|
|
8345
|
+
let importedNode = null;
|
|
8346
|
+
let currentNode = null;
|
|
8347
|
+
let returnNode = null;
|
|
8348
|
+
IS_EMPTY_INPUT = !dirty;
|
|
8349
|
+
if (IS_EMPTY_INPUT) dirty = "<!-->";
|
|
8350
|
+
if (typeof dirty !== "string" && !_isNode(dirty)) {
|
|
8351
|
+
dirty = stringifyValue(dirty);
|
|
8352
|
+
if (typeof dirty !== "string") throw typeErrorCreate("dirty is not a string, aborting");
|
|
8353
|
+
}
|
|
8354
|
+
if (!DOMPurify.isSupported) return dirty;
|
|
8355
|
+
if (SET_CONFIG) {
|
|
8356
|
+
ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
|
|
8357
|
+
ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
|
|
8358
|
+
} else _parseConfig(cfg);
|
|
8359
|
+
if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
8360
|
+
if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
8361
|
+
DOMPurify.removed = [];
|
|
8362
|
+
const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
|
|
8363
|
+
if (inPlace) {
|
|
8364
|
+
_neutralizePatchLinkage(dirty);
|
|
8365
|
+
const nn = _readNodeName(dirty);
|
|
8366
|
+
if (typeof nn === "string") {
|
|
8367
|
+
const tagName = transformCaseFunc(nn);
|
|
8368
|
+
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
8369
|
+
_neutralizeRoot(dirty);
|
|
8370
|
+
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
|
8371
|
+
}
|
|
8372
|
+
}
|
|
8373
|
+
if (_isClobbered(dirty)) {
|
|
8374
|
+
_neutralizeRoot(dirty);
|
|
8375
|
+
throw typeErrorCreate("root node is clobbered and cannot be sanitized in-place");
|
|
8376
|
+
}
|
|
8377
|
+
try {
|
|
8378
|
+
_sanitizeAttachedShadowRoots(dirty);
|
|
8379
|
+
} catch (error) {
|
|
8380
|
+
_neutralizeRoot(dirty);
|
|
8381
|
+
throw error;
|
|
8382
|
+
}
|
|
8383
|
+
} else if (_isNode(dirty)) {
|
|
8384
|
+
body = _initDocument("<!---->");
|
|
8385
|
+
importedNode = body.ownerDocument.importNode(dirty, true);
|
|
8386
|
+
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") body = importedNode;
|
|
8387
|
+
else if (importedNode.nodeName === "HTML") body = importedNode;
|
|
8388
|
+
else body.appendChild(importedNode);
|
|
8389
|
+
_sanitizeAttachedShadowRoots(body);
|
|
8390
|
+
} else {
|
|
8391
|
+
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
|
|
8392
|
+
body = _initDocument(dirty);
|
|
8393
|
+
if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
|
8394
|
+
}
|
|
8395
|
+
if (body && FORCE_BODY) _forceRemove(body.firstChild);
|
|
8396
|
+
const walkRoot = inPlace ? dirty : body;
|
|
8397
|
+
try {
|
|
8398
|
+
const nodeIterator = _createNodeIterator(walkRoot);
|
|
8399
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
8400
|
+
_sanitizeElements(currentNode, walkRoot);
|
|
8401
|
+
_sanitizeAttributes(currentNode);
|
|
8402
|
+
if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
|
|
8403
|
+
}
|
|
8404
|
+
} catch (error) {
|
|
8405
|
+
if (inPlace) {
|
|
8406
|
+
_neutralizeRoot(dirty);
|
|
8407
|
+
arrayForEach(DOMPurify.removed, (entry) => {
|
|
8408
|
+
if (entry.element) _neutralizeSubtree(entry.element);
|
|
8409
|
+
});
|
|
8410
|
+
}
|
|
8411
|
+
throw error;
|
|
8412
|
+
}
|
|
8413
|
+
if (inPlace) {
|
|
8414
|
+
arrayForEach(DOMPurify.removed, (entry) => {
|
|
8415
|
+
if (entry.element) _neutralizeSubtree(entry.element);
|
|
8416
|
+
});
|
|
8417
|
+
if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(dirty);
|
|
8418
|
+
return dirty;
|
|
8419
|
+
}
|
|
8420
|
+
if (RETURN_DOM) {
|
|
8421
|
+
if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(body);
|
|
8422
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
8423
|
+
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
8424
|
+
while (body.firstChild) returnNode.appendChild(body.firstChild);
|
|
8425
|
+
} else returnNode = body;
|
|
8426
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
|
|
8427
|
+
return returnNode;
|
|
8428
|
+
}
|
|
8429
|
+
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
8430
|
+
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;
|
|
8431
|
+
if (SAFE_FOR_TEMPLATES) serializedHTML = _stripTemplateExpressions(serializedHTML);
|
|
8432
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
|
|
8433
|
+
};
|
|
8434
|
+
DOMPurify.setConfig = function() {
|
|
8435
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
8436
|
+
_parseConfig(cfg);
|
|
8437
|
+
SET_CONFIG = true;
|
|
8438
|
+
SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
|
|
8439
|
+
SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
|
|
8440
|
+
};
|
|
8441
|
+
DOMPurify.clearConfig = function() {
|
|
8442
|
+
CONFIG = null;
|
|
8443
|
+
SET_CONFIG = false;
|
|
8444
|
+
SET_CONFIG_ALLOWED_TAGS = null;
|
|
8445
|
+
SET_CONFIG_ALLOWED_ATTR = null;
|
|
8446
|
+
trustedTypesPolicy = defaultTrustedTypesPolicy;
|
|
8447
|
+
emptyHTML = "";
|
|
8448
|
+
};
|
|
8449
|
+
DOMPurify.isValidAttribute = function(tag, attr, value) {
|
|
8450
|
+
if (!CONFIG) _parseConfig({});
|
|
8451
|
+
const lcTag = transformCaseFunc(tag);
|
|
8452
|
+
const lcName = transformCaseFunc(attr);
|
|
8453
|
+
return _isValidAttribute(lcTag, lcName, value);
|
|
8454
|
+
};
|
|
8455
|
+
DOMPurify.addHook = function(entryPoint, hookFunction) {
|
|
8456
|
+
if (typeof hookFunction !== "function") return;
|
|
8457
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) return;
|
|
8458
|
+
arrayPush(hooks[entryPoint], hookFunction);
|
|
8459
|
+
};
|
|
8460
|
+
DOMPurify.removeHook = function(entryPoint, hookFunction) {
|
|
8461
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) return;
|
|
8462
|
+
if (hookFunction !== void 0) {
|
|
8463
|
+
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
8464
|
+
return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
8465
|
+
}
|
|
8466
|
+
return arrayPop(hooks[entryPoint]);
|
|
8467
|
+
};
|
|
8468
|
+
DOMPurify.removeHooks = function(entryPoint) {
|
|
8469
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) return;
|
|
8470
|
+
hooks[entryPoint] = [];
|
|
8471
|
+
};
|
|
8472
|
+
DOMPurify.removeAllHooks = function() {
|
|
8473
|
+
hooks = _createHooksMap();
|
|
8474
|
+
};
|
|
8475
|
+
return DOMPurify;
|
|
6111
8476
|
}
|
|
8477
|
+
var purify = createDOMPurify();
|
|
8478
|
+
//#endregion
|
|
8479
|
+
//#region src/editor/extensions/smart-paste.ts
|
|
8480
|
+
var HTML_DOCUMENT_PATTERN = /<!doctype\s+html\b|<(?:html|body)\b[^>]*>/i;
|
|
8481
|
+
var HTML_PAIRED_TAG_PATTERN = /<(h[1-6]|p|ul|ol|li|blockquote|table|thead|tbody|tfoot|tr|th|td|figure|figcaption|article|section|header|footer|main|div|span|strong|em|b|i|a|code|pre)\b[^>]*>[\s\S]*?<\/\1\s*>/i;
|
|
8482
|
+
var HTML_VOID_TAG_PATTERN = /<(?:img|hr|br)\b[^>]*\/?\s*>/i;
|
|
8483
|
+
var markdown = new MarkdownIt({
|
|
8484
|
+
html: true,
|
|
8485
|
+
linkify: false,
|
|
8486
|
+
typographer: false
|
|
8487
|
+
});
|
|
6112
8488
|
function selectionIsInsideCodeBlock(parentTypeName) {
|
|
6113
8489
|
return parentTypeName === "codeBlock";
|
|
6114
8490
|
}
|
|
6115
8491
|
function looksLikeDocumentHtml(value) {
|
|
6116
|
-
|
|
8492
|
+
const match = value.match(HTML_DOCUMENT_PATTERN) ?? value.match(HTML_PAIRED_TAG_PATTERN) ?? value.match(HTML_VOID_TAG_PATTERN);
|
|
8493
|
+
if (!match) return false;
|
|
8494
|
+
const prefix = value.slice(0, match.index).replace(/<!--[^]*?-->/g, "").replace(/<\?[^]*?\?>/g, "").trim();
|
|
8495
|
+
return !/[={};`"']|=>|\b(?:const|let|var|return|function|class|import|export)\b/.test(prefix);
|
|
6117
8496
|
}
|
|
6118
8497
|
function looksLikeMarkdown(value) {
|
|
6119
|
-
|
|
8498
|
+
const tokens = markdown.parse(value, {});
|
|
8499
|
+
return tokens.some((token, index) => {
|
|
8500
|
+
if (token.type === "heading_open") return Boolean(tokens[index + 1]?.content.trim());
|
|
8501
|
+
if ([
|
|
8502
|
+
"bullet_list_open",
|
|
8503
|
+
"ordered_list_open",
|
|
8504
|
+
"blockquote_open",
|
|
8505
|
+
"fence",
|
|
8506
|
+
"table_open"
|
|
8507
|
+
].includes(token.type)) return true;
|
|
8508
|
+
return token.type === "inline" && Boolean(token.children?.some((child) => [
|
|
8509
|
+
"link_open",
|
|
8510
|
+
"image",
|
|
8511
|
+
"strong_open"
|
|
8512
|
+
].includes(child.type)));
|
|
8513
|
+
});
|
|
6120
8514
|
}
|
|
6121
8515
|
function parseHtmlSlice(schema, value) {
|
|
6122
8516
|
const parsed = new globalThis.DOMParser().parseFromString(value, "text/html");
|
|
6123
|
-
parsed.querySelectorAll(UNSAFE_HTML_SELECTOR).forEach((element) => element.remove());
|
|
6124
8517
|
const container = document.createElement("div");
|
|
6125
|
-
container.append(
|
|
8518
|
+
container.append(purify.sanitize(parsed.body.innerHTML, {
|
|
8519
|
+
USE_PROFILES: { html: true },
|
|
8520
|
+
FORBID_TAGS: [
|
|
8521
|
+
"style",
|
|
8522
|
+
"script",
|
|
8523
|
+
"iframe",
|
|
8524
|
+
"object",
|
|
8525
|
+
"embed",
|
|
8526
|
+
"template"
|
|
8527
|
+
],
|
|
8528
|
+
FORBID_ATTR: ["style"],
|
|
8529
|
+
RETURN_DOM_FRAGMENT: true
|
|
8530
|
+
}));
|
|
6126
8531
|
if (!container.textContent?.trim() && !container.querySelector("img, hr")) return null;
|
|
6127
8532
|
return DOMParser.fromSchema(schema).parseSlice(container, { preserveWhitespace: false });
|
|
6128
8533
|
}
|
|
6129
|
-
function documentSlice(schema, plainText
|
|
6130
|
-
if (
|
|
6131
|
-
if (
|
|
6132
|
-
if (!mode && !richHtml && looksLikeDocumentHtml(plainText)) return parseHtmlSlice(schema, plainText);
|
|
6133
|
-
if (!mode && !richHtml && looksLikeMarkdown(plainText)) return parseHtmlSlice(schema, markdown.render(plainText));
|
|
8534
|
+
function documentSlice(schema, plainText) {
|
|
8535
|
+
if (looksLikeMarkdown(plainText)) return parseHtmlSlice(schema, markdown.render(plainText));
|
|
8536
|
+
if (looksLikeDocumentHtml(plainText)) return parseHtmlSlice(schema, plainText);
|
|
6134
8537
|
return null;
|
|
6135
8538
|
}
|
|
6136
8539
|
/**
|
|
6137
|
-
* Interprets document markup
|
|
6138
|
-
*
|
|
8540
|
+
* Interprets recognizable document markup before Tiptap's generic paste
|
|
8541
|
+
* handling can turn preformatted clipboard HTML into a literal code block.
|
|
6139
8542
|
*
|
|
6140
|
-
*
|
|
6141
|
-
*
|
|
8543
|
+
* Document content is detected from text, not source-editor clipboard metadata.
|
|
8544
|
+
* Unrecognized source code and explicit code-block context remain literal.
|
|
6142
8545
|
*
|
|
6143
8546
|
* @contract Recognized document markup is sanitized and dispatched as one paste
|
|
6144
8547
|
* transaction; every unrecognized or code-oriented payload returns control to
|
|
@@ -6153,10 +8556,7 @@ var LoomaSmartPaste = Extension.create({
|
|
|
6153
8556
|
if (selectionIsInsideCodeBlock(view.state.selection.$from.parent.type.name)) return false;
|
|
6154
8557
|
const plainText = event.clipboardData.getData("text/plain");
|
|
6155
8558
|
if (!plainText.trim()) return false;
|
|
6156
|
-
const
|
|
6157
|
-
const mode = sourceEditorMode(event);
|
|
6158
|
-
if (mode && !DOCUMENT_MARKUP_MODES.has(mode)) return false;
|
|
6159
|
-
const slice = documentSlice(view.state.schema, plainText, richHtml, mode);
|
|
8559
|
+
const slice = documentSlice(view.state.schema, plainText);
|
|
6160
8560
|
if (!slice) return false;
|
|
6161
8561
|
const transaction = view.state.tr.replaceSelection(slice).scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste");
|
|
6162
8562
|
view.dispatch(transaction);
|