@vaadin/bundles 24.10.10 → 24.10.11
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/package.json +140 -140
- package/vaadin-bundle.json +1624 -1623
- package/vaadin.js +1294 -1314
- package/vaadin.js.map +1 -1
- package/vendors-node_modules_dompurify_dist_purify_es_mjs.js +181 -267
- package/vendors-node_modules_dompurify_dist_purify_es_mjs.js.map +1 -1
- package/vendors-node_modules_dompurify_dist_purify_js.js +181 -267
- package/vendors-node_modules_dompurify_dist_purify_js.js.map +1 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
\***********************************************/
|
|
7
7
|
/***/ (function(module) {
|
|
8
8
|
|
|
9
|
-
/*! @license DOMPurify 3.4.
|
|
9
|
+
/*! @license DOMPurify 3.4.18 | (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.18/LICENSE */
|
|
10
10
|
(function(global, factory) {
|
|
11
11
|
true ? module.exports = factory() : 0;
|
|
12
12
|
})(this, function() {
|
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
return this._invoke("return", e);
|
|
106
106
|
};
|
|
107
107
|
const entries = Object.entries;
|
|
108
|
+
const objectKeys = Object.keys;
|
|
108
109
|
const setPrototypeOf = Object.setPrototypeOf;
|
|
109
110
|
const isFrozen = Object.isFrozen;
|
|
110
111
|
const getPrototypeOf = Object.getPrototypeOf;
|
|
@@ -130,7 +131,6 @@
|
|
|
130
131
|
return new Func(...args);
|
|
131
132
|
};
|
|
132
133
|
const arrayForEach = unapply(Array.prototype.forEach);
|
|
133
|
-
Array.prototype.indexOf;
|
|
134
134
|
const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
|
|
135
135
|
const arrayPop = unapply(Array.prototype.pop);
|
|
136
136
|
const arrayPush = unapply(Array.prototype.push);
|
|
@@ -152,7 +152,11 @@
|
|
|
152
152
|
const symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
|
|
153
153
|
const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
154
154
|
const objectToString = unapply(Object.prototype.toString);
|
|
155
|
-
const
|
|
155
|
+
const regExpTestRaw = RegExp.prototype.test;
|
|
156
|
+
const regExpTest = function regExpTest(regExp, value) {
|
|
157
|
+
if (regExp instanceof RegExp) regExp.lastIndex = 0;
|
|
158
|
+
return apply(regExpTestRaw, regExp, [value]);
|
|
159
|
+
};
|
|
156
160
|
const typeErrorCreate = unconstruct(TypeError);
|
|
157
161
|
/**
|
|
158
162
|
* Creates a new function that calls the given function with a specified thisArg and arguments.
|
|
@@ -162,7 +166,6 @@
|
|
|
162
166
|
*/
|
|
163
167
|
function unapply(func) {
|
|
164
168
|
return function(thisArg) {
|
|
165
|
-
if (thisArg instanceof RegExp) thisArg.lastIndex = 0;
|
|
166
169
|
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
|
|
167
170
|
return apply(func, thisArg, args);
|
|
168
171
|
};
|
|
@@ -236,6 +239,19 @@
|
|
|
236
239
|
return newObject;
|
|
237
240
|
}
|
|
238
241
|
/**
|
|
242
|
+
* Copy a flat lookup table
|
|
243
|
+
*
|
|
244
|
+
* @param set - The set to copy.
|
|
245
|
+
* @returns A new prototype-free set with the same entries.
|
|
246
|
+
*/
|
|
247
|
+
function cloneSet(set) {
|
|
248
|
+
const newSet = create(null);
|
|
249
|
+
const keys = objectKeys(set);
|
|
250
|
+
let l = keys.length;
|
|
251
|
+
while (l--) newSet[keys[l]] = set[keys[l]];
|
|
252
|
+
return newSet;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
239
255
|
* Convert non-node values into strings without depending on direct property access.
|
|
240
256
|
*
|
|
241
257
|
* @param value - The value to stringify.
|
|
@@ -304,6 +320,7 @@
|
|
|
304
320
|
return null;
|
|
305
321
|
}
|
|
306
322
|
function isRegex(value) {
|
|
323
|
+
if (!value) return false;
|
|
307
324
|
try {
|
|
308
325
|
regExpTest(value, "");
|
|
309
326
|
return true;
|
|
@@ -446,8 +463,6 @@
|
|
|
446
463
|
"defs",
|
|
447
464
|
"desc",
|
|
448
465
|
"ellipse",
|
|
449
|
-
"enterkeyhint",
|
|
450
|
-
"exportparts",
|
|
451
466
|
"filter",
|
|
452
467
|
"font",
|
|
453
468
|
"g",
|
|
@@ -455,14 +470,12 @@
|
|
|
455
470
|
"glyphref",
|
|
456
471
|
"hkern",
|
|
457
472
|
"image",
|
|
458
|
-
"inputmode",
|
|
459
473
|
"line",
|
|
460
474
|
"lineargradient",
|
|
461
475
|
"marker",
|
|
462
476
|
"mask",
|
|
463
477
|
"metadata",
|
|
464
478
|
"mpath",
|
|
465
|
-
"part",
|
|
466
479
|
"path",
|
|
467
480
|
"pattern",
|
|
468
481
|
"polygon",
|
|
@@ -962,6 +975,7 @@
|
|
|
962
975
|
const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
|
|
963
976
|
const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
|
|
964
977
|
const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
|
|
978
|
+
const TMPL_MARKER_SERIALIZED = seal(/{{|}}|\${|<%|%>|<%|%>/);
|
|
965
979
|
const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
|
|
966
980
|
const ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
|
967
981
|
const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
|
|
@@ -973,19 +987,15 @@
|
|
|
973
987
|
const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
|
|
974
988
|
const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
|
|
975
989
|
const SELF_CLOSING_TAG = seal(/\/>/i);
|
|
990
|
+
const ATTR_VALUE_BREAKOUT = seal(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i);
|
|
991
|
+
const LEADING_WHITESPACE = seal(/^[\r\n\t ]+/);
|
|
976
992
|
const NODE_TYPE = {
|
|
977
993
|
element: 1,
|
|
978
|
-
attribute: 2,
|
|
979
994
|
text: 3,
|
|
980
|
-
cdataSection: 4,
|
|
981
|
-
entityReference: 5,
|
|
982
|
-
entityNode: 6,
|
|
983
995
|
processingInstruction: 7,
|
|
984
996
|
comment: 8,
|
|
985
997
|
document: 9,
|
|
986
|
-
|
|
987
|
-
documentFragment: 11,
|
|
988
|
-
notation: 12
|
|
998
|
+
documentFragment: 11
|
|
989
999
|
};
|
|
990
1000
|
const LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, [
|
|
991
1001
|
"style",
|
|
@@ -1042,39 +1052,33 @@
|
|
|
1042
1052
|
};
|
|
1043
1053
|
};
|
|
1044
1054
|
/**
|
|
1045
|
-
* Resolve a set-valued configuration option
|
|
1046
|
-
* cfg[key] when it is an own array property (seeded with a clone of
|
|
1047
|
-
* options.base when given, case-normalized via options.transform),
|
|
1048
|
-
* the fallback set otherwise.
|
|
1055
|
+
* Resolve a set-valued configuration option.
|
|
1049
1056
|
*
|
|
1050
1057
|
* @param cfg the cloned, prototype-free configuration object
|
|
1051
1058
|
* @param key the configuration property to read
|
|
1052
1059
|
* @param fallback the set to use when the option is absent or not an array
|
|
1053
|
-
* @param options transform and optional base set to
|
|
1054
|
-
* @returns
|
|
1060
|
+
* @param options case transform, and an optional base set to extend a copy of
|
|
1061
|
+
* @returns a fresh set built from cfg[key], or the fallback
|
|
1055
1062
|
*/
|
|
1056
1063
|
const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
|
|
1057
|
-
return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ?
|
|
1064
|
+
return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? cloneSet(options.base) : {}, cfg[key], options.transform) : fallback;
|
|
1058
1065
|
};
|
|
1059
1066
|
/**
|
|
1060
|
-
* Resolve an object-valued configuration option
|
|
1061
|
-
* of cfg[key] when it is an own, truthy object property, else a fresh
|
|
1062
|
-
* fallback built by makeFallback (fresh on every parse, so a previous
|
|
1063
|
-
* parse can never leak state into the next one).
|
|
1067
|
+
* Resolve an object-valued configuration option.
|
|
1064
1068
|
*
|
|
1065
1069
|
* @param cfg the cloned, prototype-free configuration object
|
|
1066
1070
|
* @param key the configuration property to read
|
|
1067
|
-
* @param
|
|
1068
|
-
* @returns the
|
|
1071
|
+
* @param fallback the read-only value to use when the option is absent
|
|
1072
|
+
* @returns a prototype-free clone of cfg[key], or the fallback
|
|
1069
1073
|
*/
|
|
1070
|
-
const _resolveObjectOption = function _resolveObjectOption(cfg, key,
|
|
1074
|
+
const _resolveObjectOption = function _resolveObjectOption(cfg, key, fallback) {
|
|
1071
1075
|
const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
|
|
1072
|
-
return value && typeof value === "object" ? clone(value) :
|
|
1076
|
+
return value && typeof value === "object" ? clone(value) : fallback;
|
|
1073
1077
|
};
|
|
1074
1078
|
function createDOMPurify() {
|
|
1075
1079
|
let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
1076
1080
|
const DOMPurify = (root) => createDOMPurify(root);
|
|
1077
|
-
DOMPurify.version = "3.4.
|
|
1081
|
+
DOMPurify.version = "3.4.18";
|
|
1078
1082
|
DOMPurify.removed = [];
|
|
1079
1083
|
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
|
|
1080
1084
|
DOMPurify.isSupported = false;
|
|
@@ -1083,11 +1087,7 @@
|
|
|
1083
1087
|
let document = window.document;
|
|
1084
1088
|
const originalDocument = document;
|
|
1085
1089
|
const currentScript = originalDocument.currentScript;
|
|
1086
|
-
window.
|
|
1087
|
-
const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter;
|
|
1088
|
-
window.NamedNodeMap === void 0 && (window.NamedNodeMap || window.MozNamedAttrMap);
|
|
1089
|
-
window.HTMLFormElement;
|
|
1090
|
-
const DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
|
|
1090
|
+
const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter, DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
|
|
1091
1091
|
const ElementPrototype = Element.prototype;
|
|
1092
1092
|
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
|
1093
1093
|
const remove = lookupGetter(ElementPrototype, "remove");
|
|
@@ -1131,6 +1131,9 @@
|
|
|
1131
1131
|
IN_TRUSTED_TYPES_POLICY--;
|
|
1132
1132
|
}
|
|
1133
1133
|
};
|
|
1134
|
+
const _signOutput = function _signOutput(html) {
|
|
1135
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(html) : html;
|
|
1136
|
+
};
|
|
1134
1137
|
const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
|
|
1135
1138
|
_assertNotInTrustedTypesPolicy();
|
|
1136
1139
|
IN_TRUSTED_TYPES_POLICY++;
|
|
@@ -1175,26 +1178,7 @@
|
|
|
1175
1178
|
...mathMl,
|
|
1176
1179
|
...xml
|
|
1177
1180
|
]);
|
|
1178
|
-
let CUSTOM_ELEMENT_HANDLING =
|
|
1179
|
-
tagNameCheck: {
|
|
1180
|
-
writable: true,
|
|
1181
|
-
configurable: false,
|
|
1182
|
-
enumerable: true,
|
|
1183
|
-
value: null
|
|
1184
|
-
},
|
|
1185
|
-
attributeNameCheck: {
|
|
1186
|
-
writable: true,
|
|
1187
|
-
configurable: false,
|
|
1188
|
-
enumerable: true,
|
|
1189
|
-
value: null
|
|
1190
|
-
},
|
|
1191
|
-
allowCustomizedBuiltInElements: {
|
|
1192
|
-
writable: true,
|
|
1193
|
-
configurable: false,
|
|
1194
|
-
enumerable: true,
|
|
1195
|
-
value: false
|
|
1196
|
-
}
|
|
1197
|
-
}));
|
|
1181
|
+
let CUSTOM_ELEMENT_HANDLING = null;
|
|
1198
1182
|
let FORBID_TAGS = null;
|
|
1199
1183
|
let FORBID_ATTR = null;
|
|
1200
1184
|
const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
@@ -1231,7 +1215,7 @@
|
|
|
1231
1215
|
let KEEP_CONTENT = true;
|
|
1232
1216
|
let IN_PLACE = false;
|
|
1233
1217
|
let IN_PLACE_VISITED = null;
|
|
1234
|
-
let USE_PROFILES =
|
|
1218
|
+
let USE_PROFILES = false;
|
|
1235
1219
|
let FORBID_CONTENTS = null;
|
|
1236
1220
|
const DEFAULT_FORBID_CONTENTS = addToSet({}, [
|
|
1237
1221
|
"annotation-xml",
|
|
@@ -1298,16 +1282,17 @@
|
|
|
1298
1282
|
SVG_NAMESPACE,
|
|
1299
1283
|
HTML_NAMESPACE
|
|
1300
1284
|
], stringToString);
|
|
1301
|
-
const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze([
|
|
1285
|
+
const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(addToSet({}, [
|
|
1302
1286
|
"mi",
|
|
1303
1287
|
"mo",
|
|
1304
1288
|
"mn",
|
|
1305
1289
|
"ms",
|
|
1306
1290
|
"mtext"
|
|
1307
|
-
]);
|
|
1308
|
-
let MATHML_TEXT_INTEGRATION_POINTS =
|
|
1309
|
-
const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
|
|
1310
|
-
let HTML_INTEGRATION_POINTS =
|
|
1291
|
+
]));
|
|
1292
|
+
let MATHML_TEXT_INTEGRATION_POINTS = null;
|
|
1293
|
+
const DEFAULT_HTML_INTEGRATION_POINTS = freeze(addToSet({}, ["annotation-xml"]));
|
|
1294
|
+
let HTML_INTEGRATION_POINTS = null;
|
|
1295
|
+
const DEFAULT_CUSTOM_ELEMENT_HANDLING = freeze(create(null));
|
|
1311
1296
|
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
|
|
1312
1297
|
"title",
|
|
1313
1298
|
"style",
|
|
@@ -1331,7 +1316,6 @@
|
|
|
1331
1316
|
*/
|
|
1332
1317
|
const _parseConfig = function _parseConfig() {
|
|
1333
1318
|
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1334
|
-
if (CONFIG && CONFIG === cfg) return;
|
|
1335
1319
|
if (!cfg || typeof cfg !== "object") cfg = {};
|
|
1336
1320
|
cfg = clone(cfg);
|
|
1337
1321
|
PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
@@ -1348,8 +1332,8 @@
|
|
|
1348
1332
|
base: DEFAULT_DATA_URI_TAGS
|
|
1349
1333
|
});
|
|
1350
1334
|
FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
|
|
1351
|
-
FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS",
|
|
1352
|
-
FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR",
|
|
1335
|
+
FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", create(null), { transform: transformCaseFunc });
|
|
1336
|
+
FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", create(null), { transform: transformCaseFunc });
|
|
1353
1337
|
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
|
|
1354
1338
|
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
|
1355
1339
|
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
|
@@ -1368,9 +1352,9 @@
|
|
|
1368
1352
|
IN_PLACE = cfg.IN_PLACE || false;
|
|
1369
1353
|
IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
|
|
1370
1354
|
NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
|
|
1371
|
-
MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS",
|
|
1372
|
-
HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS",
|
|
1373
|
-
const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING",
|
|
1355
|
+
MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
|
|
1356
|
+
HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", DEFAULT_HTML_INTEGRATION_POINTS);
|
|
1357
|
+
const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", DEFAULT_CUSTOM_ELEMENT_HANDLING);
|
|
1374
1358
|
CUSTOM_ELEMENT_HANDLING = create(null);
|
|
1375
1359
|
if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
|
|
1376
1360
|
if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
|
|
@@ -1379,6 +1363,7 @@
|
|
|
1379
1363
|
if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
|
|
1380
1364
|
if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
|
|
1381
1365
|
if (USE_PROFILES) {
|
|
1366
|
+
if ((objectHasOwnProperty(cfg, "ALLOWED_TAGS") || objectHasOwnProperty(cfg, "ALLOWED_ATTR")) && typeof console !== "undefined" && typeof console.warn === "function") console.warn("DOMPurify: USE_PROFILES overrides ALLOWED_TAGS and ALLOWED_ATTR. Do not use these options together.");
|
|
1382
1367
|
ALLOWED_TAGS = addToSet({}, text);
|
|
1383
1368
|
ALLOWED_ATTR = create(null);
|
|
1384
1369
|
if (USE_PROFILES.html === true) {
|
|
@@ -1406,19 +1391,19 @@
|
|
|
1406
1391
|
if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
|
|
1407
1392
|
if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
1408
1393
|
else if (arrayIsArray(cfg.ADD_TAGS)) {
|
|
1409
|
-
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS =
|
|
1394
|
+
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = cloneSet(ALLOWED_TAGS);
|
|
1410
1395
|
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
1411
1396
|
}
|
|
1412
1397
|
}
|
|
1413
1398
|
if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
|
|
1414
1399
|
if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
1415
1400
|
else if (arrayIsArray(cfg.ADD_ATTR)) {
|
|
1416
|
-
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR =
|
|
1401
|
+
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = cloneSet(ALLOWED_ATTR);
|
|
1417
1402
|
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
1418
1403
|
}
|
|
1419
1404
|
}
|
|
1420
1405
|
if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
|
|
1421
|
-
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS =
|
|
1406
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = cloneSet(FORBID_CONTENTS);
|
|
1422
1407
|
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
1423
1408
|
}
|
|
1424
1409
|
if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
|
|
@@ -1428,7 +1413,7 @@
|
|
|
1428
1413
|
"body"
|
|
1429
1414
|
]);
|
|
1430
1415
|
if (ALLOWED_TAGS.table) {
|
|
1431
|
-
|
|
1416
|
+
ALLOWED_TAGS.tbody = true;
|
|
1432
1417
|
delete FORBID_TAGS.tbody;
|
|
1433
1418
|
}
|
|
1434
1419
|
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
@@ -1449,8 +1434,7 @@
|
|
|
1449
1434
|
if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
|
|
1450
1435
|
if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
|
|
1451
1436
|
}
|
|
1452
|
-
|
|
1453
|
-
CONFIG = cfg;
|
|
1437
|
+
CONFIG = freeze(cfg);
|
|
1454
1438
|
};
|
|
1455
1439
|
const ALL_SVG_TAGS = addToSet({}, [
|
|
1456
1440
|
...svg$1,
|
|
@@ -1462,39 +1446,39 @@
|
|
|
1462
1446
|
* Namespace rules for an element in the SVG namespace.
|
|
1463
1447
|
*
|
|
1464
1448
|
* @param tagName the element's lowercase tag name
|
|
1465
|
-
* @param
|
|
1449
|
+
* @param parentNamespace the (possibly simulated) parent's namespace
|
|
1466
1450
|
* @param parentTagName the parent's lowercase tag name
|
|
1467
1451
|
* @returns true if a spec-compliant parser could produce this element
|
|
1468
1452
|
*/
|
|
1469
|
-
const _checkSvgNamespace = function _checkSvgNamespace(tagName,
|
|
1470
|
-
if (
|
|
1471
|
-
if (
|
|
1453
|
+
const _checkSvgNamespace = function _checkSvgNamespace(tagName, parentNamespace, parentTagName) {
|
|
1454
|
+
if (parentNamespace === HTML_NAMESPACE) return tagName === "svg";
|
|
1455
|
+
if (parentNamespace === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
1472
1456
|
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
1473
1457
|
};
|
|
1474
1458
|
/**
|
|
1475
1459
|
* Namespace rules for an element in the MathML namespace.
|
|
1476
1460
|
*
|
|
1477
1461
|
* @param tagName the element's lowercase tag name
|
|
1478
|
-
* @param
|
|
1462
|
+
* @param parentNamespace the (possibly simulated) parent's namespace
|
|
1479
1463
|
* @param parentTagName the parent's lowercase tag name
|
|
1480
1464
|
* @returns true if a spec-compliant parser could produce this element
|
|
1481
1465
|
*/
|
|
1482
|
-
const _checkMathMlNamespace = function _checkMathMlNamespace(tagName,
|
|
1483
|
-
if (
|
|
1484
|
-
if (
|
|
1466
|
+
const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parentNamespace, parentTagName) {
|
|
1467
|
+
if (parentNamespace === HTML_NAMESPACE) return tagName === "math";
|
|
1468
|
+
if (parentNamespace === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
|
1485
1469
|
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
1486
1470
|
};
|
|
1487
1471
|
/**
|
|
1488
1472
|
* Namespace rules for an element in the HTML namespace.
|
|
1489
1473
|
*
|
|
1490
1474
|
* @param tagName the element's lowercase tag name
|
|
1491
|
-
* @param
|
|
1475
|
+
* @param parentNamespace the (possibly simulated) parent's namespace
|
|
1492
1476
|
* @param parentTagName the parent's lowercase tag name
|
|
1493
1477
|
* @returns true if a spec-compliant parser could produce this element
|
|
1494
1478
|
*/
|
|
1495
|
-
const _checkHtmlNamespace = function _checkHtmlNamespace(tagName,
|
|
1496
|
-
if (
|
|
1497
|
-
if (
|
|
1479
|
+
const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parentNamespace, parentTagName) {
|
|
1480
|
+
if (parentNamespace === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
|
|
1481
|
+
if (parentNamespace === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
|
|
1498
1482
|
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
1499
1483
|
};
|
|
1500
1484
|
/**
|
|
@@ -1507,21 +1491,17 @@
|
|
|
1507
1491
|
const elementNamespace = _readNamespaceURI(element);
|
|
1508
1492
|
const tagName = stringToLowerCase(_readNodeName(element));
|
|
1509
1493
|
const parentNode = getParentNode(element);
|
|
1510
|
-
let
|
|
1511
|
-
let parentTagName;
|
|
1494
|
+
let parentNamespace = NAMESPACE;
|
|
1495
|
+
let parentTagName = "template";
|
|
1512
1496
|
if (parentNode && _readNodeType(parentNode) === NODE_TYPE.element) {
|
|
1513
|
-
|
|
1497
|
+
parentNamespace = _readNamespaceURI(parentNode);
|
|
1514
1498
|
parentTagName = stringToLowerCase(_readNodeName(parentNode));
|
|
1515
|
-
} else {
|
|
1516
|
-
parent = { namespaceURI: NAMESPACE };
|
|
1517
|
-
parentTagName = "template";
|
|
1518
1499
|
}
|
|
1519
1500
|
if (!ALLOWED_NAMESPACES[elementNamespace]) return false;
|
|
1520
|
-
if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName,
|
|
1521
|
-
if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName,
|
|
1522
|
-
if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName,
|
|
1523
|
-
|
|
1524
|
-
return false;
|
|
1501
|
+
if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parentNamespace, parentTagName);
|
|
1502
|
+
if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parentNamespace, parentTagName);
|
|
1503
|
+
if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parentNamespace, parentTagName);
|
|
1504
|
+
return PARSER_MEDIA_TYPE === "application/xhtml+xml";
|
|
1525
1505
|
};
|
|
1526
1506
|
/**
|
|
1527
1507
|
* _forceRemove
|
|
@@ -1538,17 +1518,10 @@
|
|
|
1538
1518
|
}
|
|
1539
1519
|
};
|
|
1540
1520
|
/**
|
|
1541
|
-
*
|
|
1542
|
-
*
|
|
1543
|
-
*
|
|
1544
|
-
*
|
|
1545
|
-
* HTML element in an HTML document and so silently misses a case-preserved
|
|
1546
|
-
* handler (e.g. `ONERROR` off an XML/XHTML import) - the same defect
|
|
1547
|
-
* _removeAttribute() was fixed for, which a name-based call would reintroduce
|
|
1548
|
-
* on these IN_PLACE teardown paths. Unlike _removeAttribute this does not
|
|
1549
|
-
* record into DOMPurify.removed: the neutralize passes intentionally do not
|
|
1550
|
-
* book-keep. A clobbered/detached node falls back to best-effort name-based
|
|
1551
|
-
* removal.
|
|
1521
|
+
* Removes an Attr node as that exact node, without book-keeping. Name-based
|
|
1522
|
+
* removal lowercases the name in HTML documents and would miss a
|
|
1523
|
+
* case-preserved one such as `ONERROR`, so it is only the fallback for
|
|
1524
|
+
* clobbered or detached nodes.
|
|
1552
1525
|
*
|
|
1553
1526
|
* @param element the element to strip the attribute from
|
|
1554
1527
|
* @param attribute the Attr node to remove
|
|
@@ -1578,12 +1551,7 @@
|
|
|
1578
1551
|
remove(child);
|
|
1579
1552
|
} catch (_) {}
|
|
1580
1553
|
});
|
|
1581
|
-
|
|
1582
|
-
if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
|
|
1583
|
-
const attribute = attributes[i];
|
|
1584
|
-
const name = attribute && attribute.name;
|
|
1585
|
-
if (typeof name === "string") _stripAttributeNode(root, attribute, name);
|
|
1586
|
-
}
|
|
1554
|
+
if (_readNodeType(root) === NODE_TYPE.element) _stripAttributes(root, false);
|
|
1587
1555
|
};
|
|
1588
1556
|
/**
|
|
1589
1557
|
* Removes an attribute, preferably as its exact Attr node: name-based
|
|
@@ -1604,14 +1572,10 @@
|
|
|
1604
1572
|
attribute: attr || null,
|
|
1605
1573
|
from: element
|
|
1606
1574
|
});
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
} catch (_) {
|
|
1611
|
-
try {
|
|
1612
|
-
element.removeAttribute(name);
|
|
1613
|
-
} catch (_) {}
|
|
1614
|
-
}
|
|
1575
|
+
if (attr) _stripAttributeNode(element, attr, name);
|
|
1576
|
+
else try {
|
|
1577
|
+
element.removeAttribute(name);
|
|
1578
|
+
} catch (_) {}
|
|
1615
1579
|
if (name === "is") {
|
|
1616
1580
|
if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
|
|
1617
1581
|
_forceRemove(element);
|
|
@@ -1622,19 +1586,19 @@
|
|
|
1622
1586
|
}
|
|
1623
1587
|
};
|
|
1624
1588
|
/**
|
|
1625
|
-
* Removes
|
|
1626
|
-
*
|
|
1589
|
+
* Removes an element's attributes without book-keeping. Used to neutralize
|
|
1590
|
+
* nodes discarded from an in-place tree.
|
|
1627
1591
|
*
|
|
1628
1592
|
* @param element the element to strip
|
|
1593
|
+
* @param keepAllowed whether attributes on the allowlist stay
|
|
1629
1594
|
*/
|
|
1630
|
-
const
|
|
1595
|
+
const _stripAttributes = function _stripAttributes(element, keepAllowed) {
|
|
1631
1596
|
const attributes = getAttributes(element);
|
|
1632
1597
|
if (!attributes) return;
|
|
1633
1598
|
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
1634
1599
|
const attribute = attributes[i];
|
|
1635
1600
|
const name = attribute && attribute.name;
|
|
1636
|
-
if (typeof name
|
|
1637
|
-
_stripAttributeNode(element, attribute, name);
|
|
1601
|
+
if (typeof name === "string" && !(keepAllowed && ALLOWED_ATTR[transformCaseFunc(name)])) _stripAttributeNode(element, attribute, name);
|
|
1638
1602
|
}
|
|
1639
1603
|
};
|
|
1640
1604
|
/**
|
|
@@ -1669,7 +1633,7 @@
|
|
|
1669
1633
|
*/
|
|
1670
1634
|
const _neutralizeSubtree = function _neutralizeSubtree(root) {
|
|
1671
1635
|
_walkTree(root, (node) => {
|
|
1672
|
-
if (_readNodeType(node) === NODE_TYPE.element)
|
|
1636
|
+
if (_readNodeType(node) === NODE_TYPE.element) _stripAttributes(node, true);
|
|
1673
1637
|
});
|
|
1674
1638
|
};
|
|
1675
1639
|
/**
|
|
@@ -1700,7 +1664,7 @@
|
|
|
1700
1664
|
if (_readNodeType(node) === NODE_TYPE.element) setAdd(reachable, node);
|
|
1701
1665
|
});
|
|
1702
1666
|
arrayForEach(before, (node) => {
|
|
1703
|
-
if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node))
|
|
1667
|
+
if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripAttributes(node, true);
|
|
1704
1668
|
});
|
|
1705
1669
|
};
|
|
1706
1670
|
/**
|
|
@@ -1773,9 +1737,7 @@
|
|
|
1773
1737
|
while (node = iterator.nextNode()) {
|
|
1774
1738
|
if (!setHas(original, node) || setHas(IN_PLACE_VISITED, node)) continue;
|
|
1775
1739
|
if (inShadow) _executeHooks(hooks.uponSanitizeShadowNode, node, null);
|
|
1776
|
-
|
|
1777
|
-
_sanitizeAttributes(node, root);
|
|
1778
|
-
if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
|
|
1740
|
+
_sanitizeNode(node, root);
|
|
1779
1741
|
}
|
|
1780
1742
|
};
|
|
1781
1743
|
/**
|
|
@@ -1807,7 +1769,7 @@
|
|
|
1807
1769
|
* and strips linkage attributes. It cannot undo a patch that already fired.
|
|
1808
1770
|
*
|
|
1809
1771
|
* TODO: if the shipped feature can patch through `for` on <label>/<output>,
|
|
1810
|
-
* drop that pair here too
|
|
1772
|
+
* drop that pair here too.
|
|
1811
1773
|
*
|
|
1812
1774
|
* @param root the in-place root to sweep
|
|
1813
1775
|
*/
|
|
@@ -1843,7 +1805,7 @@
|
|
|
1843
1805
|
let leadingWhitespace = null;
|
|
1844
1806
|
if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
|
|
1845
1807
|
else {
|
|
1846
|
-
const matches = stringMatch(dirty,
|
|
1808
|
+
const matches = stringMatch(dirty, LEADING_WHITESPACE);
|
|
1847
1809
|
leadingWhitespace = matches && matches[0];
|
|
1848
1810
|
}
|
|
1849
1811
|
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>";
|
|
@@ -1863,14 +1825,18 @@
|
|
|
1863
1825
|
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
1864
1826
|
};
|
|
1865
1827
|
/**
|
|
1866
|
-
* Creates a NodeIterator
|
|
1828
|
+
* Creates a NodeIterator over `root`. ownerDocument is read through the
|
|
1829
|
+
* cached getter: a form child named "ownerDocument" shadows the direct
|
|
1830
|
+
* read and would make createNodeIterator throw.
|
|
1867
1831
|
*
|
|
1868
|
-
* @param root The
|
|
1832
|
+
* @param root The node to start traversing on.
|
|
1833
|
+
* @param characterDataOnly whether to skip elements
|
|
1869
1834
|
* @return The created NodeIterator
|
|
1870
1835
|
*/
|
|
1871
1836
|
const _createNodeIterator = function _createNodeIterator(root) {
|
|
1837
|
+
let characterDataOnly = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
1872
1838
|
const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
|
|
1873
|
-
return createNodeIterator.call(doc || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
1839
|
+
return createNodeIterator.call(doc || root, root, (characterDataOnly ? 0 : NodeFilter.SHOW_ELEMENT) | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
1874
1840
|
};
|
|
1875
1841
|
/**
|
|
1876
1842
|
* Replace template expression syntax (mustache, ERB, template
|
|
@@ -1887,21 +1853,11 @@
|
|
|
1887
1853
|
return value;
|
|
1888
1854
|
};
|
|
1889
1855
|
/**
|
|
1890
|
-
*
|
|
1891
|
-
*
|
|
1892
|
-
*
|
|
1893
|
-
*
|
|
1894
|
-
*
|
|
1895
|
-
*
|
|
1896
|
-
* Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
|
|
1897
|
-
* in place rather than round-tripping through innerHTML. This preserves
|
|
1898
|
-
* descendant node references (important for IN_PLACE callers), avoids a
|
|
1899
|
-
* serialize/reparse cycle, and reads literal character data — which means
|
|
1900
|
-
* `<%...%>` in text content matches the ERB regex against its real bytes
|
|
1901
|
-
* instead of the HTML-entity-escaped form innerHTML would produce.
|
|
1902
|
-
*
|
|
1903
|
-
* Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
|
|
1904
|
-
* attributes is performed during the per-node `_sanitizeAttributes` pass.
|
|
1856
|
+
* Strips template expressions from the character data under `node`,
|
|
1857
|
+
* template contents included. Runs after the walk, since an expression can
|
|
1858
|
+
* also form when a removed element leaves two text nodes adjacent. Works on
|
|
1859
|
+
* the nodes rather than on markup, which keeps node references intact and
|
|
1860
|
+
* sees `<%` unescaped. Attribute values are handled in _sanitizeAttributes.
|
|
1905
1861
|
*
|
|
1906
1862
|
* @param node The root element whose character data should be scrubbed.
|
|
1907
1863
|
*/
|
|
@@ -1914,23 +1870,15 @@
|
|
|
1914
1870
|
});
|
|
1915
1871
|
};
|
|
1916
1872
|
/**
|
|
1917
|
-
*
|
|
1918
|
-
*
|
|
1919
|
-
*
|
|
1920
|
-
* strip template expressions from its own character data only. Does not
|
|
1921
|
-
* enter <template>.content or attached shadow roots (NodeIterator never
|
|
1922
|
-
* does). Used by _sanitizeShadowDOM, where every nested template content
|
|
1923
|
-
* and shadow root is already walked - and therefore scrubbed - by its own
|
|
1924
|
-
* recursive _sanitizeShadowDOM call; recursing here as well would rescrub
|
|
1925
|
-
* each nested fragment once per ancestor, which is quadratic in nesting
|
|
1926
|
-
* depth.
|
|
1873
|
+
* Normalizes `node` and strips template expressions from its own character
|
|
1874
|
+
* data. Template contents and shadow roots are not entered, their own
|
|
1875
|
+
* _sanitizeShadowDOM call scrubs them.
|
|
1927
1876
|
*
|
|
1928
1877
|
* @param node The root whose own character data should be scrubbed.
|
|
1929
1878
|
*/
|
|
1930
1879
|
const _scrubOwnCharacterData = function _scrubOwnCharacterData(node) {
|
|
1931
1880
|
node.normalize();
|
|
1932
|
-
const
|
|
1933
|
-
const walker = createNodeIterator.call(doc || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
|
|
1881
|
+
const walker = _createNodeIterator(node, true);
|
|
1934
1882
|
let currentNode = walker.nextNode();
|
|
1935
1883
|
while (currentNode) {
|
|
1936
1884
|
currentNode.data = _stripTemplateExpressions(currentNode.data);
|
|
@@ -1938,13 +1886,9 @@
|
|
|
1938
1886
|
}
|
|
1939
1887
|
};
|
|
1940
1888
|
/**
|
|
1941
|
-
*
|
|
1942
|
-
*
|
|
1943
|
-
*
|
|
1944
|
-
* interface with [LegacyOverrideBuiltIns]; a descendant element with a
|
|
1945
|
-
* `name` attribute matching a prototype property shadows that property
|
|
1946
|
-
* on direct reads. We use this check at the IN_PLACE entry-point and
|
|
1947
|
-
* during attribute sanitization to refuse clobbered forms.
|
|
1889
|
+
* Detects DOM clobbering on a form, the only element whose named children
|
|
1890
|
+
* shadow its own properties. Each probe compares a direct read with what
|
|
1891
|
+
* the property has to be.
|
|
1948
1892
|
*
|
|
1949
1893
|
* @param element element to check for clobbering attacks
|
|
1950
1894
|
* @return true if clobbered, false if safe
|
|
@@ -1956,42 +1900,26 @@
|
|
|
1956
1900
|
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);
|
|
1957
1901
|
};
|
|
1958
1902
|
/**
|
|
1959
|
-
*
|
|
1903
|
+
* Reads nodeType through the cached getter, so the result holds for nodes
|
|
1904
|
+
* from any realm (GHSA-4w3q-35jp-p934) and cannot be clobbered.
|
|
1960
1905
|
*
|
|
1961
|
-
*
|
|
1962
|
-
*
|
|
1963
|
-
* constant (11). nodeType is a numeric value resolved from the node's
|
|
1964
|
-
* internal slot, identical across realms for the same kind of node.
|
|
1965
|
-
*
|
|
1966
|
-
* @param value object to check
|
|
1967
|
-
* @return true if value is a DocumentFragment-shaped node from any realm
|
|
1906
|
+
* @param value anything
|
|
1907
|
+
* @return the node type, or null if value is not a DOM node
|
|
1968
1908
|
*/
|
|
1969
|
-
const
|
|
1970
|
-
if (!getNodeType || typeof value !== "object" || value === null) return
|
|
1909
|
+
const _nodeTypeOf = function _nodeTypeOf(value) {
|
|
1910
|
+
if (!getNodeType || typeof value !== "object" || value === null) return null;
|
|
1971
1911
|
try {
|
|
1972
|
-
|
|
1912
|
+
const nodeType = getNodeType(value);
|
|
1913
|
+
return typeof nodeType === "number" ? nodeType : null;
|
|
1973
1914
|
} catch (_) {
|
|
1974
|
-
return
|
|
1915
|
+
return null;
|
|
1975
1916
|
}
|
|
1976
1917
|
};
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
* contentDocument). The previous `value instanceof Node` check was
|
|
1981
|
-
* realm-bound: nodes from a different window failed it, causing
|
|
1982
|
-
* sanitize() to silently stringify them and reset IN_PLACE to false,
|
|
1983
|
-
* returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
|
|
1984
|
-
*
|
|
1985
|
-
* @param value object to check whether it's a DOM node
|
|
1986
|
-
* @return true if value is a DOM node from any realm
|
|
1987
|
-
*/
|
|
1918
|
+
const _isDocumentFragment = function _isDocumentFragment(value) {
|
|
1919
|
+
return _nodeTypeOf(value) === NODE_TYPE.documentFragment;
|
|
1920
|
+
};
|
|
1988
1921
|
const _isNode = function _isNode(value) {
|
|
1989
|
-
|
|
1990
|
-
try {
|
|
1991
|
-
return typeof getNodeType(value) === "number";
|
|
1992
|
-
} catch (_) {
|
|
1993
|
-
return false;
|
|
1994
|
-
}
|
|
1922
|
+
return _nodeTypeOf(value) !== null;
|
|
1995
1923
|
};
|
|
1996
1924
|
function _executeHooks(hooks, currentNode, data) {
|
|
1997
1925
|
if (hooks.length === 0) return;
|
|
@@ -2007,13 +1935,14 @@
|
|
|
2007
1935
|
*
|
|
2008
1936
|
* @param currentNode the node to inspect
|
|
2009
1937
|
* @param tagName the node's transformCaseFunc'd tag name
|
|
1938
|
+
* @param nodeType the node's type, read through the cached getter
|
|
2010
1939
|
* @return true if the node must be removed
|
|
2011
1940
|
*/
|
|
2012
|
-
const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
|
|
2013
|
-
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
|
|
2014
|
-
if (SAFE_FOR_XML && LITERAL_TEXT_ELEMENTS[tagName] &&
|
|
2015
|
-
if (
|
|
2016
|
-
if (SAFE_FOR_XML &&
|
|
1941
|
+
const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName, nodeType) {
|
|
1942
|
+
if (SAFE_FOR_XML && nodeType === NODE_TYPE.element && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
|
|
1943
|
+
if (SAFE_FOR_XML && LITERAL_TEXT_ELEMENTS[tagName] && nodeType === NODE_TYPE.element && _readNamespaceURI(currentNode) === HTML_NAMESPACE && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent))) return true;
|
|
1944
|
+
if (nodeType === NODE_TYPE.processingInstruction) return true;
|
|
1945
|
+
if (SAFE_FOR_XML && nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
|
|
2017
1946
|
return false;
|
|
2018
1947
|
};
|
|
2019
1948
|
/**
|
|
@@ -2037,17 +1966,9 @@
|
|
|
2037
1966
|
return false;
|
|
2038
1967
|
};
|
|
2039
1968
|
/**
|
|
2040
|
-
*
|
|
2041
|
-
*
|
|
2042
|
-
*
|
|
2043
|
-
* intentionally skipped for kept custom elements), else hoist
|
|
2044
|
-
* content per KEEP_CONTENT and remove.
|
|
2045
|
-
*
|
|
2046
|
-
* A kept custom element is the ONLY case in which this function
|
|
2047
|
-
* returns false, so the caller uses that return value to run the
|
|
2048
|
-
* afterSanitizeElements hook on the kept element and keep the
|
|
2049
|
-
* element-hook lifecycle consistent with normal allowlisted
|
|
2050
|
-
* elements (GHSA-c2j3-45gr-mqc4).
|
|
1969
|
+
* Handles a node whose tag is forbidden or not allowlisted: hoists its
|
|
1970
|
+
* content per KEEP_CONTENT and removes it. The one exception is a custom
|
|
1971
|
+
* element allowed via CUSTOM_ELEMENT_HANDLING, which is kept.
|
|
2051
1972
|
*
|
|
2052
1973
|
* @param currentNode the disallowed node
|
|
2053
1974
|
* @param tagName the node's transformCaseFunc'd tag name
|
|
@@ -2070,11 +1991,9 @@
|
|
|
2070
1991
|
return true;
|
|
2071
1992
|
};
|
|
2072
1993
|
/**
|
|
2073
|
-
*
|
|
2074
|
-
* (
|
|
2075
|
-
*
|
|
2076
|
-
* reference and leak past the call. Returns the set unchanged once it is
|
|
2077
|
-
* already call-local, so repeated calls across elements are idempotent.
|
|
1994
|
+
* Forks an allowlist off its shared binding (the instance default or the
|
|
1995
|
+
* setConfig() capture) before a hook sees it, so a hook's widening stays
|
|
1996
|
+
* within the call. A set that is already call-local is returned as is.
|
|
2078
1997
|
*
|
|
2079
1998
|
* @param hookList the uponSanitize* hook array for this event
|
|
2080
1999
|
* @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
|
|
@@ -2085,7 +2004,7 @@
|
|
|
2085
2004
|
*/
|
|
2086
2005
|
const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
|
|
2087
2006
|
if (hookList.length === 0) return set;
|
|
2088
|
-
return set === defaultSet || set === setConfigSet ?
|
|
2007
|
+
return set === defaultSet || set === setConfigSet ? cloneSet(set) : set;
|
|
2089
2008
|
};
|
|
2090
2009
|
/**
|
|
2091
2010
|
* A hook may have detached the node it was called for. If so, treat it as
|
|
@@ -2119,13 +2038,14 @@
|
|
|
2119
2038
|
return true;
|
|
2120
2039
|
}
|
|
2121
2040
|
const tagName = transformCaseFunc(_readNodeName(currentNode));
|
|
2041
|
+
const nodeType = _readNodeType(currentNode);
|
|
2122
2042
|
ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
|
|
2123
2043
|
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
2124
2044
|
tagName,
|
|
2125
2045
|
allowedTags: ALLOWED_TAGS
|
|
2126
2046
|
});
|
|
2127
2047
|
if (_handleHookDetachedNode(currentNode, root)) return true;
|
|
2128
|
-
if (_isUnsafeNode(currentNode, tagName)) {
|
|
2048
|
+
if (_isUnsafeNode(currentNode, tagName, nodeType)) {
|
|
2129
2049
|
_forceRemove(currentNode);
|
|
2130
2050
|
return true;
|
|
2131
2051
|
}
|
|
@@ -2137,7 +2057,7 @@
|
|
|
2137
2057
|
}
|
|
2138
2058
|
return removed;
|
|
2139
2059
|
}
|
|
2140
|
-
if (
|
|
2060
|
+
if (nodeType === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
|
|
2141
2061
|
_forceRemove(currentNode);
|
|
2142
2062
|
return true;
|
|
2143
2063
|
}
|
|
@@ -2145,9 +2065,10 @@
|
|
|
2145
2065
|
_forceRemove(currentNode);
|
|
2146
2066
|
return true;
|
|
2147
2067
|
}
|
|
2148
|
-
if (SAFE_FOR_TEMPLATES &&
|
|
2149
|
-
const
|
|
2150
|
-
|
|
2068
|
+
if (SAFE_FOR_TEMPLATES && nodeType === NODE_TYPE.text) {
|
|
2069
|
+
const text = currentNode.textContent;
|
|
2070
|
+
const content = _stripTemplateExpressions(text);
|
|
2071
|
+
if (text !== content) {
|
|
2151
2072
|
arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
|
|
2152
2073
|
currentNode.textContent = content;
|
|
2153
2074
|
}
|
|
@@ -2172,9 +2093,10 @@
|
|
|
2172
2093
|
if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) return true;
|
|
2173
2094
|
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);
|
|
2174
2095
|
if (URI_SAFE_ATTRIBUTES[lcName]) return true;
|
|
2175
|
-
|
|
2096
|
+
const compactValue = stringReplace(value, ATTR_WHITESPACE$1, "");
|
|
2097
|
+
if (regExpTest(IS_ALLOWED_URI$1, compactValue)) return true;
|
|
2176
2098
|
if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) return true;
|
|
2177
|
-
if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1,
|
|
2099
|
+
if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, compactValue)) return true;
|
|
2178
2100
|
return !value;
|
|
2179
2101
|
};
|
|
2180
2102
|
const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
|
|
@@ -2218,21 +2140,8 @@
|
|
|
2218
2140
|
return value;
|
|
2219
2141
|
};
|
|
2220
2142
|
/**
|
|
2221
|
-
*
|
|
2222
|
-
*
|
|
2223
|
-
* remove the element when found; otherwise, when this writeback is the
|
|
2224
|
-
* recreate half of the SANITIZE_NAMED_PROPS remove-and-recreate, pop the
|
|
2225
|
-
* removal entry that path recorded so it does not show as removed. On
|
|
2226
|
-
* failure, remove the attribute instead.
|
|
2227
|
-
*
|
|
2228
|
-
* Returns true only on a clean write (the value was set and the new value
|
|
2229
|
-
* introduced no clobbering). The caller uses that, together with its own
|
|
2230
|
-
* knowledge of whether this attribute pushed a DOMPurify.removed record, to
|
|
2231
|
-
* decide whether to pop that record. The pop must happen ONLY for the
|
|
2232
|
-
* named-prop remove-and-recreate; popping on any other value change (trim,
|
|
2233
|
-
* template scrubbing, Trusted Types) would consume an unrelated _forceRemove
|
|
2234
|
-
* subtree-cleanup record and let that detached subtree keep a live event
|
|
2235
|
-
* handler through the IN_PLACE neutralization pass (SO-001).
|
|
2143
|
+
* Writes a changed attribute value back. If the new value clobbers, the
|
|
2144
|
+
* element is removed; if the write fails, the attribute is.
|
|
2236
2145
|
*
|
|
2237
2146
|
* @param currentNode the element carrying the attribute
|
|
2238
2147
|
* @param name the attribute name as present on the element
|
|
@@ -2255,20 +2164,17 @@
|
|
|
2255
2164
|
}
|
|
2256
2165
|
};
|
|
2257
2166
|
/**
|
|
2258
|
-
*
|
|
2259
|
-
*
|
|
2260
|
-
*
|
|
2261
|
-
* hook can force-keep an attribute, shared with the public
|
|
2262
|
-
* isValidAttribute() so that it never approves a value sanitize() would
|
|
2263
|
-
* strip.
|
|
2167
|
+
* Value checks that apply before a hook can force-keep an attribute. Also
|
|
2168
|
+
* used by isValidAttribute(), so it never approves a value that sanitize()
|
|
2169
|
+
* would strip.
|
|
2264
2170
|
*
|
|
2265
2171
|
* @param name the attribute name as found on the node (case preserved)
|
|
2266
2172
|
* @param value the attribute value
|
|
2267
2173
|
* @returns true if the attribute must be removed because of its value
|
|
2268
2174
|
*/
|
|
2269
2175
|
const _isUnsafeAttributeValue = function _isUnsafeAttributeValue(name, value) {
|
|
2270
|
-
if (SAFE_FOR_XML && regExpTest(
|
|
2271
|
-
return stringToLowerCase(name) === "attributename" &&
|
|
2176
|
+
if (SAFE_FOR_XML && regExpTest(ATTR_VALUE_BREAKOUT, value)) return true;
|
|
2177
|
+
return stringToLowerCase(name) === "attributename" && stringIndexOf(value, "href") !== -1;
|
|
2272
2178
|
};
|
|
2273
2179
|
/**
|
|
2274
2180
|
* _sanitizeAttributes
|
|
@@ -2295,7 +2201,7 @@
|
|
|
2295
2201
|
forceKeepAttr: void 0
|
|
2296
2202
|
};
|
|
2297
2203
|
let l = attributes.length;
|
|
2298
|
-
const lcTag = transformCaseFunc(currentNode
|
|
2204
|
+
const lcTag = transformCaseFunc(_readNodeName(currentNode));
|
|
2299
2205
|
while (l--) {
|
|
2300
2206
|
const attr = attributes[l];
|
|
2301
2207
|
const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
|
|
@@ -2341,6 +2247,18 @@
|
|
|
2341
2247
|
_handleHookDetachedNode(currentNode, root);
|
|
2342
2248
|
};
|
|
2343
2249
|
/**
|
|
2250
|
+
* Sanitizes one node: the node itself, its attributes and, for a
|
|
2251
|
+
* template, its content.
|
|
2252
|
+
*
|
|
2253
|
+
* @param node the node to sanitize
|
|
2254
|
+
* @param root the current walk root
|
|
2255
|
+
*/
|
|
2256
|
+
const _sanitizeNode = function _sanitizeNode(node, root) {
|
|
2257
|
+
_sanitizeElements(node, root);
|
|
2258
|
+
_sanitizeAttributes(node, root);
|
|
2259
|
+
if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
|
|
2260
|
+
};
|
|
2261
|
+
/**
|
|
2344
2262
|
* _sanitizeShadowDOM
|
|
2345
2263
|
*
|
|
2346
2264
|
* @param fragment to iterate over recursively
|
|
@@ -2351,9 +2269,7 @@
|
|
|
2351
2269
|
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
2352
2270
|
while (shadowNode = shadowIterator.nextNode()) {
|
|
2353
2271
|
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
2354
|
-
|
|
2355
|
-
_sanitizeAttributes(shadowNode, fragment);
|
|
2356
|
-
if (_isDocumentFragment(shadowNode.content)) _sanitizeShadowDOM2(shadowNode.content);
|
|
2272
|
+
_sanitizeNode(shadowNode, fragment);
|
|
2357
2273
|
if (_readNodeType(shadowNode) === NODE_TYPE.element) {
|
|
2358
2274
|
const innerSr = getShadowRoot(shadowNode);
|
|
2359
2275
|
if (_isDocumentFragment(innerSr)) {
|
|
@@ -2429,8 +2345,6 @@
|
|
|
2429
2345
|
ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
|
|
2430
2346
|
ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
|
|
2431
2347
|
} else _parseConfig(cfg);
|
|
2432
|
-
if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
2433
|
-
if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
2434
2348
|
DOMPurify.removed = [];
|
|
2435
2349
|
const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
|
|
2436
2350
|
let inPlaceNodes = [];
|
|
@@ -2459,7 +2373,7 @@
|
|
|
2459
2373
|
else body.appendChild(importedNode);
|
|
2460
2374
|
_sanitizeAttachedShadowRoots(body);
|
|
2461
2375
|
} else {
|
|
2462
|
-
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return
|
|
2376
|
+
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return _signOutput(dirty);
|
|
2463
2377
|
body = _initDocument(dirty);
|
|
2464
2378
|
if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
|
2465
2379
|
}
|
|
@@ -2468,11 +2382,7 @@
|
|
|
2468
2382
|
try {
|
|
2469
2383
|
if (inPlace) _sanitizeAttachedShadowRoots(dirty);
|
|
2470
2384
|
const nodeIterator = _createNodeIterator(walkRoot);
|
|
2471
|
-
while (currentNode = nodeIterator.nextNode())
|
|
2472
|
-
_sanitizeElements(currentNode, walkRoot);
|
|
2473
|
-
_sanitizeAttributes(currentNode, walkRoot);
|
|
2474
|
-
if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
|
|
2475
|
-
}
|
|
2385
|
+
while (currentNode = nodeIterator.nextNode()) _sanitizeNode(currentNode, walkRoot);
|
|
2476
2386
|
if (inPlace) _sanitizeUnvisitedNodes(dirty, inPlaceNodes);
|
|
2477
2387
|
} catch (error) {
|
|
2478
2388
|
if (inPlace) {
|
|
@@ -2497,10 +2407,14 @@
|
|
|
2497
2407
|
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
|
|
2498
2408
|
return returnNode;
|
|
2499
2409
|
}
|
|
2500
|
-
|
|
2410
|
+
const serialize = () => WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
2411
|
+
let serializedHTML = serialize();
|
|
2412
|
+
if (SAFE_FOR_TEMPLATES && regExpTest(TMPL_MARKER_SERIALIZED, serializedHTML)) {
|
|
2413
|
+
_scrubOwnCharacterData(body);
|
|
2414
|
+
serializedHTML = serialize();
|
|
2415
|
+
}
|
|
2501
2416
|
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;
|
|
2502
|
-
|
|
2503
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
|
|
2417
|
+
return _signOutput(serializedHTML);
|
|
2504
2418
|
};
|
|
2505
2419
|
DOMPurify.setConfig = function() {
|
|
2506
2420
|
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|