tinymce-rails 8.7.0 → 8.8.1
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.
- checksums.yaml +4 -4
- data/app/assets/source/tinymce/tinymce.js +974 -258
- data/lib/tinymce/rails/version.rb +2 -2
- data/vendor/assets/javascripts/tinymce/icons/default/icons.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/link/plugin.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/table/plugin.js +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/oxide/skin.css +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/oxide/skin.js +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/oxide/skin.min.css +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/oxide-dark/skin.css +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/oxide-dark/skin.js +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/oxide-dark/skin.min.css +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/tinymce-5/skin.css +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/tinymce-5/skin.js +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/tinymce-5/skin.min.css +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/tinymce-5-dark/skin.css +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/tinymce-5-dark/skin.js +1 -1
- data/vendor/assets/javascripts/tinymce/skins/ui/tinymce-5-dark/skin.min.css +1 -1
- data/vendor/assets/javascripts/tinymce/themes/silver/theme.js +3 -3
- data/vendor/assets/javascripts/tinymce/tinymce.js +5 -5
- metadata +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TinyMCE version 8.
|
|
2
|
+
* TinyMCE version 8.8.1 (2026-07-22)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
(function () {
|
|
@@ -17181,6 +17181,18 @@
|
|
|
17181
17181
|
return block;
|
|
17182
17182
|
}
|
|
17183
17183
|
});
|
|
17184
|
+
// Resolve list items from the
|
|
17185
|
+
// selected cells directly instead, matching how SelectionUtils.runOnRanges resolves fake selections.
|
|
17186
|
+
const getCellSelectionListItems = (editor) => {
|
|
17187
|
+
const fakeSelectionNodes = getCellsFromEditor(editor);
|
|
17188
|
+
if (fakeSelectionNodes.length > 0) {
|
|
17189
|
+
const listItems = bind$3(fakeSelectionNodes, (cell) => descendants(cell, 'li'));
|
|
17190
|
+
return Optional.some(map$3(listItems, (item) => item.dom));
|
|
17191
|
+
}
|
|
17192
|
+
else {
|
|
17193
|
+
return Optional.none();
|
|
17194
|
+
}
|
|
17195
|
+
};
|
|
17184
17196
|
const getFullySelectedBlocks = (selection) => {
|
|
17185
17197
|
if (selection.isCollapsed()) {
|
|
17186
17198
|
return [];
|
|
@@ -17197,8 +17209,15 @@
|
|
|
17197
17209
|
return first.concat(middle).concat(last);
|
|
17198
17210
|
}
|
|
17199
17211
|
};
|
|
17200
|
-
const getFullySelectedListItems = (
|
|
17201
|
-
|
|
17212
|
+
const getFullySelectedListItems = (editor) => {
|
|
17213
|
+
const items = getCellSelectionListItems(editor).getOrThunk(() => getFullySelectedBlocks(editor.selection));
|
|
17214
|
+
return filter$5(items, isEditableListItem(editor.selection.dom));
|
|
17215
|
+
};
|
|
17216
|
+
const getPartiallySelectedListItems = (editor) => {
|
|
17217
|
+
const items = getCellSelectionListItems(editor)
|
|
17218
|
+
.getOrThunk(() => getAndOnlyNormalizeFirstBlockIf(editor.selection, (el) => !isListItem$3(el)));
|
|
17219
|
+
return filter$5(items, isEditableListItem(editor.selection.dom));
|
|
17220
|
+
};
|
|
17202
17221
|
|
|
17203
17222
|
const each$8 = Tools.each;
|
|
17204
17223
|
const isElementNode = (node) => isElement$7(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$1(node);
|
|
@@ -17440,14 +17459,14 @@
|
|
|
17440
17459
|
};
|
|
17441
17460
|
const removeListStyleFormats = (editor, name, vars) => {
|
|
17442
17461
|
if (name === 'removeformat') {
|
|
17443
|
-
each$e(getPartiallySelectedListItems(editor
|
|
17462
|
+
each$e(getPartiallySelectedListItems(editor), (li) => {
|
|
17444
17463
|
each$e(listItemStyles, (name) => editor.dom.setStyle(li, name, ''));
|
|
17445
17464
|
removeEmptyStyleAttributeIfNeeded(editor.dom, li);
|
|
17446
17465
|
});
|
|
17447
17466
|
}
|
|
17448
17467
|
else {
|
|
17449
17468
|
getExpandedListItemFormat(editor.formatter, name).each((liFmt) => {
|
|
17450
|
-
each$e(getPartiallySelectedListItems(editor
|
|
17469
|
+
each$e(getPartiallySelectedListItems(editor), (li) => removeStyles$1(editor.dom, li, liFmt, vars, null));
|
|
17451
17470
|
});
|
|
17452
17471
|
}
|
|
17453
17472
|
};
|
|
@@ -18628,7 +18647,7 @@
|
|
|
18628
18647
|
}
|
|
18629
18648
|
};
|
|
18630
18649
|
|
|
18631
|
-
/*! @license DOMPurify 3.4.
|
|
18650
|
+
/*! @license DOMPurify 3.4.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.11/LICENSE */
|
|
18632
18651
|
|
|
18633
18652
|
function _arrayLikeToArray(r, a) {
|
|
18634
18653
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -18957,16 +18976,31 @@
|
|
|
18957
18976
|
);
|
|
18958
18977
|
const DOCTYPE_NAME = seal(/^html$/i);
|
|
18959
18978
|
const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
18979
|
+
// Markup-significant character probes used by _sanitizeElements.
|
|
18980
|
+
// Shared module-level instances are safe despite the sticky /g flags:
|
|
18981
|
+
// unapply() resets lastIndex for RegExp receivers before every call.
|
|
18982
|
+
const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
|
|
18983
|
+
const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
|
|
18984
|
+
const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
|
|
18985
|
+
const SELF_CLOSING_TAG = seal(/\/>/i);
|
|
18960
18986
|
|
|
18961
|
-
/* eslint-disable @typescript-eslint/indent */
|
|
18962
18987
|
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
|
|
18963
18988
|
const NODE_TYPE = {
|
|
18964
18989
|
element: 1,
|
|
18990
|
+
attribute: 2,
|
|
18965
18991
|
text: 3,
|
|
18992
|
+
cdataSection: 4,
|
|
18993
|
+
entityReference: 5,
|
|
18966
18994
|
// Deprecated
|
|
18967
|
-
|
|
18995
|
+
entityNode: 6,
|
|
18996
|
+
// Deprecated
|
|
18997
|
+
processingInstruction: 7,
|
|
18968
18998
|
comment: 8,
|
|
18969
|
-
document: 9
|
|
18999
|
+
document: 9,
|
|
19000
|
+
documentType: 10,
|
|
19001
|
+
documentFragment: 11,
|
|
19002
|
+
notation: 12 // Deprecated
|
|
19003
|
+
};
|
|
18970
19004
|
const getGlobal = function getGlobal() {
|
|
18971
19005
|
return typeof window === 'undefined' ? null : window;
|
|
18972
19006
|
};
|
|
@@ -19021,10 +19055,25 @@
|
|
|
19021
19055
|
uponSanitizeShadowNode: []
|
|
19022
19056
|
};
|
|
19023
19057
|
};
|
|
19058
|
+
/**
|
|
19059
|
+
* Resolve a set-valued configuration option: a fresh set built from
|
|
19060
|
+
* cfg[key] when it is an own array property (seeded with a clone of
|
|
19061
|
+
* options.base when given, case-normalized via options.transform),
|
|
19062
|
+
* the fallback set otherwise.
|
|
19063
|
+
*
|
|
19064
|
+
* @param cfg the cloned, prototype-free configuration object
|
|
19065
|
+
* @param key the configuration property to read
|
|
19066
|
+
* @param fallback the set to use when the option is absent or not an array
|
|
19067
|
+
* @param options transform and optional base set to merge into
|
|
19068
|
+
* @returns the resolved set
|
|
19069
|
+
*/
|
|
19070
|
+
const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
|
|
19071
|
+
return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
|
|
19072
|
+
};
|
|
19024
19073
|
function createDOMPurify() {
|
|
19025
19074
|
let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
|
|
19026
19075
|
const DOMPurify = root => createDOMPurify(root);
|
|
19027
|
-
DOMPurify.version = '3.4.
|
|
19076
|
+
DOMPurify.version = '3.4.11';
|
|
19028
19077
|
DOMPurify.removed = [];
|
|
19029
19078
|
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
|
|
19030
19079
|
// Not running in a browser, provide a factory function
|
|
@@ -19035,15 +19084,15 @@
|
|
|
19035
19084
|
let document = window.document;
|
|
19036
19085
|
const originalDocument = document;
|
|
19037
19086
|
const currentScript = originalDocument.currentScript;
|
|
19038
|
-
|
|
19039
|
-
HTMLTemplateElement = window.HTMLTemplateElement,
|
|
19087
|
+
window.DocumentFragment;
|
|
19088
|
+
const HTMLTemplateElement = window.HTMLTemplateElement,
|
|
19040
19089
|
Node = window.Node,
|
|
19041
19090
|
Element = window.Element,
|
|
19042
19091
|
NodeFilter = window.NodeFilter,
|
|
19043
|
-
_window$NamedNodeMap = window.NamedNodeMap
|
|
19044
|
-
|
|
19045
|
-
|
|
19046
|
-
DOMParser = window.DOMParser,
|
|
19092
|
+
_window$NamedNodeMap = window.NamedNodeMap;
|
|
19093
|
+
_window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap;
|
|
19094
|
+
window.HTMLFormElement;
|
|
19095
|
+
const DOMParser = window.DOMParser,
|
|
19047
19096
|
trustedTypes = window.trustedTypes;
|
|
19048
19097
|
const ElementPrototype = Element.prototype;
|
|
19049
19098
|
const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
|
|
@@ -19051,7 +19100,10 @@
|
|
|
19051
19100
|
const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
|
|
19052
19101
|
const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
|
|
19053
19102
|
const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
|
|
19103
|
+
const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
|
|
19104
|
+
const getAttributes = lookupGetter(ElementPrototype, 'attributes');
|
|
19054
19105
|
const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
|
|
19106
|
+
const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
|
|
19055
19107
|
// As per issue #47, the web-components registry is inherited by a
|
|
19056
19108
|
// new document created via createHTMLDocument. As per the spec
|
|
19057
19109
|
// (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
|
|
@@ -19066,6 +19118,54 @@
|
|
|
19066
19118
|
}
|
|
19067
19119
|
let trustedTypesPolicy;
|
|
19068
19120
|
let emptyHTML = '';
|
|
19121
|
+
// The instance's own internal Trusted Types policy. Unlike a caller-supplied
|
|
19122
|
+
// `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
|
|
19123
|
+
// on duplicate policy names — and is the only policy allowed to persist
|
|
19124
|
+
// across configurations and survive `clearConfig()`.
|
|
19125
|
+
let defaultTrustedTypesPolicy;
|
|
19126
|
+
let defaultTrustedTypesPolicyResolved = false;
|
|
19127
|
+
// Tracks whether we are already inside a call to the configured Trusted Types
|
|
19128
|
+
// policy (`createHTML` or `createScriptURL`). If a supplied policy callback
|
|
19129
|
+
// itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
|
|
19130
|
+
// re-enter the policy and recurse until the stack overflows. We detect that
|
|
19131
|
+
// re-entry and throw a clear, actionable error instead. The guard is shared
|
|
19132
|
+
// across both callbacks, because either one re-entering `sanitize` triggers
|
|
19133
|
+
// the same unbounded recursion.
|
|
19134
|
+
let IN_TRUSTED_TYPES_POLICY = 0;
|
|
19135
|
+
const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
|
|
19136
|
+
if (IN_TRUSTED_TYPES_POLICY > 0) {
|
|
19137
|
+
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.');
|
|
19138
|
+
}
|
|
19139
|
+
};
|
|
19140
|
+
const _createTrustedHTML = function _createTrustedHTML(html) {
|
|
19141
|
+
_assertNotInTrustedTypesPolicy();
|
|
19142
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
19143
|
+
try {
|
|
19144
|
+
return trustedTypesPolicy.createHTML(html);
|
|
19145
|
+
} finally {
|
|
19146
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
19147
|
+
}
|
|
19148
|
+
};
|
|
19149
|
+
const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
|
|
19150
|
+
_assertNotInTrustedTypesPolicy();
|
|
19151
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
19152
|
+
try {
|
|
19153
|
+
return trustedTypesPolicy.createScriptURL(scriptUrl);
|
|
19154
|
+
} finally {
|
|
19155
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
19156
|
+
}
|
|
19157
|
+
};
|
|
19158
|
+
// Lazily resolve (and cache) the instance's internal default policy.
|
|
19159
|
+
// Resolution is attempted at most once: a successful `createPolicy` cannot be
|
|
19160
|
+
// repeated (Trusted Types throws on duplicate names), and a failed or
|
|
19161
|
+
// unsupported attempt must not be retried on every parse.
|
|
19162
|
+
const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
|
|
19163
|
+
if (!defaultTrustedTypesPolicyResolved) {
|
|
19164
|
+
defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
19165
|
+
defaultTrustedTypesPolicyResolved = true;
|
|
19166
|
+
}
|
|
19167
|
+
return defaultTrustedTypesPolicy;
|
|
19168
|
+
};
|
|
19069
19169
|
const _document = document,
|
|
19070
19170
|
implementation = _document.implementation,
|
|
19071
19171
|
createNodeIterator = _document.createNodeIterator,
|
|
@@ -19162,6 +19262,13 @@
|
|
|
19162
19262
|
let WHOLE_DOCUMENT = false;
|
|
19163
19263
|
/* Track whether config is already set on this instance of DOMPurify. */
|
|
19164
19264
|
let SET_CONFIG = false;
|
|
19265
|
+
/* Pristine allowlist bindings captured at setConfig() time. On the
|
|
19266
|
+
* persistent-config path sanitize() restores the sets from these before
|
|
19267
|
+
* the per-walk hook clone-guard, so a hook's in-call widening cannot
|
|
19268
|
+
* carry across calls. Null until setConfig() is called; reset by
|
|
19269
|
+
* clearConfig(). */
|
|
19270
|
+
let SET_CONFIG_ALLOWED_TAGS = null;
|
|
19271
|
+
let SET_CONFIG_ALLOWED_ATTR = null;
|
|
19165
19272
|
/* Decide if all elements (e.g. style, script) must be children of
|
|
19166
19273
|
* document.body. By default, browsers might move them to document.head */
|
|
19167
19274
|
let FORCE_BODY = false;
|
|
@@ -19204,7 +19311,17 @@
|
|
|
19204
19311
|
let USE_PROFILES = {};
|
|
19205
19312
|
/* Tags to ignore content of when KEEP_CONTENT is true */
|
|
19206
19313
|
let FORBID_CONTENTS = null;
|
|
19207
|
-
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
|
|
19314
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
|
|
19315
|
+
// <selectedcontent> mirrors the selected <option>'s subtree, cloned by
|
|
19316
|
+
// the UA (customizable <select>) — including any on* handlers — and the
|
|
19317
|
+
// engine re-mirrors synchronously whenever a removal changes which
|
|
19318
|
+
// option/selectedcontent is current, even inside DOMPurify's inert
|
|
19319
|
+
// DOMParser document. Hoisting its children on removal re-inserts a fresh
|
|
19320
|
+
// mirror target ahead of the walk, which the engine refills, looping
|
|
19321
|
+
// forever (DoS) and amplifying output. Dropping its content on removal
|
|
19322
|
+
// (rather than hoisting) breaks that cascade; the content is a duplicate
|
|
19323
|
+
// of the option, which is sanitized on its own. See campaign-3 F1/F6.
|
|
19324
|
+
'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
|
|
19208
19325
|
/* Tags that are safe for data: URIs */
|
|
19209
19326
|
let DATA_URI_TAGS = null;
|
|
19210
19327
|
const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
|
|
@@ -19220,8 +19337,10 @@
|
|
|
19220
19337
|
/* Allowed XHTML+XML namespaces */
|
|
19221
19338
|
let ALLOWED_NAMESPACES = null;
|
|
19222
19339
|
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
19223
|
-
|
|
19224
|
-
let
|
|
19340
|
+
const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
|
|
19341
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
|
|
19342
|
+
const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
|
|
19343
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
|
|
19225
19344
|
// Certain elements are allowed in both SVG and HTML
|
|
19226
19345
|
// namespace. We need to specify them explicitly
|
|
19227
19346
|
// so that they don't get erroneously deleted from
|
|
@@ -19263,14 +19382,32 @@
|
|
|
19263
19382
|
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
|
|
19264
19383
|
transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
|
|
19265
19384
|
/* Set configuration parameters */
|
|
19266
|
-
ALLOWED_TAGS =
|
|
19267
|
-
|
|
19268
|
-
|
|
19269
|
-
|
|
19270
|
-
|
|
19271
|
-
|
|
19272
|
-
|
|
19273
|
-
|
|
19385
|
+
ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
|
|
19386
|
+
transform: transformCaseFunc
|
|
19387
|
+
});
|
|
19388
|
+
ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
|
|
19389
|
+
transform: transformCaseFunc
|
|
19390
|
+
});
|
|
19391
|
+
ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
|
|
19392
|
+
transform: stringToString
|
|
19393
|
+
});
|
|
19394
|
+
URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
|
|
19395
|
+
transform: transformCaseFunc,
|
|
19396
|
+
base: DEFAULT_URI_SAFE_ATTRIBUTES
|
|
19397
|
+
});
|
|
19398
|
+
DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
|
|
19399
|
+
transform: transformCaseFunc,
|
|
19400
|
+
base: DEFAULT_DATA_URI_TAGS
|
|
19401
|
+
});
|
|
19402
|
+
FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
|
|
19403
|
+
transform: transformCaseFunc
|
|
19404
|
+
});
|
|
19405
|
+
FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
|
|
19406
|
+
transform: transformCaseFunc
|
|
19407
|
+
});
|
|
19408
|
+
FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
|
|
19409
|
+
transform: transformCaseFunc
|
|
19410
|
+
});
|
|
19274
19411
|
USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
|
|
19275
19412
|
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
|
|
19276
19413
|
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
|
|
@@ -19289,8 +19426,8 @@
|
|
|
19289
19426
|
IN_PLACE = cfg.IN_PLACE || false; // Default false
|
|
19290
19427
|
IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
|
|
19291
19428
|
NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
|
|
19292
|
-
MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({},
|
|
19293
|
-
HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({},
|
|
19429
|
+
MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS); // Default built-in map
|
|
19430
|
+
HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS); // Default built-in map
|
|
19294
19431
|
const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create$7(null);
|
|
19295
19432
|
CUSTOM_ELEMENT_HANDLING = create$7(null);
|
|
19296
19433
|
if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
|
|
@@ -19302,6 +19439,7 @@
|
|
|
19302
19439
|
if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
|
|
19303
19440
|
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
|
|
19304
19441
|
}
|
|
19442
|
+
seal(CUSTOM_ELEMENT_HANDLING);
|
|
19305
19443
|
if (SAFE_FOR_TEMPLATES) {
|
|
19306
19444
|
ALLOW_DATA_ATTR = false;
|
|
19307
19445
|
}
|
|
@@ -19385,6 +19523,13 @@
|
|
|
19385
19523
|
addToSet(ALLOWED_TAGS, ['tbody']);
|
|
19386
19524
|
delete FORBID_TAGS.tbody;
|
|
19387
19525
|
}
|
|
19526
|
+
// Re-derive the active Trusted Types policy from this configuration on
|
|
19527
|
+
// every parse. The active policy must never be sticky closure state that
|
|
19528
|
+
// outlives the config that set it: a caller-supplied policy left in place
|
|
19529
|
+
// after `clearConfig()` — or after a later call that supplied none, or
|
|
19530
|
+
// `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
|
|
19531
|
+
// `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
|
|
19532
|
+
// See GHSA-vxr8-fq34-vvx9.
|
|
19388
19533
|
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
19389
19534
|
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
|
|
19390
19535
|
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
@@ -19392,18 +19537,45 @@
|
|
|
19392
19537
|
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
|
|
19393
19538
|
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
19394
19539
|
}
|
|
19395
|
-
//
|
|
19540
|
+
// A caller-supplied policy applies to this configuration only.
|
|
19541
|
+
const previousTrustedTypesPolicy = trustedTypesPolicy;
|
|
19396
19542
|
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
19397
|
-
// Sign local variables required by `sanitize`.
|
|
19398
|
-
|
|
19543
|
+
// Sign local variables required by `sanitize`. If the supplied policy's
|
|
19544
|
+
// `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
|
|
19545
|
+
// throws via the re-entrancy guard. Restore the previous policy first so
|
|
19546
|
+
// the instance is not left in a poisoned state. See #1422.
|
|
19547
|
+
try {
|
|
19548
|
+
emptyHTML = _createTrustedHTML('');
|
|
19549
|
+
} catch (error) {
|
|
19550
|
+
trustedTypesPolicy = previousTrustedTypesPolicy;
|
|
19551
|
+
throw error;
|
|
19552
|
+
}
|
|
19553
|
+
} else if (cfg.TRUSTED_TYPES_POLICY === null) {
|
|
19554
|
+
// Explicit opt-out for this call: perform no Trusted Types signing and
|
|
19555
|
+
// create nothing (so a strict `trusted-types` CSP that disallows a
|
|
19556
|
+
// `dompurify` policy can still call `sanitize` from inside its own
|
|
19557
|
+
// policy — see #1422). Resetting to `undefined` rather than a sticky
|
|
19558
|
+
// `null` also drops any previously retained caller policy, so it cannot
|
|
19559
|
+
// resurface on a later call, while still allowing the next config-less
|
|
19560
|
+
// call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
|
|
19561
|
+
trustedTypesPolicy = undefined;
|
|
19562
|
+
emptyHTML = '';
|
|
19399
19563
|
} else {
|
|
19400
|
-
//
|
|
19564
|
+
// No policy supplied: keep the currently active policy if one is set — a
|
|
19565
|
+
// previously supplied policy is intentionally sticky across config-less
|
|
19566
|
+
// calls — otherwise fall back to the instance's own internal policy,
|
|
19567
|
+
// created at most once. (A policy supplied for a *single* call still
|
|
19568
|
+
// lingers by design; what must not linger is a policy whose configuration
|
|
19569
|
+
// has been torn down via `clearConfig()`, which restores the default.)
|
|
19401
19570
|
if (trustedTypesPolicy === undefined) {
|
|
19402
|
-
trustedTypesPolicy =
|
|
19571
|
+
trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
|
|
19403
19572
|
}
|
|
19404
|
-
//
|
|
19405
|
-
|
|
19406
|
-
|
|
19573
|
+
// Sign internal variables only when a policy is active. A falsy policy
|
|
19574
|
+
// (Trusted Types unsupported, creation failed, or an explicit opt-out)
|
|
19575
|
+
// leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
|
|
19576
|
+
// a non-policy and throw. See #1422.
|
|
19577
|
+
if (trustedTypesPolicy && typeof emptyHTML === 'string') {
|
|
19578
|
+
emptyHTML = _createTrustedHTML('');
|
|
19407
19579
|
}
|
|
19408
19580
|
}
|
|
19409
19581
|
// Prevent further manipulation of configuration.
|
|
@@ -19418,6 +19590,77 @@
|
|
|
19418
19590
|
* correctly. */
|
|
19419
19591
|
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
19420
19592
|
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
19593
|
+
/**
|
|
19594
|
+
* Namespace rules for an element in the SVG namespace.
|
|
19595
|
+
*
|
|
19596
|
+
* @param tagName the element's lowercase tag name
|
|
19597
|
+
* @param parent the (possibly simulated) parent node
|
|
19598
|
+
* @param parentTagName the parent's lowercase tag name
|
|
19599
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
19600
|
+
*/
|
|
19601
|
+
const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
|
|
19602
|
+
// The only way to switch from HTML namespace to SVG
|
|
19603
|
+
// is via <svg>. If it happens via any other tag, then
|
|
19604
|
+
// it should be killed.
|
|
19605
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
19606
|
+
return tagName === 'svg';
|
|
19607
|
+
}
|
|
19608
|
+
// The only way to switch from MathML to SVG is via <svg>
|
|
19609
|
+
// if the parent is either <annotation-xml> or a MathML
|
|
19610
|
+
// text integration point.
|
|
19611
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
19612
|
+
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
19613
|
+
}
|
|
19614
|
+
// We only allow elements that are defined in SVG
|
|
19615
|
+
// spec. All others are disallowed in SVG namespace.
|
|
19616
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
19617
|
+
};
|
|
19618
|
+
/**
|
|
19619
|
+
* Namespace rules for an element in the MathML namespace.
|
|
19620
|
+
*
|
|
19621
|
+
* @param tagName the element's lowercase tag name
|
|
19622
|
+
* @param parent the (possibly simulated) parent node
|
|
19623
|
+
* @param parentTagName the parent's lowercase tag name
|
|
19624
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
19625
|
+
*/
|
|
19626
|
+
const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
|
|
19627
|
+
// The only way to switch from HTML namespace to MathML
|
|
19628
|
+
// is via <math>. If it happens via any other tag, then
|
|
19629
|
+
// it should be killed.
|
|
19630
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
19631
|
+
return tagName === 'math';
|
|
19632
|
+
}
|
|
19633
|
+
// The only way to switch from SVG to MathML is via
|
|
19634
|
+
// <math> and HTML integration points
|
|
19635
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
19636
|
+
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
19637
|
+
}
|
|
19638
|
+
// We only allow elements that are defined in MathML
|
|
19639
|
+
// spec. All others are disallowed in MathML namespace.
|
|
19640
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
19641
|
+
};
|
|
19642
|
+
/**
|
|
19643
|
+
* Namespace rules for an element in the HTML namespace.
|
|
19644
|
+
*
|
|
19645
|
+
* @param tagName the element's lowercase tag name
|
|
19646
|
+
* @param parent the (possibly simulated) parent node
|
|
19647
|
+
* @param parentTagName the parent's lowercase tag name
|
|
19648
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
19649
|
+
*/
|
|
19650
|
+
const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
|
|
19651
|
+
// The only way to switch from SVG to HTML is via
|
|
19652
|
+
// HTML integration points, and from MathML to HTML
|
|
19653
|
+
// is via MathML text integration points
|
|
19654
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
19655
|
+
return false;
|
|
19656
|
+
}
|
|
19657
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
19658
|
+
return false;
|
|
19659
|
+
}
|
|
19660
|
+
// We disallow tags that are specific for MathML
|
|
19661
|
+
// or SVG and should never appear in HTML namespace
|
|
19662
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
19663
|
+
};
|
|
19421
19664
|
/**
|
|
19422
19665
|
* @param element a DOM element whose namespace is being checked
|
|
19423
19666
|
* @returns Return false if the element has a
|
|
@@ -19440,51 +19683,13 @@
|
|
|
19440
19683
|
return false;
|
|
19441
19684
|
}
|
|
19442
19685
|
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
19443
|
-
|
|
19444
|
-
// is via <svg>. If it happens via any other tag, then
|
|
19445
|
-
// it should be killed.
|
|
19446
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
19447
|
-
return tagName === 'svg';
|
|
19448
|
-
}
|
|
19449
|
-
// The only way to switch from MathML to SVG is via`
|
|
19450
|
-
// svg if parent is either <annotation-xml> or MathML
|
|
19451
|
-
// text integration points.
|
|
19452
|
-
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
19453
|
-
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
19454
|
-
}
|
|
19455
|
-
// We only allow elements that are defined in SVG
|
|
19456
|
-
// spec. All others are disallowed in SVG namespace.
|
|
19457
|
-
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
19686
|
+
return _checkSvgNamespace(tagName, parent, parentTagName);
|
|
19458
19687
|
}
|
|
19459
19688
|
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
19460
|
-
|
|
19461
|
-
// is via <math>. If it happens via any other tag, then
|
|
19462
|
-
// it should be killed.
|
|
19463
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
19464
|
-
return tagName === 'math';
|
|
19465
|
-
}
|
|
19466
|
-
// The only way to switch from SVG to MathML is via
|
|
19467
|
-
// <math> and HTML integration points
|
|
19468
|
-
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
19469
|
-
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
19470
|
-
}
|
|
19471
|
-
// We only allow elements that are defined in MathML
|
|
19472
|
-
// spec. All others are disallowed in MathML namespace.
|
|
19473
|
-
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
19689
|
+
return _checkMathMlNamespace(tagName, parent, parentTagName);
|
|
19474
19690
|
}
|
|
19475
19691
|
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
19476
|
-
|
|
19477
|
-
// HTML integration points, and from MathML to HTML
|
|
19478
|
-
// is via MathML text integration points
|
|
19479
|
-
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
19480
|
-
return false;
|
|
19481
|
-
}
|
|
19482
|
-
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
19483
|
-
return false;
|
|
19484
|
-
}
|
|
19485
|
-
// We disallow tags that are specific for MathML
|
|
19486
|
-
// or SVG and should never appear in HTML namespace
|
|
19487
|
-
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
19692
|
+
return _checkHtmlNamespace(tagName, parent, parentTagName);
|
|
19488
19693
|
}
|
|
19489
19694
|
// For XHTML and XML documents that support custom namespaces
|
|
19490
19695
|
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
@@ -19509,7 +19714,74 @@
|
|
|
19509
19714
|
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
19510
19715
|
getParentNode(node).removeChild(node);
|
|
19511
19716
|
} catch (_) {
|
|
19717
|
+
/* The normal detach failed — this is reached for a parentless node
|
|
19718
|
+
(getParentNode() is null, so .removeChild throws). Element.prototype
|
|
19719
|
+
.remove() is itself a spec no-op on a parentless node, so a recorded
|
|
19720
|
+
"removal" would otherwise hand the caller back an intact,
|
|
19721
|
+
payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
|
|
19722
|
+
the style-with-element-child rule decided to kill). Fail closed by
|
|
19723
|
+
throwing — exactly as a clobbered root does at the IN_PLACE entry —
|
|
19724
|
+
rather than trying to "neutralize" the node via its own methods.
|
|
19725
|
+
Neutralizing would mean calling getAttributeNames()/removeAttribute()
|
|
19726
|
+
on the node, both of which a <form> root can clobber via a named child
|
|
19727
|
+
(and _isClobbered does not even probe getAttributeNames), so the
|
|
19728
|
+
neutralize step could itself be silently defeated, leaving the payload
|
|
19729
|
+
intact. A throw touches only the cached, clobber-safe remove() and
|
|
19730
|
+
getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
|
|
19731
|
+
to every root-kill reason. REPORT-3.
|
|
19732
|
+
This lives inside the catch, so it never fires for a normally-removed
|
|
19733
|
+
in-tree node: those have a parent, removeChild() succeeds, and the
|
|
19734
|
+
catch is not entered. Only a kept (parentless) root reaches here. */
|
|
19512
19735
|
remove(node);
|
|
19736
|
+
if (!getParentNode(node)) {
|
|
19737
|
+
throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
|
|
19738
|
+
}
|
|
19739
|
+
}
|
|
19740
|
+
};
|
|
19741
|
+
/**
|
|
19742
|
+
* _neutralizeRoot
|
|
19743
|
+
*
|
|
19744
|
+
* Fail-closed teardown of an in-place root after the sanitize walk aborts
|
|
19745
|
+
* (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
|
|
19746
|
+
* custom element's reaction detaches a node so `_forceRemove`'s deliberate
|
|
19747
|
+
* parentless guard throws, or any other re-entrant engine mutation — would
|
|
19748
|
+
* otherwise leave the caller's *live* tree half-sanitized, with everything
|
|
19749
|
+
* after the abort point still carrying its handlers. There is no safe way
|
|
19750
|
+
* to resume the walk (the tree mutated under us), so we strip the root bare:
|
|
19751
|
+
* remove every child and every attribute, then let the caller's catch see
|
|
19752
|
+
* the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
|
|
19753
|
+
* getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
|
|
19754
|
+
*
|
|
19755
|
+
* @param root the in-place root to empty
|
|
19756
|
+
*/
|
|
19757
|
+
const _neutralizeRoot = function _neutralizeRoot(root) {
|
|
19758
|
+
const childNodes = getChildNodes(root);
|
|
19759
|
+
if (childNodes) {
|
|
19760
|
+
const snapshot = [];
|
|
19761
|
+
arrayForEach(childNodes, child => {
|
|
19762
|
+
arrayPush(snapshot, child);
|
|
19763
|
+
});
|
|
19764
|
+
arrayForEach(snapshot, child => {
|
|
19765
|
+
try {
|
|
19766
|
+
remove(child);
|
|
19767
|
+
} catch (_) {
|
|
19768
|
+
/* Best-effort teardown; a still-attached child is handled below */
|
|
19769
|
+
}
|
|
19770
|
+
});
|
|
19771
|
+
}
|
|
19772
|
+
const attributes = getAttributes(root);
|
|
19773
|
+
if (attributes) {
|
|
19774
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
19775
|
+
const attribute = attributes[i];
|
|
19776
|
+
const name = attribute && attribute.name;
|
|
19777
|
+
if (typeof name === 'string') {
|
|
19778
|
+
try {
|
|
19779
|
+
root.removeAttribute(name);
|
|
19780
|
+
} catch (_) {
|
|
19781
|
+
/* Clobbered removeAttribute — ignore (fail-closed best effort) */
|
|
19782
|
+
}
|
|
19783
|
+
}
|
|
19784
|
+
}
|
|
19513
19785
|
}
|
|
19514
19786
|
};
|
|
19515
19787
|
/**
|
|
@@ -19544,6 +19816,72 @@
|
|
|
19544
19816
|
}
|
|
19545
19817
|
}
|
|
19546
19818
|
};
|
|
19819
|
+
/**
|
|
19820
|
+
* _stripDisallowedAttributes
|
|
19821
|
+
*
|
|
19822
|
+
* Removes every attribute the active configuration does not allow from a
|
|
19823
|
+
* single element, using the same allowlist as the main attribute pass (so
|
|
19824
|
+
* `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
|
|
19825
|
+
* neutralise nodes that are being discarded from an in-place tree.
|
|
19826
|
+
*
|
|
19827
|
+
* @param element the element to strip
|
|
19828
|
+
*/
|
|
19829
|
+
const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
|
|
19830
|
+
const attributes = getAttributes(element);
|
|
19831
|
+
if (!attributes) {
|
|
19832
|
+
return;
|
|
19833
|
+
}
|
|
19834
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
19835
|
+
const attribute = attributes[i];
|
|
19836
|
+
const name = attribute && attribute.name;
|
|
19837
|
+
if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
|
|
19838
|
+
continue;
|
|
19839
|
+
}
|
|
19840
|
+
try {
|
|
19841
|
+
element.removeAttribute(name);
|
|
19842
|
+
} catch (_) {
|
|
19843
|
+
/* Clobbered removeAttribute on a doomed node — ignore */
|
|
19844
|
+
}
|
|
19845
|
+
}
|
|
19846
|
+
};
|
|
19847
|
+
/**
|
|
19848
|
+
* _neutralizeSubtree
|
|
19849
|
+
*
|
|
19850
|
+
* Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
|
|
19851
|
+
* move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
|
|
19852
|
+
* namespace, comment, processing-instruction and KEEP_CONTENT:false removals
|
|
19853
|
+
* all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
|
|
19854
|
+
* those dropped nodes are detached from the caller's LIVE tree but a
|
|
19855
|
+
* handler-bearing original among them (an `<img onerror>`/`<video>` that was
|
|
19856
|
+
* loading) keeps its queued resource event, which fires in page scope after
|
|
19857
|
+
* sanitize returns. This walks a removed subtree and strips every attribute
|
|
19858
|
+
* the active configuration does not allow — so `on*` handlers are cancelled
|
|
19859
|
+
* through the SAME allowlist that governs kept nodes, not a separate `/^on/`
|
|
19860
|
+
* blocklist. Run synchronously before sanitize returns, i.e. before any
|
|
19861
|
+
* queued event can fire. Hook-free by design: these nodes leave the output,
|
|
19862
|
+
* so firing attribute hooks for them would be surprising. Clobber-safe reads;
|
|
19863
|
+
* a doomed clobbered node may shadow `removeAttribute` (its own attributes are
|
|
19864
|
+
* irrelevant — it is discarded — while its non-clobbered descendants, e.g.
|
|
19865
|
+
* the `<img>`, are reached and scrubbed).
|
|
19866
|
+
*
|
|
19867
|
+
* @param root the root of a removed subtree to neutralise
|
|
19868
|
+
*/
|
|
19869
|
+
const _neutralizeSubtree = function _neutralizeSubtree(root) {
|
|
19870
|
+
const stack = [root];
|
|
19871
|
+
while (stack.length > 0) {
|
|
19872
|
+
const node = stack.pop();
|
|
19873
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
19874
|
+
if (nodeType === NODE_TYPE.element) {
|
|
19875
|
+
_stripDisallowedAttributes(node);
|
|
19876
|
+
}
|
|
19877
|
+
const childNodes = getChildNodes(node);
|
|
19878
|
+
if (childNodes) {
|
|
19879
|
+
for (let i = childNodes.length - 1; i >= 0; --i) {
|
|
19880
|
+
stack.push(childNodes[i]);
|
|
19881
|
+
}
|
|
19882
|
+
}
|
|
19883
|
+
}
|
|
19884
|
+
};
|
|
19547
19885
|
/**
|
|
19548
19886
|
* _initDocument
|
|
19549
19887
|
*
|
|
@@ -19565,7 +19903,7 @@
|
|
|
19565
19903
|
// Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
|
|
19566
19904
|
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
|
|
19567
19905
|
}
|
|
19568
|
-
const dirtyPayload = trustedTypesPolicy ?
|
|
19906
|
+
const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
|
|
19569
19907
|
/*
|
|
19570
19908
|
* Use the DOMParser API by default, fallback later if needs be
|
|
19571
19909
|
* DOMParser not work for svg when has multiple root element.
|
|
@@ -19605,6 +19943,20 @@
|
|
|
19605
19943
|
// eslint-disable-next-line no-bitwise
|
|
19606
19944
|
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
19607
19945
|
};
|
|
19946
|
+
/**
|
|
19947
|
+
* Replace template expression syntax (mustache, ERB, template
|
|
19948
|
+
* literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
|
|
19949
|
+
* sites. Order matters: mustache, then ERB, then template literal.
|
|
19950
|
+
*
|
|
19951
|
+
* @param value the string to scrub
|
|
19952
|
+
* @returns the scrubbed string
|
|
19953
|
+
*/
|
|
19954
|
+
const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
|
|
19955
|
+
value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
|
|
19956
|
+
value = stringReplace(value, ERB_EXPR$1, ' ');
|
|
19957
|
+
value = stringReplace(value, TMPLIT_EXPR$1, ' ');
|
|
19958
|
+
return value;
|
|
19959
|
+
};
|
|
19608
19960
|
/**
|
|
19609
19961
|
* Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
|
|
19610
19962
|
* character data of an element subtree. Used as the final safety net for
|
|
@@ -19624,29 +19976,100 @@
|
|
|
19624
19976
|
*
|
|
19625
19977
|
* @param node The root element whose character data should be scrubbed.
|
|
19626
19978
|
*/
|
|
19627
|
-
const
|
|
19979
|
+
const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
|
|
19980
|
+
var _node$querySelectorAl;
|
|
19628
19981
|
node.normalize();
|
|
19629
19982
|
const walker = createNodeIterator.call(node.ownerDocument || node, node,
|
|
19630
19983
|
// eslint-disable-next-line no-bitwise
|
|
19631
19984
|
NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
|
|
19632
19985
|
let currentNode = walker.nextNode();
|
|
19633
19986
|
while (currentNode) {
|
|
19634
|
-
|
|
19635
|
-
arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
|
|
19636
|
-
data = stringReplace(data, expr, ' ');
|
|
19637
|
-
});
|
|
19638
|
-
currentNode.data = data;
|
|
19987
|
+
currentNode.data = _stripTemplateExpressions(currentNode.data);
|
|
19639
19988
|
currentNode = walker.nextNode();
|
|
19640
19989
|
}
|
|
19990
|
+
// NodeIterator does not descend into <template>.content per the DOM spec,
|
|
19991
|
+
// so we must explicitly recurse into each template's content fragment,
|
|
19992
|
+
// mirroring the approach used by _sanitizeShadowDOM.
|
|
19993
|
+
const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
|
|
19994
|
+
if (templates) {
|
|
19995
|
+
arrayForEach(templates, tmpl => {
|
|
19996
|
+
if (_isDocumentFragment(tmpl.content)) {
|
|
19997
|
+
_scrubTemplateExpressions2(tmpl.content);
|
|
19998
|
+
}
|
|
19999
|
+
});
|
|
20000
|
+
}
|
|
19641
20001
|
};
|
|
19642
20002
|
/**
|
|
19643
20003
|
* _isClobbered
|
|
19644
20004
|
*
|
|
20005
|
+
* Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
|
|
20006
|
+
* interface with [LegacyOverrideBuiltIns]; a descendant element with a
|
|
20007
|
+
* `name` attribute matching a prototype property shadows that property
|
|
20008
|
+
* on direct reads. We use this check at the IN_PLACE entry-point and
|
|
20009
|
+
* during attribute sanitization to refuse clobbered forms.
|
|
20010
|
+
*
|
|
19645
20011
|
* @param element element to check for clobbering attacks
|
|
19646
20012
|
* @return true if clobbered, false if safe
|
|
19647
20013
|
*/
|
|
19648
20014
|
const _isClobbered = function _isClobbered(element) {
|
|
19649
|
-
|
|
20015
|
+
// Realm-independent tag-name probe. If we can't determine the tag
|
|
20016
|
+
// name at all, we can't reason about clobbering — return false
|
|
20017
|
+
// (the caller's other defences still apply).
|
|
20018
|
+
const realTagName = getNodeName ? getNodeName(element) : null;
|
|
20019
|
+
if (typeof realTagName !== 'string') {
|
|
20020
|
+
return false;
|
|
20021
|
+
}
|
|
20022
|
+
if (transformCaseFunc(realTagName) !== 'form') {
|
|
20023
|
+
return false;
|
|
20024
|
+
}
|
|
20025
|
+
return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
|
|
20026
|
+
// Realm-safe NamedNodeMap detection: equality against the cached
|
|
20027
|
+
// prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
|
|
20028
|
+
// makes the direct read diverge from the cached read; a clean form
|
|
20029
|
+
// (same-realm OR foreign-realm) has both reads pointing at the same
|
|
20030
|
+
// canonical NamedNodeMap.
|
|
20031
|
+
element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
|
|
20032
|
+
// NodeType clobbering probe. Cached Node.prototype.nodeType getter
|
|
20033
|
+
// returns the integer 1 for any Element regardless of realm; direct
|
|
20034
|
+
// read on a clobbered form (e.g. <input name="nodeType">) returns
|
|
20035
|
+
// the named child element. Cheap addition — nodeType is read from
|
|
20036
|
+
// an internal slot, no serialization cost — and removes a residual
|
|
20037
|
+
// clobbering surface used by several mXSS / PI / comment branches
|
|
20038
|
+
// in _sanitizeElements that compare currentNode.nodeType directly.
|
|
20039
|
+
element.nodeType !== getNodeType(element) ||
|
|
20040
|
+
// HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
|
|
20041
|
+
// "childNodes" shadows the prototype getter. Direct reads of
|
|
20042
|
+
// form.childNodes from a clobbered form return the named child
|
|
20043
|
+
// instead of the real NodeList, so any walk that reads it directly
|
|
20044
|
+
// skips the form's real children. Compare the direct read to the
|
|
20045
|
+
// cached Node.prototype getter — when the form's named-property
|
|
20046
|
+
// getter intercepts the read, the two values differ and we flag
|
|
20047
|
+
// the form. This catches every clobbering child type (input,
|
|
20048
|
+
// select, etc.) regardless of whether the named child happens to
|
|
20049
|
+
// carry a numeric .length, which a typeof-based probe would miss
|
|
20050
|
+
// (e.g. HTMLSelectElement.length is a defined unsigned-long).
|
|
20051
|
+
element.childNodes !== getChildNodes(element);
|
|
20052
|
+
};
|
|
20053
|
+
/**
|
|
20054
|
+
* Checks whether the given value is a DocumentFragment from any realm.
|
|
20055
|
+
*
|
|
20056
|
+
* The realm-independent replacement reads `nodeType` through the cached
|
|
20057
|
+
* Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
|
|
20058
|
+
* constant (11). nodeType is a numeric value resolved from the node's
|
|
20059
|
+
* internal slot, identical across realms for the same kind of node.
|
|
20060
|
+
*
|
|
20061
|
+
* @param value object to check
|
|
20062
|
+
* @return true if value is a DocumentFragment-shaped node from any realm
|
|
20063
|
+
*/
|
|
20064
|
+
const _isDocumentFragment = function _isDocumentFragment(value) {
|
|
20065
|
+
if (!getNodeType || typeof value !== 'object' || value === null) {
|
|
20066
|
+
return false;
|
|
20067
|
+
}
|
|
20068
|
+
try {
|
|
20069
|
+
return getNodeType(value) === NODE_TYPE.documentFragment;
|
|
20070
|
+
} catch (_) {
|
|
20071
|
+
return false;
|
|
20072
|
+
}
|
|
19650
20073
|
};
|
|
19651
20074
|
/**
|
|
19652
20075
|
* Checks whether the given object is a DOM node, including nodes that
|
|
@@ -19656,12 +20079,6 @@
|
|
|
19656
20079
|
* sanitize() to silently stringify them and reset IN_PLACE to false,
|
|
19657
20080
|
* returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
|
|
19658
20081
|
*
|
|
19659
|
-
* Implementation: call the cached `nodeType` getter from Node.prototype
|
|
19660
|
-
* directly on the value. This bypasses any clobbered instance property
|
|
19661
|
-
* (e.g. a child element named "nodeType") and works across realms
|
|
19662
|
-
* because the WebIDL `nodeType` getter reads an internal slot that
|
|
19663
|
-
* every real Node has, regardless of which window minted it.
|
|
19664
|
-
*
|
|
19665
20082
|
* @param value object to check whether it's a DOM node
|
|
19666
20083
|
* @return true if value is a DOM node from any realm
|
|
19667
20084
|
*/
|
|
@@ -19676,10 +20093,104 @@
|
|
|
19676
20093
|
}
|
|
19677
20094
|
};
|
|
19678
20095
|
function _executeHooks(hooks, currentNode, data) {
|
|
20096
|
+
if (hooks.length === 0) {
|
|
20097
|
+
return;
|
|
20098
|
+
}
|
|
19679
20099
|
arrayForEach(hooks, hook => {
|
|
19680
20100
|
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
19681
20101
|
});
|
|
19682
20102
|
}
|
|
20103
|
+
/**
|
|
20104
|
+
* Structural-threat checks that condemn a node regardless of the
|
|
20105
|
+
* allowlists: mXSS via namespace confusion, risky CSS construction,
|
|
20106
|
+
* processing instructions, markup-bearing comments. Pure predicate;
|
|
20107
|
+
* the caller removes. Check order is load-bearing.
|
|
20108
|
+
*
|
|
20109
|
+
* @param currentNode the node to inspect
|
|
20110
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
20111
|
+
* @return true if the node must be removed
|
|
20112
|
+
*/
|
|
20113
|
+
const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
|
|
20114
|
+
/* Detect mXSS attempts abusing namespace confusion */
|
|
20115
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
|
|
20116
|
+
return true;
|
|
20117
|
+
}
|
|
20118
|
+
/* Remove risky CSS construction leading to mXSS */
|
|
20119
|
+
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
|
|
20120
|
+
return true;
|
|
20121
|
+
}
|
|
20122
|
+
/* Remove any occurrence of processing instructions */
|
|
20123
|
+
if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
|
|
20124
|
+
return true;
|
|
20125
|
+
}
|
|
20126
|
+
/* Remove any kind of possibly harmful comments */
|
|
20127
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
|
|
20128
|
+
return true;
|
|
20129
|
+
}
|
|
20130
|
+
return false;
|
|
20131
|
+
};
|
|
20132
|
+
/**
|
|
20133
|
+
* Handle a node whose tag is forbidden or not allowlisted: keep
|
|
20134
|
+
* allowed custom elements (false return exits _sanitizeElements
|
|
20135
|
+
* early - namespace/fallback checks and the afterSanitizeElements
|
|
20136
|
+
* hook are intentionally skipped for kept custom elements), else
|
|
20137
|
+
* hoist content per KEEP_CONTENT and remove.
|
|
20138
|
+
*
|
|
20139
|
+
* @param currentNode the disallowed node
|
|
20140
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
20141
|
+
* @return true if the node was removed, false if kept
|
|
20142
|
+
*/
|
|
20143
|
+
const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
|
|
20144
|
+
/* Check if we have a custom element to handle */
|
|
20145
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
20146
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
20147
|
+
return false;
|
|
20148
|
+
}
|
|
20149
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
20150
|
+
return false;
|
|
20151
|
+
}
|
|
20152
|
+
}
|
|
20153
|
+
/* Keep content except for bad-listed elements.
|
|
20154
|
+
Use the cached prototype getters exclusively — the previous code
|
|
20155
|
+
had `|| currentNode.parentNode` / `|| currentNode.childNodes`
|
|
20156
|
+
fallbacks, but the cached getters always return the canonical
|
|
20157
|
+
value (or null for a real parent-less node), so the fallback
|
|
20158
|
+
path was dead in safe cases and a clobbering surface in unsafe
|
|
20159
|
+
ones. Falsy cached results stay falsy; the `if (childNodes &&
|
|
20160
|
+
parentNode)` check already gates correctly. */
|
|
20161
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
20162
|
+
const parentNode = getParentNode(currentNode);
|
|
20163
|
+
const childNodes = getChildNodes(currentNode);
|
|
20164
|
+
if (childNodes && parentNode) {
|
|
20165
|
+
const childCount = childNodes.length;
|
|
20166
|
+
/* In-place: hoist the *original* children so the iterator visits
|
|
20167
|
+
and sanitises them through the same allowlist pass as every other
|
|
20168
|
+
node. The caller built the tree in the live document, so the
|
|
20169
|
+
originals carry already-queued resource events (`<img onerror>`,
|
|
20170
|
+
`<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
|
|
20171
|
+
those originals detached but still armed, firing in page scope
|
|
20172
|
+
while the returned tree looked clean. Moving is safe in-place: the
|
|
20173
|
+
root is pre-validated as an allowed tag and so is never the node
|
|
20174
|
+
being removed, which keeps `parentNode` inside the iterator root
|
|
20175
|
+
and the relocated child inside the serialised tree.
|
|
20176
|
+
Otherwise (string / DOM-copy paths): clone. The iterator is rooted
|
|
20177
|
+
at — and the result serialised from — `body`, so a restrictive
|
|
20178
|
+
ALLOWED_TAGS that removes `body` itself must leave its content in
|
|
20179
|
+
place, which only cloning does; and those paths parse into an
|
|
20180
|
+
inert document, so their discarded originals never had a queued
|
|
20181
|
+
event to neutralise.
|
|
20182
|
+
`childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
|
|
20183
|
+
valid whether we move (drops the trailing entry) or clone (leaves
|
|
20184
|
+
the list intact). */
|
|
20185
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
20186
|
+
const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
|
|
20187
|
+
parentNode.insertBefore(hoisted, getNextSibling(currentNode));
|
|
20188
|
+
}
|
|
20189
|
+
}
|
|
20190
|
+
}
|
|
20191
|
+
_forceRemove(currentNode);
|
|
20192
|
+
return true;
|
|
20193
|
+
};
|
|
19683
20194
|
/**
|
|
19684
20195
|
* _sanitizeElements
|
|
19685
20196
|
*
|
|
@@ -19690,7 +20201,6 @@
|
|
|
19690
20201
|
* @return true if node was killed, false if left alive
|
|
19691
20202
|
*/
|
|
19692
20203
|
const _sanitizeElements = function _sanitizeElements(currentNode) {
|
|
19693
|
-
let content = null;
|
|
19694
20204
|
/* Execute a hook if present */
|
|
19695
20205
|
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
19696
20206
|
/* Check if element is clobbered or can clobber */
|
|
@@ -19699,75 +20209,41 @@
|
|
|
19699
20209
|
return true;
|
|
19700
20210
|
}
|
|
19701
20211
|
/* Now let's check the element's type and name */
|
|
19702
|
-
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
20212
|
+
const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
|
|
19703
20213
|
/* Execute a hook if present */
|
|
19704
20214
|
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
19705
20215
|
tagName,
|
|
19706
20216
|
allowedTags: ALLOWED_TAGS
|
|
19707
20217
|
});
|
|
19708
|
-
/*
|
|
19709
|
-
if (
|
|
19710
|
-
_forceRemove(currentNode);
|
|
19711
|
-
return true;
|
|
19712
|
-
}
|
|
19713
|
-
/* Remove risky CSS construction leading to mXSS */
|
|
19714
|
-
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
|
|
19715
|
-
_forceRemove(currentNode);
|
|
19716
|
-
return true;
|
|
19717
|
-
}
|
|
19718
|
-
/* Remove any occurrence of processing instructions */
|
|
19719
|
-
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
19720
|
-
_forceRemove(currentNode);
|
|
19721
|
-
return true;
|
|
19722
|
-
}
|
|
19723
|
-
/* Remove any kind of possibly harmful comments */
|
|
19724
|
-
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
20218
|
+
/* Remove mXSS vectors, processing instructions and risky comments */
|
|
20219
|
+
if (_isUnsafeNode(currentNode, tagName)) {
|
|
19725
20220
|
_forceRemove(currentNode);
|
|
19726
20221
|
return true;
|
|
19727
20222
|
}
|
|
19728
20223
|
/* Remove element if anything forbids its presence */
|
|
19729
20224
|
if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
|
|
19730
|
-
|
|
19731
|
-
|
|
19732
|
-
|
|
19733
|
-
|
|
19734
|
-
|
|
19735
|
-
|
|
19736
|
-
|
|
19737
|
-
|
|
19738
|
-
|
|
19739
|
-
|
|
19740
|
-
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
19741
|
-
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
19742
|
-
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
19743
|
-
if (childNodes && parentNode) {
|
|
19744
|
-
const childCount = childNodes.length;
|
|
19745
|
-
for (let i = childCount - 1; i >= 0; --i) {
|
|
19746
|
-
const childClone = cloneNode(childNodes[i], true);
|
|
19747
|
-
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
19748
|
-
}
|
|
19749
|
-
}
|
|
19750
|
-
}
|
|
19751
|
-
_forceRemove(currentNode);
|
|
19752
|
-
return true;
|
|
19753
|
-
}
|
|
19754
|
-
/* Check whether element has a valid namespace */
|
|
19755
|
-
if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
|
|
20225
|
+
return _sanitizeDisallowedNode(currentNode, tagName);
|
|
20226
|
+
}
|
|
20227
|
+
/* Check whether element has a valid namespace.
|
|
20228
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
|
|
20229
|
+
nodeType getter rather than `instanceof Element`, which is realm-
|
|
20230
|
+
bound and short-circuits to false for any node minted in a different
|
|
20231
|
+
realm — letting a foreign-realm element with a forbidden namespace
|
|
20232
|
+
slip past the namespace check entirely. */
|
|
20233
|
+
const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
|
|
20234
|
+
if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
|
|
19756
20235
|
_forceRemove(currentNode);
|
|
19757
20236
|
return true;
|
|
19758
20237
|
}
|
|
19759
20238
|
/* Make sure that older browsers don't get fallback-tag mXSS */
|
|
19760
|
-
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(
|
|
20239
|
+
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
|
|
19761
20240
|
_forceRemove(currentNode);
|
|
19762
20241
|
return true;
|
|
19763
20242
|
}
|
|
19764
20243
|
/* Sanitize element content to be template-safe */
|
|
19765
20244
|
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
19766
20245
|
/* Get the element's text content */
|
|
19767
|
-
content = currentNode.textContent;
|
|
19768
|
-
arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
|
|
19769
|
-
content = stringReplace(content, expr, ' ');
|
|
19770
|
-
});
|
|
20246
|
+
const content = _stripTemplateExpressions(currentNode.textContent);
|
|
19771
20247
|
if (currentNode.textContent !== content) {
|
|
19772
20248
|
arrayPush(DOMPurify.removed, {
|
|
19773
20249
|
element: currentNode.cloneNode()
|
|
@@ -19802,7 +20278,7 @@
|
|
|
19802
20278
|
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
|
19803
20279
|
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
|
|
19804
20280
|
We don't need to check the value; it's always URI safe. */
|
|
19805
|
-
if (ALLOW_DATA_ATTR &&
|
|
20281
|
+
if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
|
|
19806
20282
|
if (
|
|
19807
20283
|
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
19808
20284
|
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
@@ -19834,6 +20310,63 @@
|
|
|
19834
20310
|
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
|
|
19835
20311
|
return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
|
|
19836
20312
|
};
|
|
20313
|
+
/**
|
|
20314
|
+
* Wrap an attribute value in the matching Trusted Types object when
|
|
20315
|
+
* the active policy requires it. Namespaced attributes pass through
|
|
20316
|
+
* unchanged (no TT support yet, see
|
|
20317
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
|
|
20318
|
+
*
|
|
20319
|
+
* @param lcTag lowercase tag name of the containing element
|
|
20320
|
+
* @param lcName lowercase attribute name
|
|
20321
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
20322
|
+
* @param value the attribute value to wrap
|
|
20323
|
+
* @return the value, wrapped when Trusted Types demand it
|
|
20324
|
+
*/
|
|
20325
|
+
const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
|
|
20326
|
+
if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
|
|
20327
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
20328
|
+
case 'TrustedHTML':
|
|
20329
|
+
{
|
|
20330
|
+
return _createTrustedHTML(value);
|
|
20331
|
+
}
|
|
20332
|
+
case 'TrustedScriptURL':
|
|
20333
|
+
{
|
|
20334
|
+
return _createTrustedScriptURL(value);
|
|
20335
|
+
}
|
|
20336
|
+
}
|
|
20337
|
+
}
|
|
20338
|
+
return value;
|
|
20339
|
+
};
|
|
20340
|
+
/**
|
|
20341
|
+
* Write a modified attribute value back onto the element. On
|
|
20342
|
+
* success, re-probe for clobbering introduced by the new value and
|
|
20343
|
+
* remove the element when found; otherwise pop the removal entry
|
|
20344
|
+
* recorded by the earlier _removeAttribute (long-standing pairing
|
|
20345
|
+
* with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
|
|
20346
|
+
* failure, remove the attribute instead.
|
|
20347
|
+
*
|
|
20348
|
+
* @param currentNode the element carrying the attribute
|
|
20349
|
+
* @param name the attribute name as present on the element
|
|
20350
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
20351
|
+
* @param value the new attribute value
|
|
20352
|
+
*/
|
|
20353
|
+
const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
|
|
20354
|
+
try {
|
|
20355
|
+
if (namespaceURI) {
|
|
20356
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
20357
|
+
} else {
|
|
20358
|
+
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
20359
|
+
currentNode.setAttribute(name, value);
|
|
20360
|
+
}
|
|
20361
|
+
if (_isClobbered(currentNode)) {
|
|
20362
|
+
_forceRemove(currentNode);
|
|
20363
|
+
} else {
|
|
20364
|
+
arrayPop(DOMPurify.removed);
|
|
20365
|
+
}
|
|
20366
|
+
} catch (_) {
|
|
20367
|
+
_removeAttribute(name, currentNode);
|
|
20368
|
+
}
|
|
20369
|
+
};
|
|
19837
20370
|
/**
|
|
19838
20371
|
* _sanitizeAttributes
|
|
19839
20372
|
*
|
|
@@ -19860,6 +20393,7 @@
|
|
|
19860
20393
|
forceKeepAttr: undefined
|
|
19861
20394
|
};
|
|
19862
20395
|
let l = attributes.length;
|
|
20396
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
19863
20397
|
/* Go backwards over all attributes; safely remove bad ones */
|
|
19864
20398
|
while (l--) {
|
|
19865
20399
|
const attr = attributes[l];
|
|
@@ -19897,7 +20431,7 @@
|
|
|
19897
20431
|
_removeAttribute(name, currentNode);
|
|
19898
20432
|
continue;
|
|
19899
20433
|
}
|
|
19900
|
-
/* Did the hooks
|
|
20434
|
+
/* Did the hooks force-keep the attribute? */
|
|
19901
20435
|
if (hookEvent.forceKeepAttr) {
|
|
19902
20436
|
continue;
|
|
19903
20437
|
}
|
|
@@ -19907,56 +20441,24 @@
|
|
|
19907
20441
|
continue;
|
|
19908
20442
|
}
|
|
19909
20443
|
/* Work around a security issue in jQuery 3.0 */
|
|
19910
|
-
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(
|
|
20444
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
|
|
19911
20445
|
_removeAttribute(name, currentNode);
|
|
19912
20446
|
continue;
|
|
19913
20447
|
}
|
|
19914
20448
|
/* Sanitize attribute content to be template-safe */
|
|
19915
20449
|
if (SAFE_FOR_TEMPLATES) {
|
|
19916
|
-
|
|
19917
|
-
value = stringReplace(value, expr, ' ');
|
|
19918
|
-
});
|
|
20450
|
+
value = _stripTemplateExpressions(value);
|
|
19919
20451
|
}
|
|
19920
20452
|
/* Is `value` valid for this attribute? */
|
|
19921
|
-
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
19922
20453
|
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
19923
20454
|
_removeAttribute(name, currentNode);
|
|
19924
20455
|
continue;
|
|
19925
20456
|
}
|
|
19926
20457
|
/* Handle attributes that require Trusted Types */
|
|
19927
|
-
|
|
19928
|
-
if (namespaceURI) ; else {
|
|
19929
|
-
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
19930
|
-
case 'TrustedHTML':
|
|
19931
|
-
{
|
|
19932
|
-
value = trustedTypesPolicy.createHTML(value);
|
|
19933
|
-
break;
|
|
19934
|
-
}
|
|
19935
|
-
case 'TrustedScriptURL':
|
|
19936
|
-
{
|
|
19937
|
-
value = trustedTypesPolicy.createScriptURL(value);
|
|
19938
|
-
break;
|
|
19939
|
-
}
|
|
19940
|
-
}
|
|
19941
|
-
}
|
|
19942
|
-
}
|
|
20458
|
+
value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
|
|
19943
20459
|
/* Handle invalid data-* attribute set by try-catching it */
|
|
19944
20460
|
if (value !== initValue) {
|
|
19945
|
-
|
|
19946
|
-
if (namespaceURI) {
|
|
19947
|
-
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
19948
|
-
} else {
|
|
19949
|
-
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
19950
|
-
currentNode.setAttribute(name, value);
|
|
19951
|
-
}
|
|
19952
|
-
if (_isClobbered(currentNode)) {
|
|
19953
|
-
_forceRemove(currentNode);
|
|
19954
|
-
} else {
|
|
19955
|
-
arrayPop(DOMPurify.removed);
|
|
19956
|
-
}
|
|
19957
|
-
} catch (_) {
|
|
19958
|
-
_removeAttribute(name, currentNode);
|
|
19959
|
-
}
|
|
20461
|
+
_setAttributeValue(currentNode, name, namespaceURI, value);
|
|
19960
20462
|
}
|
|
19961
20463
|
}
|
|
19962
20464
|
/* Execute a hook if present */
|
|
@@ -19979,10 +20481,31 @@
|
|
|
19979
20481
|
_sanitizeElements(shadowNode);
|
|
19980
20482
|
/* Check attributes next */
|
|
19981
20483
|
_sanitizeAttributes(shadowNode);
|
|
19982
|
-
/* Deep shadow DOM detected
|
|
19983
|
-
|
|
20484
|
+
/* Deep shadow DOM detected.
|
|
20485
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
|
|
20486
|
+
DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
|
|
20487
|
+
recurse into <template>.content from foreign realms too. */
|
|
20488
|
+
if (_isDocumentFragment(shadowNode.content)) {
|
|
19984
20489
|
_sanitizeShadowDOM2(shadowNode.content);
|
|
19985
20490
|
}
|
|
20491
|
+
/* An element iterated here may itself host an attached
|
|
20492
|
+
shadow root. The default NodeIterator does not enter shadow
|
|
20493
|
+
trees, so a shadow root nested inside template.content was
|
|
20494
|
+
previously reached by no walk at all (the pre-pass at
|
|
20495
|
+
_sanitizeAttachedShadowRoots descends via childNodes, which
|
|
20496
|
+
doesn't enter template.content; the template-content recursion
|
|
20497
|
+
above iterates the content but never inspected shadowRoot).
|
|
20498
|
+
Walk it explicitly. The nodeType guard avoids reading
|
|
20499
|
+
shadowRoot off text / comment / CDATA / PI nodes that the
|
|
20500
|
+
iterator also surfaces. */
|
|
20501
|
+
const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
|
|
20502
|
+
if (shadowNodeType === NODE_TYPE.element) {
|
|
20503
|
+
const innerSr = getShadowRoot(shadowNode);
|
|
20504
|
+
if (_isDocumentFragment(innerSr)) {
|
|
20505
|
+
_sanitizeAttachedShadowRoots(innerSr);
|
|
20506
|
+
_sanitizeShadowDOM2(innerSr);
|
|
20507
|
+
}
|
|
20508
|
+
}
|
|
19986
20509
|
}
|
|
19987
20510
|
/* Execute a hook if present */
|
|
19988
20511
|
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
@@ -20006,28 +20529,83 @@
|
|
|
20006
20529
|
*
|
|
20007
20530
|
* @param root the subtree root to walk for attached shadow roots
|
|
20008
20531
|
*/
|
|
20009
|
-
const
|
|
20010
|
-
|
|
20011
|
-
|
|
20012
|
-
|
|
20013
|
-
|
|
20014
|
-
|
|
20015
|
-
|
|
20016
|
-
|
|
20017
|
-
|
|
20018
|
-
|
|
20019
|
-
|
|
20020
|
-
|
|
20021
|
-
|
|
20022
|
-
|
|
20023
|
-
|
|
20024
|
-
|
|
20025
|
-
const
|
|
20026
|
-
|
|
20027
|
-
|
|
20028
|
-
}
|
|
20029
|
-
|
|
20030
|
-
|
|
20532
|
+
const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
|
|
20533
|
+
/* Iterative (explicit stack) rather than per-child recursion. DOM APIs
|
|
20534
|
+
impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
|
|
20535
|
+
built straight into the DOM — the IN_PLACE surface) deeper than the JS
|
|
20536
|
+
call-stack budget would otherwise overflow native recursion here and
|
|
20537
|
+
throw at the IN_PLACE entry pre-pass, before a single node is
|
|
20538
|
+
sanitized, leaving the caller's live tree untouched (fail-open). See
|
|
20539
|
+
campaign-3 F4. A heap stack keeps depth off the call stack.
|
|
20540
|
+
Each work item is either a node to descend into, or a deferred
|
|
20541
|
+
`_sanitizeShadowDOM` for an already-walked shadow root. The deferred
|
|
20542
|
+
form preserves the original post-order discipline: a shadow root's
|
|
20543
|
+
nested shadow roots are discovered before the outer shadow is
|
|
20544
|
+
sanitized (which may remove hosts). Pushes are in reverse of the
|
|
20545
|
+
desired processing order (LIFO): template content, then children, then
|
|
20546
|
+
the shadow-sanitize, then the shadow walk — so the order matches the
|
|
20547
|
+
previous recursion exactly. */
|
|
20548
|
+
const stack = [{
|
|
20549
|
+
node: root,
|
|
20550
|
+
shadow: null
|
|
20551
|
+
}];
|
|
20552
|
+
while (stack.length > 0) {
|
|
20553
|
+
const item = stack.pop();
|
|
20554
|
+
/* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
|
|
20555
|
+
if (item.shadow) {
|
|
20556
|
+
_sanitizeShadowDOM2(item.shadow);
|
|
20557
|
+
continue;
|
|
20558
|
+
}
|
|
20559
|
+
const node = item.node;
|
|
20560
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
20561
|
+
const isElement = nodeType === NODE_TYPE.element;
|
|
20562
|
+
/* (pushed last → processed first) Children, snapshotted in reverse so
|
|
20563
|
+
the first child is processed first. Snapshotting matters because a
|
|
20564
|
+
hook may detach siblings mid-walk. */
|
|
20565
|
+
const childNodes = getChildNodes(node);
|
|
20566
|
+
if (childNodes) {
|
|
20567
|
+
for (let i = childNodes.length - 1; i >= 0; --i) {
|
|
20568
|
+
stack.push({
|
|
20569
|
+
node: childNodes[i],
|
|
20570
|
+
shadow: null
|
|
20571
|
+
});
|
|
20572
|
+
}
|
|
20573
|
+
}
|
|
20574
|
+
/* (pushed before children → processed after them, matching the old
|
|
20575
|
+
"template content last" order) When the node is a <template>,
|
|
20576
|
+
descend into its content. */
|
|
20577
|
+
if (isElement) {
|
|
20578
|
+
const rootName = getNodeName ? getNodeName(node) : null;
|
|
20579
|
+
if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
|
|
20580
|
+
const content = node.content;
|
|
20581
|
+
if (_isDocumentFragment(content)) {
|
|
20582
|
+
stack.push({
|
|
20583
|
+
node: content,
|
|
20584
|
+
shadow: null
|
|
20585
|
+
});
|
|
20586
|
+
}
|
|
20587
|
+
}
|
|
20588
|
+
}
|
|
20589
|
+
/* Shadow root (processed first): walk its subtree, then sanitise it.
|
|
20590
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
|
|
20591
|
+
rather than `instanceof DocumentFragment`, which is realm-bound and
|
|
20592
|
+
silently skipped foreign-realm shadow roots (e.g.
|
|
20593
|
+
iframe.contentDocument attachShadow). */
|
|
20594
|
+
if (isElement) {
|
|
20595
|
+
const sr = getShadowRoot(node);
|
|
20596
|
+
if (_isDocumentFragment(sr)) {
|
|
20597
|
+
/* Push the deferred sanitise first so it pops after the shadow
|
|
20598
|
+
walk we push next, i.e. nested shadow roots are discovered
|
|
20599
|
+
before this one is sanitised. */
|
|
20600
|
+
stack.push({
|
|
20601
|
+
node: null,
|
|
20602
|
+
shadow: sr
|
|
20603
|
+
}, {
|
|
20604
|
+
node: sr,
|
|
20605
|
+
shadow: null
|
|
20606
|
+
});
|
|
20607
|
+
}
|
|
20608
|
+
}
|
|
20031
20609
|
}
|
|
20032
20610
|
};
|
|
20033
20611
|
// eslint-disable-next-line complexity
|
|
@@ -20056,27 +20634,77 @@
|
|
|
20056
20634
|
return dirty;
|
|
20057
20635
|
}
|
|
20058
20636
|
/* Assign config vars */
|
|
20059
|
-
if (
|
|
20637
|
+
if (SET_CONFIG) {
|
|
20638
|
+
/* Persistent setConfig() path: _parseConfig is skipped, so the sets are
|
|
20639
|
+
* not re-derived per call. Restore them from the pristine bindings
|
|
20640
|
+
* captured at setConfig() time so a previous call's hook clone (mutated
|
|
20641
|
+
* below) does not carry over. */
|
|
20642
|
+
ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
|
|
20643
|
+
ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
|
|
20644
|
+
} else {
|
|
20060
20645
|
_parseConfig(cfg);
|
|
20061
20646
|
}
|
|
20647
|
+
/* Clone the hook-mutable allowlists before the walk whenever an
|
|
20648
|
+
* uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
|
|
20649
|
+
* and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
|
|
20650
|
+
* a hook that widens them would otherwise mutate the shared set
|
|
20651
|
+
* permanently: across later calls and across every element. Cloning per
|
|
20652
|
+
* walk keeps documented in-call widening working while scoping it to the
|
|
20653
|
+
* call. A single guard for both config paths - the per-call path rebinds
|
|
20654
|
+
* the sets in _parseConfig each call, the persistent path restores them
|
|
20655
|
+
* from the captured bindings just above - so the two cannot diverge. */
|
|
20656
|
+
if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
|
|
20657
|
+
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
20658
|
+
}
|
|
20659
|
+
if (hooks.uponSanitizeAttribute.length > 0) {
|
|
20660
|
+
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
20661
|
+
}
|
|
20062
20662
|
/* Clean up removed elements */
|
|
20063
20663
|
DOMPurify.removed = [];
|
|
20064
|
-
/*
|
|
20065
|
-
|
|
20066
|
-
|
|
20067
|
-
|
|
20068
|
-
|
|
20069
|
-
|
|
20070
|
-
|
|
20664
|
+
/* Resolve IN_PLACE for this call without mutating persistent config.
|
|
20665
|
+
Writing the IN_PLACE closure variable here leaks under setConfig(),
|
|
20666
|
+
where _parseConfig is skipped on later calls: a single string call would
|
|
20667
|
+
disable in-place mode for every subsequent node call, returning a
|
|
20668
|
+
sanitized copy while leaving the caller's node — which in-place callers
|
|
20669
|
+
keep using and whose return value they ignore — unsanitized. REPORT-2. */
|
|
20670
|
+
const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
|
|
20671
|
+
if (inPlace) {
|
|
20672
|
+
/* Do some early pre-sanitization to avoid unsafe root nodes.
|
|
20673
|
+
Read nodeName through the cached prototype getter — a clobbering
|
|
20674
|
+
child named "nodeName" on the form root would otherwise shadow
|
|
20675
|
+
the property and let this check skip the root-allowlist
|
|
20676
|
+
validation entirely. */
|
|
20677
|
+
const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
|
|
20071
20678
|
if (typeof nn === 'string') {
|
|
20072
20679
|
const tagName = transformCaseFunc(nn);
|
|
20073
20680
|
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
20074
20681
|
throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
|
|
20075
20682
|
}
|
|
20076
20683
|
}
|
|
20684
|
+
/* Pre-flight the root through _isClobbered. The iterator-driven
|
|
20685
|
+
removal path can not detach a parent-less root: _forceRemove
|
|
20686
|
+
falls through to Element.prototype.remove(), which per spec
|
|
20687
|
+
is a no-op on a node with no parent. A clobbered root would
|
|
20688
|
+
then survive the main loop with its attributes uninspected,
|
|
20689
|
+
because _sanitizeAttributes early-returns on _isClobbered. The
|
|
20690
|
+
result would be an attacker-controlled form, complete with any
|
|
20691
|
+
event-handler attributes the caller passed in, handed back to
|
|
20692
|
+
the application unsanitized. Refuse to sanitize such a root
|
|
20693
|
+
the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
|
|
20694
|
+
if (_isClobbered(dirty)) {
|
|
20695
|
+
throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
|
|
20696
|
+
}
|
|
20077
20697
|
/* Sanitize attached shadow roots before the main iterator runs.
|
|
20078
|
-
The iterator does not descend into shadow trees.
|
|
20079
|
-
|
|
20698
|
+
The iterator does not descend into shadow trees. Same fail-closed
|
|
20699
|
+
barrier as the main walk (campaign-3 F2): a custom-element reaction
|
|
20700
|
+
inside a shadow root could abort this pre-pass before the walk runs,
|
|
20701
|
+
which would otherwise leave the entire live tree unsanitized. */
|
|
20702
|
+
try {
|
|
20703
|
+
_sanitizeAttachedShadowRoots(dirty);
|
|
20704
|
+
} catch (error) {
|
|
20705
|
+
_neutralizeRoot(dirty);
|
|
20706
|
+
throw error;
|
|
20707
|
+
}
|
|
20080
20708
|
} else if (_isNode(dirty)) {
|
|
20081
20709
|
/* If dirty is a DOM element, append to an empty document to avoid
|
|
20082
20710
|
elements being stripped by the parser */
|
|
@@ -20093,14 +20721,16 @@
|
|
|
20093
20721
|
}
|
|
20094
20722
|
/* Clonable shadow roots are deep-cloned by importNode(); sanitize
|
|
20095
20723
|
them before the main iterator runs, since the iterator does not
|
|
20096
|
-
descend into shadow trees.
|
|
20097
|
-
|
|
20724
|
+
descend into shadow trees. The walk routes every read through a
|
|
20725
|
+
cached prototype getter so clobbering descendants on a form root
|
|
20726
|
+
cannot hide a shadow host from this pass. */
|
|
20727
|
+
_sanitizeAttachedShadowRoots(importedNode);
|
|
20098
20728
|
} else {
|
|
20099
20729
|
/* Exit directly if we have nothing to do */
|
|
20100
20730
|
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
|
|
20101
20731
|
// eslint-disable-next-line unicorn/prefer-includes
|
|
20102
20732
|
dirty.indexOf('<') === -1) {
|
|
20103
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ?
|
|
20733
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
|
|
20104
20734
|
}
|
|
20105
20735
|
/* Initialize the document to work on */
|
|
20106
20736
|
body = _initDocument(dirty);
|
|
@@ -20114,29 +20744,59 @@
|
|
|
20114
20744
|
_forceRemove(body.firstChild);
|
|
20115
20745
|
}
|
|
20116
20746
|
/* Get node iterator */
|
|
20117
|
-
const nodeIterator = _createNodeIterator(
|
|
20118
|
-
/* Now start iterating over the created document
|
|
20119
|
-
|
|
20120
|
-
|
|
20121
|
-
|
|
20122
|
-
|
|
20123
|
-
|
|
20124
|
-
|
|
20125
|
-
|
|
20126
|
-
|
|
20747
|
+
const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
|
|
20748
|
+
/* Now start iterating over the created document.
|
|
20749
|
+
The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
|
|
20750
|
+
engine/custom-element mutation can detach a node mid-walk so
|
|
20751
|
+
`_forceRemove`'s parentless guard throws, aborting the loop. Without the
|
|
20752
|
+
barrier the caller's in-place tree would be left half-sanitized with the
|
|
20753
|
+
unvisited tail still armed. On any throw we fail closed — strip the
|
|
20754
|
+
in-place root bare — then rethrow so the existing throw contract is
|
|
20755
|
+
preserved. (String/DOM-copy paths never return the partial body, so the
|
|
20756
|
+
propagating throw is already fail-closed there.) */
|
|
20757
|
+
try {
|
|
20758
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
20759
|
+
/* Sanitize tags and elements */
|
|
20760
|
+
_sanitizeElements(currentNode);
|
|
20761
|
+
/* Check attributes next */
|
|
20762
|
+
_sanitizeAttributes(currentNode);
|
|
20763
|
+
/* Shadow DOM detected, sanitize it.
|
|
20764
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
|
|
20765
|
+
instead of instanceof, so foreign-realm <template>.content is
|
|
20766
|
+
walked correctly. */
|
|
20767
|
+
if (_isDocumentFragment(currentNode.content)) {
|
|
20768
|
+
_sanitizeShadowDOM2(currentNode.content);
|
|
20769
|
+
}
|
|
20770
|
+
}
|
|
20771
|
+
} catch (error) {
|
|
20772
|
+
if (inPlace) {
|
|
20773
|
+
_neutralizeRoot(dirty);
|
|
20127
20774
|
}
|
|
20775
|
+
throw error;
|
|
20128
20776
|
}
|
|
20129
20777
|
/* If we sanitized `dirty` in-place, return it. */
|
|
20130
|
-
if (
|
|
20778
|
+
if (inPlace) {
|
|
20779
|
+
/* Fail-closed completion of the audit-5 F1 fix: every node removed from
|
|
20780
|
+
the caller's live tree is detached but may still hold a queued
|
|
20781
|
+
resource-event handler that fires in page scope after we return. The
|
|
20782
|
+
move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
|
|
20783
|
+
non-allow-listed attributes off every other removed subtree (clobber,
|
|
20784
|
+
mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
|
|
20785
|
+
cancelled before any event can fire. Runs synchronously, pre-return. */
|
|
20786
|
+
arrayForEach(DOMPurify.removed, entry => {
|
|
20787
|
+
if (entry.element) {
|
|
20788
|
+
_neutralizeSubtree(entry.element);
|
|
20789
|
+
}
|
|
20790
|
+
});
|
|
20131
20791
|
if (SAFE_FOR_TEMPLATES) {
|
|
20132
|
-
|
|
20792
|
+
_scrubTemplateExpressions2(dirty);
|
|
20133
20793
|
}
|
|
20134
20794
|
return dirty;
|
|
20135
20795
|
}
|
|
20136
20796
|
/* Return sanitized string or DOM */
|
|
20137
20797
|
if (RETURN_DOM) {
|
|
20138
20798
|
if (SAFE_FOR_TEMPLATES) {
|
|
20139
|
-
|
|
20799
|
+
_scrubTemplateExpressions2(body);
|
|
20140
20800
|
}
|
|
20141
20801
|
if (RETURN_DOM_FRAGMENT) {
|
|
20142
20802
|
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
@@ -20166,20 +20826,28 @@
|
|
|
20166
20826
|
}
|
|
20167
20827
|
/* Sanitize final string template-safe */
|
|
20168
20828
|
if (SAFE_FOR_TEMPLATES) {
|
|
20169
|
-
|
|
20170
|
-
serializedHTML = stringReplace(serializedHTML, expr, ' ');
|
|
20171
|
-
});
|
|
20829
|
+
serializedHTML = _stripTemplateExpressions(serializedHTML);
|
|
20172
20830
|
}
|
|
20173
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ?
|
|
20831
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
|
|
20174
20832
|
};
|
|
20175
20833
|
DOMPurify.setConfig = function () {
|
|
20176
20834
|
let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
20177
20835
|
_parseConfig(cfg);
|
|
20178
20836
|
SET_CONFIG = true;
|
|
20837
|
+
SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
|
|
20838
|
+
SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
|
|
20179
20839
|
};
|
|
20180
20840
|
DOMPurify.clearConfig = function () {
|
|
20181
20841
|
CONFIG = null;
|
|
20182
20842
|
SET_CONFIG = false;
|
|
20843
|
+
SET_CONFIG_ALLOWED_TAGS = null;
|
|
20844
|
+
SET_CONFIG_ALLOWED_ATTR = null;
|
|
20845
|
+
// Drop any caller-supplied Trusted Types policy so it cannot poison later
|
|
20846
|
+
// `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
|
|
20847
|
+
// never recreated — Trusted Types throws on duplicate names) is restored by
|
|
20848
|
+
// the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
|
|
20849
|
+
trustedTypesPolicy = defaultTrustedTypesPolicy;
|
|
20850
|
+
emptyHTML = '';
|
|
20183
20851
|
};
|
|
20184
20852
|
DOMPurify.isValidAttribute = function (tag, attr, value) {
|
|
20185
20853
|
/* Initialize shared config vars if necessary. */
|
|
@@ -20194,9 +20862,19 @@
|
|
|
20194
20862
|
if (typeof hookFunction !== 'function') {
|
|
20195
20863
|
return;
|
|
20196
20864
|
}
|
|
20865
|
+
/* Reject unknown entry points. Without this, a non-hook key (e.g.
|
|
20866
|
+
* '__proto__') indexes off the prototype chain rather than a real
|
|
20867
|
+
* hook array, and arrayPush then writes to Object.prototype. Guard
|
|
20868
|
+
* with an own-property check against the known hook names. */
|
|
20869
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
20870
|
+
return;
|
|
20871
|
+
}
|
|
20197
20872
|
arrayPush(hooks[entryPoint], hookFunction);
|
|
20198
20873
|
};
|
|
20199
20874
|
DOMPurify.removeHook = function (entryPoint, hookFunction) {
|
|
20875
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
20876
|
+
return undefined;
|
|
20877
|
+
}
|
|
20200
20878
|
if (hookFunction !== undefined) {
|
|
20201
20879
|
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
20202
20880
|
return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
@@ -20204,6 +20882,9 @@
|
|
|
20204
20882
|
return arrayPop(hooks[entryPoint]);
|
|
20205
20883
|
};
|
|
20206
20884
|
DOMPurify.removeHooks = function (entryPoint) {
|
|
20885
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
20886
|
+
return;
|
|
20887
|
+
}
|
|
20207
20888
|
hooks[entryPoint] = [];
|
|
20208
20889
|
};
|
|
20209
20890
|
DOMPurify.removeAllHooks = function () {
|
|
@@ -20687,22 +21368,44 @@
|
|
|
20687
21368
|
const bogus = get$a(element, 'data-mce-bogus');
|
|
20688
21369
|
if (!isInternalElement && isString(bogus)) {
|
|
20689
21370
|
if (bogus === 'all') {
|
|
21371
|
+
// Empty before removing so a detached raw-text element (e.g. script/style) can't carry
|
|
21372
|
+
// markup-like content into DOMPurify's unsafe-node check, which would then throw trying
|
|
21373
|
+
// to _forceRemove the now-parentless node.
|
|
21374
|
+
empty(element);
|
|
20690
21375
|
remove$8(element);
|
|
20691
21376
|
}
|
|
20692
21377
|
else {
|
|
20693
21378
|
unwrap(element);
|
|
20694
21379
|
}
|
|
21380
|
+
// We detach the element above; DOMPurify throws if it then tries to _forceRemove the
|
|
21381
|
+
// now-parentless node, so mark the tag allowed to stop that second removal.
|
|
21382
|
+
if (isNonNullable(evt)) {
|
|
21383
|
+
evt.allowedTags[lcTagName] = true;
|
|
21384
|
+
}
|
|
20695
21385
|
return;
|
|
20696
21386
|
}
|
|
20697
21387
|
// Determine if the schema allows the element and either add it or remove it
|
|
20698
21388
|
const rule = schema.getElementRule(lcTagName);
|
|
20699
21389
|
if (validate && !rule) {
|
|
20700
|
-
//
|
|
20701
|
-
|
|
20702
|
-
|
|
21390
|
+
// Don't detach invalid special / non-HTML-namespace elements: DOMPurify throws if it later
|
|
21391
|
+
// _forceRemoves a parentless node (its unsafe-content and namespace checks do this regardless
|
|
21392
|
+
// of allowedTags). Empty and leave attached instead, so DOMPurify removes it without hoisting content.
|
|
21393
|
+
if (settings.sanitize && (has$2(specialElements, lcTagName) || scope !== 'html')) {
|
|
21394
|
+
empty(element);
|
|
20703
21395
|
}
|
|
20704
21396
|
else {
|
|
20705
|
-
|
|
21397
|
+
// No DOMPurify to remove it (sanitize disabled), or a plain invalid HTML element: detach it ourselves.
|
|
21398
|
+
if (has$2(specialElements, lcTagName)) {
|
|
21399
|
+
remove$8(element);
|
|
21400
|
+
}
|
|
21401
|
+
else {
|
|
21402
|
+
unwrap(element);
|
|
21403
|
+
}
|
|
21404
|
+
// The element is now detached; mark the tag allowed so DOMPurify won't _forceRemove the
|
|
21405
|
+
// parentless node and throw. Safe here: it's empty and HTML-namespaced, so no earlier check fires.
|
|
21406
|
+
if (isNonNullable(evt)) {
|
|
21407
|
+
evt.allowedTags[lcTagName] = true;
|
|
21408
|
+
}
|
|
20706
21409
|
}
|
|
20707
21410
|
return;
|
|
20708
21411
|
}
|
|
@@ -20885,7 +21588,9 @@
|
|
|
20885
21588
|
evt.allowedTags[lcTagName] = keepElement;
|
|
20886
21589
|
if (!keepElement && settings.sanitize) {
|
|
20887
21590
|
if (isElement$7(node)) {
|
|
20888
|
-
node
|
|
21591
|
+
// Empty the node and leave it attached so DOMPurify removes it (allowedTags is false).
|
|
21592
|
+
// Detaching it would make DOMPurify throw when it _forceRemoves the parentless node.
|
|
21593
|
+
empty(SugarElement.fromDom(node));
|
|
20889
21594
|
}
|
|
20890
21595
|
}
|
|
20891
21596
|
});
|
|
@@ -22559,7 +23264,7 @@
|
|
|
22559
23264
|
applyCaretFormat(ed, name, vars);
|
|
22560
23265
|
}
|
|
22561
23266
|
getExpandedListItemFormat(ed.formatter, name).each((liFmt) => {
|
|
22562
|
-
const list = getFullySelectedListItems(ed
|
|
23267
|
+
const list = getFullySelectedListItems(ed);
|
|
22563
23268
|
each$e(list, (li) => applyStyles(dom, li, liFmt, vars));
|
|
22564
23269
|
});
|
|
22565
23270
|
}
|
|
@@ -25605,7 +26310,8 @@
|
|
|
25605
26310
|
}, (href) => {
|
|
25606
26311
|
e.preventDefault();
|
|
25607
26312
|
if (/^#/.test(href)) {
|
|
25608
|
-
const
|
|
26313
|
+
const id = removeLeading(href, '#');
|
|
26314
|
+
const targetEl = editor.dom.select(`[id="${id}"],[name="${id}"]`);
|
|
25609
26315
|
if (targetEl.length) {
|
|
25610
26316
|
editor.selection.scrollIntoView(targetEl[0], true);
|
|
25611
26317
|
}
|
|
@@ -31040,10 +31746,14 @@
|
|
|
31040
31746
|
};
|
|
31041
31747
|
const isInDragStartEvent = checkEvent(0 /* Event.Dragstart */);
|
|
31042
31748
|
|
|
31043
|
-
const createEmptyFileList = () =>
|
|
31044
|
-
|
|
31045
|
-
|
|
31046
|
-
|
|
31749
|
+
const createEmptyFileList = () => {
|
|
31750
|
+
const empty = [];
|
|
31751
|
+
return Object.freeze({
|
|
31752
|
+
length: 0,
|
|
31753
|
+
item: (_) => null,
|
|
31754
|
+
[Symbol.iterator]: () => empty[Symbol.iterator]()
|
|
31755
|
+
});
|
|
31756
|
+
};
|
|
31047
31757
|
|
|
31048
31758
|
const modeId = generate('mode');
|
|
31049
31759
|
const getMode = (transfer) => {
|
|
@@ -36876,7 +37586,12 @@
|
|
|
36876
37586
|
**/
|
|
36877
37587
|
const isValidSibling = (el) => getClientRects([el.dom]).length > 0;
|
|
36878
37588
|
const firstBlockChildOrNewLine = (target) => child(target, (child) => isBr$6(child) || isElement$8(child) && get$8(child, 'display') === 'block');
|
|
36879
|
-
const clickAfterEl = (clientX, clientY, rect) => clientX >= rect.right && clientY >= rect.top && clientY <= rect.bottom;
|
|
37589
|
+
const clickAfterEl = (clientX, clientY, el) => get$c(getClientRects([el.dom]), 0).exists((rect) => clientX >= rect.right && clientY >= rect.top && clientY <= rect.bottom);
|
|
37590
|
+
const selectPos = (editor, e, pos) => {
|
|
37591
|
+
e.preventDefault();
|
|
37592
|
+
editor.focus();
|
|
37593
|
+
editor.selection.setRng(pos.toRange());
|
|
37594
|
+
};
|
|
36880
37595
|
/**
|
|
36881
37596
|
* In Chrome in a `LI` that contains a block element and where the first child is an inline element
|
|
36882
37597
|
* clicking on the right side of the first child the carret goes at the start of the element instead that in the end of it
|
|
@@ -36886,15 +37601,16 @@
|
|
|
36886
37601
|
editor.on('mousedown', (e) => {
|
|
36887
37602
|
const target = SugarElement.fromDom(e.target);
|
|
36888
37603
|
if (isListItem$2(target)) {
|
|
36889
|
-
firstBlockChildOrNewLine(target).
|
|
36890
|
-
|
|
36891
|
-
|
|
36892
|
-
|
|
36893
|
-
|
|
36894
|
-
|
|
36895
|
-
|
|
36896
|
-
|
|
36897
|
-
|
|
37604
|
+
firstBlockChildOrNewLine(target).fold(() => {
|
|
37605
|
+
lastChild(target).each((lastChild) => {
|
|
37606
|
+
if (clickAfterEl(e.clientX, e.clientY, lastChild)) {
|
|
37607
|
+
lastPositionIn(target.dom).each((pos) => selectPos(editor, e, pos));
|
|
37608
|
+
}
|
|
37609
|
+
});
|
|
37610
|
+
}, (firstBlock) => {
|
|
37611
|
+
findLast(prevSiblings(firstBlock), isValidSibling).each((lastInlineBeforeBlock) => {
|
|
37612
|
+
if (clickAfterEl(e.clientX, e.clientY, lastInlineBeforeBlock)) {
|
|
37613
|
+
prevPosition(target.dom, CaretPosition(firstBlock.dom, 0)).each((pos) => selectPos(editor, e, pos));
|
|
36898
37614
|
}
|
|
36899
37615
|
});
|
|
36900
37616
|
});
|
|
@@ -41185,14 +41901,14 @@
|
|
|
41185
41901
|
* @property minorVersion
|
|
41186
41902
|
* @type String
|
|
41187
41903
|
*/
|
|
41188
|
-
minorVersion: '
|
|
41904
|
+
minorVersion: '8.1',
|
|
41189
41905
|
/**
|
|
41190
41906
|
* Release date of TinyMCE build.
|
|
41191
41907
|
*
|
|
41192
41908
|
* @property releaseDate
|
|
41193
41909
|
* @type String
|
|
41194
41910
|
*/
|
|
41195
|
-
releaseDate: '2026-07-
|
|
41911
|
+
releaseDate: '2026-07-22',
|
|
41196
41912
|
/**
|
|
41197
41913
|
* Collection of language pack data.
|
|
41198
41914
|
*
|
|
@@ -42109,7 +42825,7 @@
|
|
|
42109
42825
|
}
|
|
42110
42826
|
catch {
|
|
42111
42827
|
// It will thrown an error when running this module
|
|
42112
|
-
// within
|
|
42828
|
+
// within rspack where the module.exports object is sealed
|
|
42113
42829
|
}
|
|
42114
42830
|
}
|
|
42115
42831
|
};
|