igv 3.8.1 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/igv.esm.js CHANGED
@@ -10606,7 +10606,7 @@ function didSelectSingleTrackType(types) {
10606
10606
  return 1 === unique.length
10607
10607
  }
10608
10608
 
10609
- /*! @license DOMPurify 3.4.7 | (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.7/LICENSE */
10609
+ /*! @license DOMPurify 3.4.10 | (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.10/LICENSE */
10610
10610
 
10611
10611
  function _arrayLikeToArray(r, a) {
10612
10612
  (null == a || a > r.length) && (a = r.length);
@@ -10935,6 +10935,13 @@ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205
10935
10935
  );
10936
10936
  const DOCTYPE_NAME = seal(/^html$/i);
10937
10937
  const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
10938
+ // Markup-significant character probes used by _sanitizeElements.
10939
+ // Shared module-level instances are safe despite the sticky /g flags:
10940
+ // unapply() resets lastIndex for RegExp receivers before every call.
10941
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
10942
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
10943
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
10944
+ const SELF_CLOSING_TAG = seal(/\/>/i);
10938
10945
 
10939
10946
  /* eslint-disable @typescript-eslint/indent */
10940
10947
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
@@ -10947,7 +10954,7 @@ const NODE_TYPE = {
10947
10954
  // Deprecated
10948
10955
  entityNode: 6,
10949
10956
  // Deprecated
10950
- progressingInstruction: 7,
10957
+ processingInstruction: 7,
10951
10958
  comment: 8,
10952
10959
  document: 9,
10953
10960
  documentType: 10,
@@ -11008,10 +11015,25 @@ const _createHooksMap = function _createHooksMap() {
11008
11015
  uponSanitizeShadowNode: []
11009
11016
  };
11010
11017
  };
11018
+ /**
11019
+ * Resolve a set-valued configuration option: a fresh set built from
11020
+ * cfg[key] when it is an own array property (seeded with a clone of
11021
+ * options.base when given, case-normalized via options.transform),
11022
+ * the fallback set otherwise.
11023
+ *
11024
+ * @param cfg the cloned, prototype-free configuration object
11025
+ * @param key the configuration property to read
11026
+ * @param fallback the set to use when the option is absent or not an array
11027
+ * @param options transform and optional base set to merge into
11028
+ * @returns the resolved set
11029
+ */
11030
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
11031
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
11032
+ };
11011
11033
  function createDOMPurify() {
11012
11034
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
11013
11035
  const DOMPurify = root => createDOMPurify(root);
11014
- DOMPurify.version = '3.4.7';
11036
+ DOMPurify.version = '3.4.10';
11015
11037
  DOMPurify.removed = [];
11016
11038
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
11017
11039
  // Not running in a browser, provide a factory function
@@ -11056,6 +11078,54 @@ function createDOMPurify() {
11056
11078
  }
11057
11079
  let trustedTypesPolicy;
11058
11080
  let emptyHTML = '';
11081
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
11082
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
11083
+ // on duplicate policy names — and is the only policy allowed to persist
11084
+ // across configurations and survive `clearConfig()`.
11085
+ let defaultTrustedTypesPolicy;
11086
+ let defaultTrustedTypesPolicyResolved = false;
11087
+ // Tracks whether we are already inside a call to the configured Trusted Types
11088
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
11089
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
11090
+ // re-enter the policy and recurse until the stack overflows. We detect that
11091
+ // re-entry and throw a clear, actionable error instead. The guard is shared
11092
+ // across both callbacks, because either one re-entering `sanitize` triggers
11093
+ // the same unbounded recursion.
11094
+ let IN_TRUSTED_TYPES_POLICY = 0;
11095
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
11096
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
11097
+ 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.');
11098
+ }
11099
+ };
11100
+ const _createTrustedHTML = function _createTrustedHTML(html) {
11101
+ _assertNotInTrustedTypesPolicy();
11102
+ IN_TRUSTED_TYPES_POLICY++;
11103
+ try {
11104
+ return trustedTypesPolicy.createHTML(html);
11105
+ } finally {
11106
+ IN_TRUSTED_TYPES_POLICY--;
11107
+ }
11108
+ };
11109
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
11110
+ _assertNotInTrustedTypesPolicy();
11111
+ IN_TRUSTED_TYPES_POLICY++;
11112
+ try {
11113
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
11114
+ } finally {
11115
+ IN_TRUSTED_TYPES_POLICY--;
11116
+ }
11117
+ };
11118
+ // Lazily resolve (and cache) the instance's internal default policy.
11119
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
11120
+ // repeated (Trusted Types throws on duplicate names), and a failed or
11121
+ // unsupported attempt must not be retried on every parse.
11122
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
11123
+ if (!defaultTrustedTypesPolicyResolved) {
11124
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
11125
+ defaultTrustedTypesPolicyResolved = true;
11126
+ }
11127
+ return defaultTrustedTypesPolicy;
11128
+ };
11059
11129
  const _document = document,
11060
11130
  implementation = _document.implementation,
11061
11131
  createNodeIterator = _document.createNodeIterator,
@@ -11194,7 +11264,17 @@ function createDOMPurify() {
11194
11264
  let USE_PROFILES = {};
11195
11265
  /* Tags to ignore content of when KEEP_CONTENT is true */
11196
11266
  let FORBID_CONTENTS = null;
11197
- const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
11267
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
11268
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
11269
+ // the UA (customizable <select>) — including any on* handlers — and the
11270
+ // engine re-mirrors synchronously whenever a removal changes which
11271
+ // option/selectedcontent is current, even inside DOMPurify's inert
11272
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
11273
+ // mirror target ahead of the walk, which the engine refills, looping
11274
+ // forever (DoS) and amplifying output. Dropping its content on removal
11275
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
11276
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
11277
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
11198
11278
  /* Tags that are safe for data: URIs */
11199
11279
  let DATA_URI_TAGS = null;
11200
11280
  const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
@@ -11210,8 +11290,10 @@ function createDOMPurify() {
11210
11290
  /* Allowed XHTML+XML namespaces */
11211
11291
  let ALLOWED_NAMESPACES = null;
11212
11292
  const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
11213
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
11214
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
11293
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
11294
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
11295
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
11296
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
11215
11297
  // Certain elements are allowed in both SVG and HTML
11216
11298
  // namespace. We need to specify them explicitly
11217
11299
  // so that they don't get erroneously deleted from
@@ -11253,14 +11335,32 @@ function createDOMPurify() {
11253
11335
  // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
11254
11336
  transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
11255
11337
  /* Set configuration parameters */
11256
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') && arrayIsArray(cfg.ALLOWED_TAGS) ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
11257
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') && arrayIsArray(cfg.ALLOWED_ATTR) ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
11258
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') && arrayIsArray(cfg.ALLOWED_NAMESPACES) ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
11259
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR) ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
11260
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') && arrayIsArray(cfg.ADD_DATA_URI_TAGS) ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
11261
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS) ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
11262
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') && arrayIsArray(cfg.FORBID_TAGS) ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
11263
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') && arrayIsArray(cfg.FORBID_ATTR) ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
11338
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
11339
+ transform: transformCaseFunc
11340
+ });
11341
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
11342
+ transform: transformCaseFunc
11343
+ });
11344
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
11345
+ transform: stringToString
11346
+ });
11347
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
11348
+ transform: transformCaseFunc,
11349
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
11350
+ });
11351
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
11352
+ transform: transformCaseFunc,
11353
+ base: DEFAULT_DATA_URI_TAGS
11354
+ });
11355
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
11356
+ transform: transformCaseFunc
11357
+ });
11358
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
11359
+ transform: transformCaseFunc
11360
+ });
11361
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
11362
+ transform: transformCaseFunc
11363
+ });
11264
11364
  USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
11265
11365
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
11266
11366
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
@@ -11279,8 +11379,8 @@ function createDOMPurify() {
11279
11379
  IN_PLACE = cfg.IN_PLACE || false; // Default false
11280
11380
  IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
11281
11381
  NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
11282
- 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({}, ['mi', 'mo', 'mn', 'ms', 'mtext']); // Default built-in map
11283
- HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, ['annotation-xml']); // Default built-in map
11382
+ 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
11383
+ 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
11284
11384
  const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
11285
11385
  CUSTOM_ELEMENT_HANDLING = create(null);
11286
11386
  if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
@@ -11292,6 +11392,7 @@ function createDOMPurify() {
11292
11392
  if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
11293
11393
  CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
11294
11394
  }
11395
+ seal(CUSTOM_ELEMENT_HANDLING);
11295
11396
  if (SAFE_FOR_TEMPLATES) {
11296
11397
  ALLOW_DATA_ATTR = false;
11297
11398
  }
@@ -11375,6 +11476,13 @@ function createDOMPurify() {
11375
11476
  addToSet(ALLOWED_TAGS, ['tbody']);
11376
11477
  delete FORBID_TAGS.tbody;
11377
11478
  }
11479
+ // Re-derive the active Trusted Types policy from this configuration on
11480
+ // every parse. The active policy must never be sticky closure state that
11481
+ // outlives the config that set it: a caller-supplied policy left in place
11482
+ // after `clearConfig()` — or after a later call that supplied none, or
11483
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
11484
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
11485
+ // See GHSA-vxr8-fq34-vvx9.
11378
11486
  if (cfg.TRUSTED_TYPES_POLICY) {
11379
11487
  if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
11380
11488
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
@@ -11382,18 +11490,45 @@ function createDOMPurify() {
11382
11490
  if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
11383
11491
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
11384
11492
  }
11385
- // Overwrite existing TrustedTypes policy.
11493
+ // A caller-supplied policy applies to this configuration only.
11494
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
11386
11495
  trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
11387
- // Sign local variables required by `sanitize`.
11388
- emptyHTML = trustedTypesPolicy.createHTML('');
11496
+ // Sign local variables required by `sanitize`. If the supplied policy's
11497
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
11498
+ // throws via the re-entrancy guard. Restore the previous policy first so
11499
+ // the instance is not left in a poisoned state. See #1422.
11500
+ try {
11501
+ emptyHTML = _createTrustedHTML('');
11502
+ } catch (error) {
11503
+ trustedTypesPolicy = previousTrustedTypesPolicy;
11504
+ throw error;
11505
+ }
11506
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
11507
+ // Explicit opt-out for this call: perform no Trusted Types signing and
11508
+ // create nothing (so a strict `trusted-types` CSP that disallows a
11509
+ // `dompurify` policy can still call `sanitize` from inside its own
11510
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
11511
+ // `null` also drops any previously retained caller policy, so it cannot
11512
+ // resurface on a later call, while still allowing the next config-less
11513
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
11514
+ trustedTypesPolicy = undefined;
11515
+ emptyHTML = '';
11389
11516
  } else {
11390
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
11517
+ // No policy supplied: keep the currently active policy if one is set — a
11518
+ // previously supplied policy is intentionally sticky across config-less
11519
+ // calls — otherwise fall back to the instance's own internal policy,
11520
+ // created at most once. (A policy supplied for a *single* call still
11521
+ // lingers by design; what must not linger is a policy whose configuration
11522
+ // has been torn down via `clearConfig()`, which restores the default.)
11391
11523
  if (trustedTypesPolicy === undefined) {
11392
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
11524
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
11393
11525
  }
11394
- // If creating the internal policy succeeded sign internal variables.
11395
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
11396
- emptyHTML = trustedTypesPolicy.createHTML('');
11526
+ // Sign internal variables only when a policy is active. A falsy policy
11527
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
11528
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
11529
+ // a non-policy and throw. See #1422.
11530
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
11531
+ emptyHTML = _createTrustedHTML('');
11397
11532
  }
11398
11533
  }
11399
11534
  /*
@@ -11423,6 +11558,77 @@ function createDOMPurify() {
11423
11558
  * correctly. */
11424
11559
  const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
11425
11560
  const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
11561
+ /**
11562
+ * Namespace rules for an element in the SVG namespace.
11563
+ *
11564
+ * @param tagName the element's lowercase tag name
11565
+ * @param parent the (possibly simulated) parent node
11566
+ * @param parentTagName the parent's lowercase tag name
11567
+ * @returns true if a spec-compliant parser could produce this element
11568
+ */
11569
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
11570
+ // The only way to switch from HTML namespace to SVG
11571
+ // is via <svg>. If it happens via any other tag, then
11572
+ // it should be killed.
11573
+ if (parent.namespaceURI === HTML_NAMESPACE) {
11574
+ return tagName === 'svg';
11575
+ }
11576
+ // The only way to switch from MathML to SVG is via <svg>
11577
+ // if the parent is either <annotation-xml> or a MathML
11578
+ // text integration point.
11579
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
11580
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
11581
+ }
11582
+ // We only allow elements that are defined in SVG
11583
+ // spec. All others are disallowed in SVG namespace.
11584
+ return Boolean(ALL_SVG_TAGS[tagName]);
11585
+ };
11586
+ /**
11587
+ * Namespace rules for an element in the MathML namespace.
11588
+ *
11589
+ * @param tagName the element's lowercase tag name
11590
+ * @param parent the (possibly simulated) parent node
11591
+ * @param parentTagName the parent's lowercase tag name
11592
+ * @returns true if a spec-compliant parser could produce this element
11593
+ */
11594
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
11595
+ // The only way to switch from HTML namespace to MathML
11596
+ // is via <math>. If it happens via any other tag, then
11597
+ // it should be killed.
11598
+ if (parent.namespaceURI === HTML_NAMESPACE) {
11599
+ return tagName === 'math';
11600
+ }
11601
+ // The only way to switch from SVG to MathML is via
11602
+ // <math> and HTML integration points
11603
+ if (parent.namespaceURI === SVG_NAMESPACE) {
11604
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
11605
+ }
11606
+ // We only allow elements that are defined in MathML
11607
+ // spec. All others are disallowed in MathML namespace.
11608
+ return Boolean(ALL_MATHML_TAGS[tagName]);
11609
+ };
11610
+ /**
11611
+ * Namespace rules for an element in the HTML namespace.
11612
+ *
11613
+ * @param tagName the element's lowercase tag name
11614
+ * @param parent the (possibly simulated) parent node
11615
+ * @param parentTagName the parent's lowercase tag name
11616
+ * @returns true if a spec-compliant parser could produce this element
11617
+ */
11618
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
11619
+ // The only way to switch from SVG to HTML is via
11620
+ // HTML integration points, and from MathML to HTML
11621
+ // is via MathML text integration points
11622
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
11623
+ return false;
11624
+ }
11625
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
11626
+ return false;
11627
+ }
11628
+ // We disallow tags that are specific for MathML
11629
+ // or SVG and should never appear in HTML namespace
11630
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
11631
+ };
11426
11632
  /**
11427
11633
  * @param element a DOM element whose namespace is being checked
11428
11634
  * @returns Return false if the element has a
@@ -11445,51 +11651,13 @@ function createDOMPurify() {
11445
11651
  return false;
11446
11652
  }
11447
11653
  if (element.namespaceURI === SVG_NAMESPACE) {
11448
- // The only way to switch from HTML namespace to SVG
11449
- // is via <svg>. If it happens via any other tag, then
11450
- // it should be killed.
11451
- if (parent.namespaceURI === HTML_NAMESPACE) {
11452
- return tagName === 'svg';
11453
- }
11454
- // The only way to switch from MathML to SVG is via`
11455
- // svg if parent is either <annotation-xml> or MathML
11456
- // text integration points.
11457
- if (parent.namespaceURI === MATHML_NAMESPACE) {
11458
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
11459
- }
11460
- // We only allow elements that are defined in SVG
11461
- // spec. All others are disallowed in SVG namespace.
11462
- return Boolean(ALL_SVG_TAGS[tagName]);
11654
+ return _checkSvgNamespace(tagName, parent, parentTagName);
11463
11655
  }
11464
11656
  if (element.namespaceURI === MATHML_NAMESPACE) {
11465
- // The only way to switch from HTML namespace to MathML
11466
- // is via <math>. If it happens via any other tag, then
11467
- // it should be killed.
11468
- if (parent.namespaceURI === HTML_NAMESPACE) {
11469
- return tagName === 'math';
11470
- }
11471
- // The only way to switch from SVG to MathML is via
11472
- // <math> and HTML integration points
11473
- if (parent.namespaceURI === SVG_NAMESPACE) {
11474
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
11475
- }
11476
- // We only allow elements that are defined in MathML
11477
- // spec. All others are disallowed in MathML namespace.
11478
- return Boolean(ALL_MATHML_TAGS[tagName]);
11657
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
11479
11658
  }
11480
11659
  if (element.namespaceURI === HTML_NAMESPACE) {
11481
- // The only way to switch from SVG to HTML is via
11482
- // HTML integration points, and from MathML to HTML
11483
- // is via MathML text integration points
11484
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
11485
- return false;
11486
- }
11487
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
11488
- return false;
11489
- }
11490
- // We disallow tags that are specific for MathML
11491
- // or SVG and should never appear in HTML namespace
11492
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
11660
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
11493
11661
  }
11494
11662
  // For XHTML and XML documents that support custom namespaces
11495
11663
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
@@ -11514,7 +11682,74 @@ function createDOMPurify() {
11514
11682
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
11515
11683
  getParentNode(node).removeChild(node);
11516
11684
  } catch (_) {
11685
+ /* The normal detach failed — this is reached for a parentless node
11686
+ (getParentNode() is null, so .removeChild throws). Element.prototype
11687
+ .remove() is itself a spec no-op on a parentless node, so a recorded
11688
+ "removal" would otherwise hand the caller back an intact,
11689
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
11690
+ the style-with-element-child rule decided to kill). Fail closed by
11691
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
11692
+ rather than trying to "neutralize" the node via its own methods.
11693
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
11694
+ on the node, both of which a <form> root can clobber via a named child
11695
+ (and _isClobbered does not even probe getAttributeNames), so the
11696
+ neutralize step could itself be silently defeated, leaving the payload
11697
+ intact. A throw touches only the cached, clobber-safe remove() and
11698
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
11699
+ to every root-kill reason. REPORT-3.
11700
+ This lives inside the catch, so it never fires for a normally-removed
11701
+ in-tree node: those have a parent, removeChild() succeeds, and the
11702
+ catch is not entered. Only a kept (parentless) root reaches here. */
11517
11703
  remove(node);
11704
+ if (!getParentNode(node)) {
11705
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
11706
+ }
11707
+ }
11708
+ };
11709
+ /**
11710
+ * _neutralizeRoot
11711
+ *
11712
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
11713
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
11714
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
11715
+ * parentless guard throws, or any other re-entrant engine mutation — would
11716
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
11717
+ * after the abort point still carrying its handlers. There is no safe way
11718
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
11719
+ * remove every child and every attribute, then let the caller's catch see
11720
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
11721
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
11722
+ *
11723
+ * @param root the in-place root to empty
11724
+ */
11725
+ const _neutralizeRoot = function _neutralizeRoot(root) {
11726
+ const childNodes = getChildNodes(root);
11727
+ if (childNodes) {
11728
+ const snapshot = [];
11729
+ arrayForEach(childNodes, child => {
11730
+ arrayPush(snapshot, child);
11731
+ });
11732
+ arrayForEach(snapshot, child => {
11733
+ try {
11734
+ remove(child);
11735
+ } catch (_) {
11736
+ /* Best-effort teardown; a still-attached child is handled below */
11737
+ }
11738
+ });
11739
+ }
11740
+ const attributes = getAttributes(root);
11741
+ if (attributes) {
11742
+ for (let i = attributes.length - 1; i >= 0; --i) {
11743
+ const attribute = attributes[i];
11744
+ const name = attribute && attribute.name;
11745
+ if (typeof name === 'string') {
11746
+ try {
11747
+ root.removeAttribute(name);
11748
+ } catch (_) {
11749
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
11750
+ }
11751
+ }
11752
+ }
11518
11753
  }
11519
11754
  };
11520
11755
  /**
@@ -11549,6 +11784,72 @@ function createDOMPurify() {
11549
11784
  }
11550
11785
  }
11551
11786
  };
11787
+ /**
11788
+ * _stripDisallowedAttributes
11789
+ *
11790
+ * Removes every attribute the active configuration does not allow from a
11791
+ * single element, using the same allowlist as the main attribute pass (so
11792
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
11793
+ * neutralise nodes that are being discarded from an in-place tree.
11794
+ *
11795
+ * @param element the element to strip
11796
+ */
11797
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
11798
+ const attributes = getAttributes(element);
11799
+ if (!attributes) {
11800
+ return;
11801
+ }
11802
+ for (let i = attributes.length - 1; i >= 0; --i) {
11803
+ const attribute = attributes[i];
11804
+ const name = attribute && attribute.name;
11805
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
11806
+ continue;
11807
+ }
11808
+ try {
11809
+ element.removeAttribute(name);
11810
+ } catch (_) {
11811
+ /* Clobbered removeAttribute on a doomed node — ignore */
11812
+ }
11813
+ }
11814
+ };
11815
+ /**
11816
+ * _neutralizeSubtree
11817
+ *
11818
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
11819
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
11820
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
11821
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
11822
+ * those dropped nodes are detached from the caller's LIVE tree but a
11823
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
11824
+ * loading) keeps its queued resource event, which fires in page scope after
11825
+ * sanitize returns. This walks a removed subtree and strips every attribute
11826
+ * the active configuration does not allow — so `on*` handlers are cancelled
11827
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
11828
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
11829
+ * queued event can fire. Hook-free by design: these nodes leave the output,
11830
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
11831
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
11832
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
11833
+ * the `<img>`, are reached and scrubbed).
11834
+ *
11835
+ * @param root the root of a removed subtree to neutralise
11836
+ */
11837
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
11838
+ const stack = [root];
11839
+ while (stack.length > 0) {
11840
+ const node = stack.pop();
11841
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
11842
+ if (nodeType === NODE_TYPE.element) {
11843
+ _stripDisallowedAttributes(node);
11844
+ }
11845
+ const childNodes = getChildNodes(node);
11846
+ if (childNodes) {
11847
+ for (let i = childNodes.length - 1; i >= 0; --i) {
11848
+ stack.push(childNodes[i]);
11849
+ }
11850
+ }
11851
+ }
11852
+ };
11552
11853
  /**
11553
11854
  * _initDocument
11554
11855
  *
@@ -11570,7 +11871,7 @@ function createDOMPurify() {
11570
11871
  // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
11571
11872
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
11572
11873
  }
11573
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
11874
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
11574
11875
  /*
11575
11876
  * Use the DOMParser API by default, fallback later if needs be
11576
11877
  * DOMParser not work for svg when has multiple root element.
@@ -11610,6 +11911,20 @@ function createDOMPurify() {
11610
11911
  // eslint-disable-next-line no-bitwise
11611
11912
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
11612
11913
  };
11914
+ /**
11915
+ * Replace template expression syntax (mustache, ERB, template
11916
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
11917
+ * sites. Order matters: mustache, then ERB, then template literal.
11918
+ *
11919
+ * @param value the string to scrub
11920
+ * @returns the scrubbed string
11921
+ */
11922
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
11923
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
11924
+ value = stringReplace(value, ERB_EXPR$1, ' ');
11925
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
11926
+ return value;
11927
+ };
11613
11928
  /**
11614
11929
  * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
11615
11930
  * character data of an element subtree. Used as the final safety net for
@@ -11629,20 +11944,28 @@ function createDOMPurify() {
11629
11944
  *
11630
11945
  * @param node The root element whose character data should be scrubbed.
11631
11946
  */
11632
- const _scrubTemplateExpressions = function _scrubTemplateExpressions(node) {
11947
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
11948
+ var _node$querySelectorAl;
11633
11949
  node.normalize();
11634
11950
  const walker = createNodeIterator.call(node.ownerDocument || node, node,
11635
11951
  // eslint-disable-next-line no-bitwise
11636
11952
  NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
11637
11953
  let currentNode = walker.nextNode();
11638
11954
  while (currentNode) {
11639
- let data = currentNode.data;
11640
- arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
11641
- data = stringReplace(data, expr, ' ');
11642
- });
11643
- currentNode.data = data;
11955
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
11644
11956
  currentNode = walker.nextNode();
11645
11957
  }
11958
+ // NodeIterator does not descend into <template>.content per the DOM spec,
11959
+ // so we must explicitly recurse into each template's content fragment,
11960
+ // mirroring the approach used by _sanitizeShadowDOM.
11961
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
11962
+ if (templates) {
11963
+ arrayForEach(templates, tmpl => {
11964
+ if (_isDocumentFragment(tmpl.content)) {
11965
+ _scrubTemplateExpressions2(tmpl.content);
11966
+ }
11967
+ });
11968
+ }
11646
11969
  };
11647
11970
  /**
11648
11971
  * _isClobbered
@@ -11738,67 +12061,64 @@ function createDOMPurify() {
11738
12061
  }
11739
12062
  };
11740
12063
  function _executeHooks(hooks, currentNode, data) {
12064
+ if (hooks.length === 0) {
12065
+ return;
12066
+ }
11741
12067
  arrayForEach(hooks, hook => {
11742
12068
  hook.call(DOMPurify, currentNode, data, CONFIG);
11743
12069
  });
11744
12070
  }
11745
12071
  /**
11746
- * _sanitizeElements
12072
+ * Structural-threat checks that condemn a node regardless of the
12073
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
12074
+ * processing instructions, markup-bearing comments. Pure predicate;
12075
+ * the caller removes. Check order is load-bearing.
11747
12076
  *
11748
- * @protect nodeName
11749
- * @protect textContent
11750
- * @protect removeChild
11751
- * @param currentNode to check for permission to exist
11752
- * @return true if node was killed, false if left alive
12077
+ * @param currentNode the node to inspect
12078
+ * @param tagName the node's transformCaseFunc'd tag name
12079
+ * @return true if the node must be removed
11753
12080
  */
11754
- const _sanitizeElements = function _sanitizeElements(currentNode) {
11755
- let content = null;
11756
- /* Execute a hook if present */
11757
- _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
11758
- /* Check if element is clobbered or can clobber */
11759
- if (_isClobbered(currentNode)) {
11760
- _forceRemove(currentNode);
11761
- return true;
11762
- }
11763
- /* Now let's check the element's type and name */
11764
- const tagName = transformCaseFunc(currentNode.nodeName);
11765
- /* Execute a hook if present */
11766
- _executeHooks(hooks.uponSanitizeElement, currentNode, {
11767
- tagName,
11768
- allowedTags: ALLOWED_TAGS
11769
- });
12081
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
11770
12082
  /* Detect mXSS attempts abusing namespace confusion */
11771
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
11772
- _forceRemove(currentNode);
12083
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
11773
12084
  return true;
11774
12085
  }
11775
12086
  /* Remove risky CSS construction leading to mXSS */
11776
12087
  if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
11777
- _forceRemove(currentNode);
11778
12088
  return true;
11779
12089
  }
11780
12090
  /* Remove any occurrence of processing instructions */
11781
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
11782
- _forceRemove(currentNode);
12091
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
11783
12092
  return true;
11784
12093
  }
11785
12094
  /* Remove any kind of possibly harmful comments */
11786
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
11787
- _forceRemove(currentNode);
12095
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
11788
12096
  return true;
11789
12097
  }
11790
- /* Remove element if anything forbids its presence */
11791
- if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
11792
- /* Check if we have a custom element to handle */
11793
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
11794
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
11795
- return false;
11796
- }
11797
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
11798
- return false;
11799
- }
12098
+ return false;
12099
+ };
12100
+ /**
12101
+ * Handle a node whose tag is forbidden or not allowlisted: keep
12102
+ * allowed custom elements (false return exits _sanitizeElements
12103
+ * early - namespace/fallback checks and the afterSanitizeElements
12104
+ * hook are intentionally skipped for kept custom elements), else
12105
+ * hoist content per KEEP_CONTENT and remove.
12106
+ *
12107
+ * @param currentNode the disallowed node
12108
+ * @param tagName the node's transformCaseFunc'd tag name
12109
+ * @return true if the node was removed, false if kept
12110
+ */
12111
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
12112
+ /* Check if we have a custom element to handle */
12113
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
12114
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
12115
+ return false;
11800
12116
  }
11801
- /* Keep content except for bad-listed elements.
12117
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
12118
+ return false;
12119
+ }
12120
+ }
12121
+ /* Keep content except for bad-listed elements.
11802
12122
  Use the cached prototype getters exclusively — the previous code
11803
12123
  had `|| currentNode.parentNode` / `|| currentNode.childNodes`
11804
12124
  fallbacks, but the cached getters always return the canonical
@@ -11806,20 +12126,72 @@ function createDOMPurify() {
11806
12126
  path was dead in safe cases and a clobbering surface in unsafe
11807
12127
  ones. Falsy cached results stay falsy; the `if (childNodes &&
11808
12128
  parentNode)` check already gates correctly. */
11809
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
11810
- const parentNode = getParentNode(currentNode);
11811
- const childNodes = getChildNodes(currentNode);
11812
- if (childNodes && parentNode) {
11813
- const childCount = childNodes.length;
11814
- for (let i = childCount - 1; i >= 0; --i) {
11815
- const childClone = cloneNode(childNodes[i], true);
11816
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
11817
- }
12129
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
12130
+ const parentNode = getParentNode(currentNode);
12131
+ const childNodes = getChildNodes(currentNode);
12132
+ if (childNodes && parentNode) {
12133
+ const childCount = childNodes.length;
12134
+ /* In-place: hoist the *original* children so the iterator visits
12135
+ and sanitises them through the same allowlist pass as every other
12136
+ node. The caller built the tree in the live document, so the
12137
+ originals carry already-queued resource events (`<img onerror>`,
12138
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
12139
+ those originals detached but still armed, firing in page scope
12140
+ while the returned tree looked clean. Moving is safe in-place: the
12141
+ root is pre-validated as an allowed tag and so is never the node
12142
+ being removed, which keeps `parentNode` inside the iterator root
12143
+ and the relocated child inside the serialised tree.
12144
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
12145
+ at — and the result serialised from — `body`, so a restrictive
12146
+ ALLOWED_TAGS that removes `body` itself must leave its content in
12147
+ place, which only cloning does; and those paths parse into an
12148
+ inert document, so their discarded originals never had a queued
12149
+ event to neutralise.
12150
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
12151
+ valid whether we move (drops the trailing entry) or clone (leaves
12152
+ the list intact). */
12153
+ for (let i = childCount - 1; i >= 0; --i) {
12154
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
12155
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
11818
12156
  }
11819
12157
  }
12158
+ }
12159
+ _forceRemove(currentNode);
12160
+ return true;
12161
+ };
12162
+ /**
12163
+ * _sanitizeElements
12164
+ *
12165
+ * @protect nodeName
12166
+ * @protect textContent
12167
+ * @protect removeChild
12168
+ * @param currentNode to check for permission to exist
12169
+ * @return true if node was killed, false if left alive
12170
+ */
12171
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
12172
+ /* Execute a hook if present */
12173
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
12174
+ /* Check if element is clobbered or can clobber */
12175
+ if (_isClobbered(currentNode)) {
12176
+ _forceRemove(currentNode);
12177
+ return true;
12178
+ }
12179
+ /* Now let's check the element's type and name */
12180
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
12181
+ /* Execute a hook if present */
12182
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
12183
+ tagName,
12184
+ allowedTags: ALLOWED_TAGS
12185
+ });
12186
+ /* Remove mXSS vectors, processing instructions and risky comments */
12187
+ if (_isUnsafeNode(currentNode, tagName)) {
11820
12188
  _forceRemove(currentNode);
11821
12189
  return true;
11822
12190
  }
12191
+ /* Remove element if anything forbids its presence */
12192
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
12193
+ return _sanitizeDisallowedNode(currentNode, tagName);
12194
+ }
11823
12195
  /* Check whether element has a valid namespace.
11824
12196
  Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
11825
12197
  nodeType getter rather than `instanceof Element`, which is realm-
@@ -11832,17 +12204,14 @@ function createDOMPurify() {
11832
12204
  return true;
11833
12205
  }
11834
12206
  /* Make sure that older browsers don't get fallback-tag mXSS */
11835
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
12207
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
11836
12208
  _forceRemove(currentNode);
11837
12209
  return true;
11838
12210
  }
11839
12211
  /* Sanitize element content to be template-safe */
11840
12212
  if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
11841
12213
  /* Get the element's text content */
11842
- content = currentNode.textContent;
11843
- arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
11844
- content = stringReplace(content, expr, ' ');
11845
- });
12214
+ const content = _stripTemplateExpressions(currentNode.textContent);
11846
12215
  if (currentNode.textContent !== content) {
11847
12216
  arrayPush(DOMPurify.removed, {
11848
12217
  element: currentNode.cloneNode()
@@ -11877,7 +12246,7 @@ function createDOMPurify() {
11877
12246
  (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
11878
12247
  XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
11879
12248
  We don't need to check the value; it's always URI safe. */
11880
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted || FORBID_ATTR[lcName]) {
12249
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
11881
12250
  if (
11882
12251
  // First condition does a very basic check if a) it's basically a valid custom element tagname AND
11883
12252
  // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
@@ -11909,6 +12278,63 @@ function createDOMPurify() {
11909
12278
  const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
11910
12279
  return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
11911
12280
  };
12281
+ /**
12282
+ * Wrap an attribute value in the matching Trusted Types object when
12283
+ * the active policy requires it. Namespaced attributes pass through
12284
+ * unchanged (no TT support yet, see
12285
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
12286
+ *
12287
+ * @param lcTag lowercase tag name of the containing element
12288
+ * @param lcName lowercase attribute name
12289
+ * @param namespaceURI the attribute's namespace, if any
12290
+ * @param value the attribute value to wrap
12291
+ * @return the value, wrapped when Trusted Types demand it
12292
+ */
12293
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
12294
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
12295
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
12296
+ case 'TrustedHTML':
12297
+ {
12298
+ return _createTrustedHTML(value);
12299
+ }
12300
+ case 'TrustedScriptURL':
12301
+ {
12302
+ return _createTrustedScriptURL(value);
12303
+ }
12304
+ }
12305
+ }
12306
+ return value;
12307
+ };
12308
+ /**
12309
+ * Write a modified attribute value back onto the element. On
12310
+ * success, re-probe for clobbering introduced by the new value and
12311
+ * remove the element when found; otherwise pop the removal entry
12312
+ * recorded by the earlier _removeAttribute (long-standing pairing
12313
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
12314
+ * failure, remove the attribute instead.
12315
+ *
12316
+ * @param currentNode the element carrying the attribute
12317
+ * @param name the attribute name as present on the element
12318
+ * @param namespaceURI the attribute's namespace, if any
12319
+ * @param value the new attribute value
12320
+ */
12321
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
12322
+ try {
12323
+ if (namespaceURI) {
12324
+ currentNode.setAttributeNS(namespaceURI, name, value);
12325
+ } else {
12326
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
12327
+ currentNode.setAttribute(name, value);
12328
+ }
12329
+ if (_isClobbered(currentNode)) {
12330
+ _forceRemove(currentNode);
12331
+ } else {
12332
+ arrayPop(DOMPurify.removed);
12333
+ }
12334
+ } catch (_) {
12335
+ _removeAttribute(name, currentNode);
12336
+ }
12337
+ };
11912
12338
  /**
11913
12339
  * _sanitizeAttributes
11914
12340
  *
@@ -11935,6 +12361,7 @@ function createDOMPurify() {
11935
12361
  forceKeepAttr: undefined
11936
12362
  };
11937
12363
  let l = attributes.length;
12364
+ const lcTag = transformCaseFunc(currentNode.nodeName);
11938
12365
  /* Go backwards over all attributes; safely remove bad ones */
11939
12366
  while (l--) {
11940
12367
  const attr = attributes[l];
@@ -11972,7 +12399,7 @@ function createDOMPurify() {
11972
12399
  _removeAttribute(name, currentNode);
11973
12400
  continue;
11974
12401
  }
11975
- /* Did the hooks approve of the attribute? */
12402
+ /* Did the hooks force-keep the attribute? */
11976
12403
  if (hookEvent.forceKeepAttr) {
11977
12404
  continue;
11978
12405
  }
@@ -11982,56 +12409,24 @@ function createDOMPurify() {
11982
12409
  continue;
11983
12410
  }
11984
12411
  /* Work around a security issue in jQuery 3.0 */
11985
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
12412
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
11986
12413
  _removeAttribute(name, currentNode);
11987
12414
  continue;
11988
12415
  }
11989
12416
  /* Sanitize attribute content to be template-safe */
11990
12417
  if (SAFE_FOR_TEMPLATES) {
11991
- arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
11992
- value = stringReplace(value, expr, ' ');
11993
- });
12418
+ value = _stripTemplateExpressions(value);
11994
12419
  }
11995
12420
  /* Is `value` valid for this attribute? */
11996
- const lcTag = transformCaseFunc(currentNode.nodeName);
11997
12421
  if (!_isValidAttribute(lcTag, lcName, value)) {
11998
12422
  _removeAttribute(name, currentNode);
11999
12423
  continue;
12000
12424
  }
12001
12425
  /* Handle attributes that require Trusted Types */
12002
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
12003
- if (namespaceURI) ; else {
12004
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
12005
- case 'TrustedHTML':
12006
- {
12007
- value = trustedTypesPolicy.createHTML(value);
12008
- break;
12009
- }
12010
- case 'TrustedScriptURL':
12011
- {
12012
- value = trustedTypesPolicy.createScriptURL(value);
12013
- break;
12014
- }
12015
- }
12016
- }
12017
- }
12426
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
12018
12427
  /* Handle invalid data-* attribute set by try-catching it */
12019
12428
  if (value !== initValue) {
12020
- try {
12021
- if (namespaceURI) {
12022
- currentNode.setAttributeNS(namespaceURI, name, value);
12023
- } else {
12024
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
12025
- currentNode.setAttribute(name, value);
12026
- }
12027
- if (_isClobbered(currentNode)) {
12028
- _forceRemove(currentNode);
12029
- } else {
12030
- arrayPop(DOMPurify.removed);
12031
- }
12032
- } catch (_) {
12033
- _removeAttribute(name, currentNode);
12034
- }
12429
+ _setAttributeValue(currentNode, name, namespaceURI, value);
12035
12430
  }
12036
12431
  }
12037
12432
  /* Execute a hook if present */
@@ -12073,9 +12468,9 @@ function createDOMPurify() {
12073
12468
  iterator also surfaces. */
12074
12469
  const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
12075
12470
  if (shadowNodeType === NODE_TYPE.element) {
12076
- const innerSr = getShadowRoot ? getShadowRoot(shadowNode) : shadowNode.shadowRoot;
12471
+ const innerSr = getShadowRoot(shadowNode);
12077
12472
  if (_isDocumentFragment(innerSr)) {
12078
- _sanitizeAttachedShadowRoots2(innerSr);
12473
+ _sanitizeAttachedShadowRoots(innerSr);
12079
12474
  _sanitizeShadowDOM2(innerSr);
12080
12475
  }
12081
12476
  }
@@ -12102,46 +12497,81 @@ function createDOMPurify() {
12102
12497
  *
12103
12498
  * @param root the subtree root to walk for attached shadow roots
12104
12499
  */
12105
- const _sanitizeAttachedShadowRoots2 = function _sanitizeAttachedShadowRoots(root) {
12106
- const nodeType = getNodeType ? getNodeType(root) : root.nodeType;
12107
- if (nodeType === NODE_TYPE.element) {
12108
- const sr = getShadowRoot ? getShadowRoot(root) : root.shadowRoot;
12109
- // Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType-based
12110
- // detection rather than `instanceof DocumentFragment`, which is
12111
- // realm-bound and silently skipped shadow roots whose host element
12112
- // belonged to a foreign realm (e.g. iframe.contentDocument
12113
- // attachShadow). A foreign-realm ShadowRoot extends the foreign
12114
- // realm's DocumentFragment, not ours, so the old instanceof check
12115
- // returned false and the shadow subtree was never walked.
12116
- if (_isDocumentFragment(sr)) {
12117
- // Recurse first so that nested shadow roots are reached even if
12118
- // _sanitizeShadowDOM removes hosts at this level.
12119
- _sanitizeAttachedShadowRoots2(sr);
12120
- _sanitizeShadowDOM2(sr);
12500
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
12501
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
12502
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
12503
+ built straight into the DOM — the IN_PLACE surface) deeper than the JS
12504
+ call-stack budget would otherwise overflow native recursion here and
12505
+ throw at the IN_PLACE entry pre-pass, before a single node is
12506
+ sanitized, leaving the caller's live tree untouched (fail-open). See
12507
+ campaign-3 F4. A heap stack keeps depth off the call stack.
12508
+ Each work item is either a node to descend into, or a deferred
12509
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
12510
+ form preserves the original post-order discipline: a shadow root's
12511
+ nested shadow roots are discovered before the outer shadow is
12512
+ sanitized (which may remove hosts). Pushes are in reverse of the
12513
+ desired processing order (LIFO): template content, then children, then
12514
+ the shadow-sanitize, then the shadow walk — so the order matches the
12515
+ previous recursion exactly. */
12516
+ const stack = [{
12517
+ node: root,
12518
+ shadow: null
12519
+ }];
12520
+ while (stack.length > 0) {
12521
+ const item = stack.pop();
12522
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
12523
+ if (item.shadow) {
12524
+ _sanitizeShadowDOM2(item.shadow);
12525
+ continue;
12121
12526
  }
12122
- }
12123
- // Snapshot children before recursing. Sanitization of one subtree
12124
- // (e.g. via an uponSanitizeShadowNode hook) may detach siblings,
12125
- // and naive nextSibling traversal would silently skip the rest of
12126
- // the list once a node is detached.
12127
- const childNodes = getChildNodes ? getChildNodes(root) : root.childNodes;
12128
- if (!childNodes) {
12129
- return;
12130
- }
12131
- const snapshot = [];
12132
- arrayForEach(childNodes, child => {
12133
- arrayPush(snapshot, child);
12134
- });
12135
- for (const child of snapshot) {
12136
- _sanitizeAttachedShadowRoots2(child);
12137
- }
12138
- /* When the root is a <template>, also descend into root.content */
12139
- if (nodeType === NODE_TYPE.element) {
12140
- const rootName = getNodeName ? getNodeName(root) : null;
12141
- if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
12142
- const content = root.content;
12143
- if (_isDocumentFragment(content)) {
12144
- _sanitizeAttachedShadowRoots2(content);
12527
+ const node = item.node;
12528
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
12529
+ const isElement = nodeType === NODE_TYPE.element;
12530
+ /* (pushed last processed first) Children, snapshotted in reverse so
12531
+ the first child is processed first. Snapshotting matters because a
12532
+ hook may detach siblings mid-walk. */
12533
+ const childNodes = getChildNodes(node);
12534
+ if (childNodes) {
12535
+ for (let i = childNodes.length - 1; i >= 0; --i) {
12536
+ stack.push({
12537
+ node: childNodes[i],
12538
+ shadow: null
12539
+ });
12540
+ }
12541
+ }
12542
+ /* (pushed before children → processed after them, matching the old
12543
+ "template content last" order) When the node is a <template>,
12544
+ descend into its content. */
12545
+ if (isElement) {
12546
+ const rootName = getNodeName ? getNodeName(node) : null;
12547
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
12548
+ const content = node.content;
12549
+ if (_isDocumentFragment(content)) {
12550
+ stack.push({
12551
+ node: content,
12552
+ shadow: null
12553
+ });
12554
+ }
12555
+ }
12556
+ }
12557
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
12558
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
12559
+ rather than `instanceof DocumentFragment`, which is realm-bound and
12560
+ silently skipped foreign-realm shadow roots (e.g.
12561
+ iframe.contentDocument attachShadow). */
12562
+ if (isElement) {
12563
+ const sr = getShadowRoot(node);
12564
+ if (_isDocumentFragment(sr)) {
12565
+ /* Push the deferred sanitise first so it pops after the shadow
12566
+ walk we push next, i.e. nested shadow roots are discovered
12567
+ before this one is sanitised. */
12568
+ stack.push({
12569
+ node: null,
12570
+ shadow: sr
12571
+ }, {
12572
+ node: sr,
12573
+ shadow: null
12574
+ });
12145
12575
  }
12146
12576
  }
12147
12577
  }
@@ -12177,11 +12607,14 @@ function createDOMPurify() {
12177
12607
  }
12178
12608
  /* Clean up removed elements */
12179
12609
  DOMPurify.removed = [];
12180
- /* Check if dirty is correctly typed for IN_PLACE */
12181
- if (typeof dirty === 'string') {
12182
- IN_PLACE = false;
12183
- }
12184
- if (IN_PLACE) {
12610
+ /* Resolve IN_PLACE for this call without mutating persistent config.
12611
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
12612
+ where _parseConfig is skipped on later calls: a single string call would
12613
+ disable in-place mode for every subsequent node call, returning a
12614
+ sanitized copy while leaving the caller's node — which in-place callers
12615
+ keep using and whose return value they ignore — unsanitized. REPORT-2. */
12616
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
12617
+ if (inPlace) {
12185
12618
  /* Do some early pre-sanitization to avoid unsafe root nodes.
12186
12619
  Read nodeName through the cached prototype getter — a clobbering
12187
12620
  child named "nodeName" on the form root would otherwise shadow
@@ -12208,8 +12641,16 @@ function createDOMPurify() {
12208
12641
  throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
12209
12642
  }
12210
12643
  /* Sanitize attached shadow roots before the main iterator runs.
12211
- The iterator does not descend into shadow trees. */
12212
- _sanitizeAttachedShadowRoots2(dirty);
12644
+ The iterator does not descend into shadow trees. Same fail-closed
12645
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
12646
+ inside a shadow root could abort this pre-pass before the walk runs,
12647
+ which would otherwise leave the entire live tree unsanitized. */
12648
+ try {
12649
+ _sanitizeAttachedShadowRoots(dirty);
12650
+ } catch (error) {
12651
+ _neutralizeRoot(dirty);
12652
+ throw error;
12653
+ }
12213
12654
  } else if (_isNode(dirty)) {
12214
12655
  /* If dirty is a DOM element, append to an empty document to avoid
12215
12656
  elements being stripped by the parser */
@@ -12229,13 +12670,13 @@ function createDOMPurify() {
12229
12670
  descend into shadow trees. The walk routes every read through a
12230
12671
  cached prototype getter so clobbering descendants on a form root
12231
12672
  cannot hide a shadow host from this pass. */
12232
- _sanitizeAttachedShadowRoots2(importedNode);
12673
+ _sanitizeAttachedShadowRoots(importedNode);
12233
12674
  } else {
12234
12675
  /* Exit directly if we have nothing to do */
12235
12676
  if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
12236
12677
  // eslint-disable-next-line unicorn/prefer-includes
12237
12678
  dirty.indexOf('<') === -1) {
12238
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
12679
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
12239
12680
  }
12240
12681
  /* Initialize the document to work on */
12241
12682
  body = _initDocument(dirty);
@@ -12249,32 +12690,59 @@ function createDOMPurify() {
12249
12690
  _forceRemove(body.firstChild);
12250
12691
  }
12251
12692
  /* Get node iterator */
12252
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
12253
- /* Now start iterating over the created document */
12254
- while (currentNode = nodeIterator.nextNode()) {
12255
- /* Sanitize tags and elements */
12256
- _sanitizeElements(currentNode);
12257
- /* Check attributes next */
12258
- _sanitizeAttributes(currentNode);
12259
- /* Shadow DOM detected, sanitize it.
12260
- Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
12261
- instead of instanceof, so foreign-realm <template>.content is
12262
- walked correctly. */
12263
- if (_isDocumentFragment(currentNode.content)) {
12264
- _sanitizeShadowDOM2(currentNode.content);
12693
+ const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
12694
+ /* Now start iterating over the created document.
12695
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
12696
+ engine/custom-element mutation can detach a node mid-walk so
12697
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
12698
+ barrier the caller's in-place tree would be left half-sanitized with the
12699
+ unvisited tail still armed. On any throw we fail closed — strip the
12700
+ in-place root bare then rethrow so the existing throw contract is
12701
+ preserved. (String/DOM-copy paths never return the partial body, so the
12702
+ propagating throw is already fail-closed there.) */
12703
+ try {
12704
+ while (currentNode = nodeIterator.nextNode()) {
12705
+ /* Sanitize tags and elements */
12706
+ _sanitizeElements(currentNode);
12707
+ /* Check attributes next */
12708
+ _sanitizeAttributes(currentNode);
12709
+ /* Shadow DOM detected, sanitize it.
12710
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
12711
+ instead of instanceof, so foreign-realm <template>.content is
12712
+ walked correctly. */
12713
+ if (_isDocumentFragment(currentNode.content)) {
12714
+ _sanitizeShadowDOM2(currentNode.content);
12715
+ }
12716
+ }
12717
+ } catch (error) {
12718
+ if (inPlace) {
12719
+ _neutralizeRoot(dirty);
12265
12720
  }
12721
+ throw error;
12266
12722
  }
12267
12723
  /* If we sanitized `dirty` in-place, return it. */
12268
- if (IN_PLACE) {
12724
+ if (inPlace) {
12725
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
12726
+ the caller's live tree is detached but may still hold a queued
12727
+ resource-event handler that fires in page scope after we return. The
12728
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
12729
+ non-allow-listed attributes off every other removed subtree (clobber,
12730
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
12731
+ cancelled before any event can fire. Runs synchronously, pre-return. */
12732
+ arrayForEach(DOMPurify.removed, entry => {
12733
+ if (entry.element) {
12734
+ _neutralizeSubtree(entry.element);
12735
+ }
12736
+ });
12269
12737
  if (SAFE_FOR_TEMPLATES) {
12270
- _scrubTemplateExpressions(dirty);
12738
+ _scrubTemplateExpressions2(dirty);
12271
12739
  }
12272
12740
  return dirty;
12273
12741
  }
12274
12742
  /* Return sanitized string or DOM */
12275
12743
  if (RETURN_DOM) {
12276
12744
  if (SAFE_FOR_TEMPLATES) {
12277
- _scrubTemplateExpressions(body);
12745
+ _scrubTemplateExpressions2(body);
12278
12746
  }
12279
12747
  if (RETURN_DOM_FRAGMENT) {
12280
12748
  returnNode = createDocumentFragment.call(body.ownerDocument);
@@ -12304,11 +12772,9 @@ function createDOMPurify() {
12304
12772
  }
12305
12773
  /* Sanitize final string template-safe */
12306
12774
  if (SAFE_FOR_TEMPLATES) {
12307
- arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
12308
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
12309
- });
12775
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
12310
12776
  }
12311
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
12777
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
12312
12778
  };
12313
12779
  DOMPurify.setConfig = function () {
12314
12780
  let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -12318,6 +12784,12 @@ function createDOMPurify() {
12318
12784
  DOMPurify.clearConfig = function () {
12319
12785
  CONFIG = null;
12320
12786
  SET_CONFIG = false;
12787
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
12788
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
12789
+ // never recreated — Trusted Types throws on duplicate names) is restored by
12790
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
12791
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
12792
+ emptyHTML = '';
12321
12793
  };
12322
12794
  DOMPurify.isValidAttribute = function (tag, attr, value) {
12323
12795
  /* Initialize shared config vars if necessary. */
@@ -76656,6 +77128,9 @@ class XMLSession {
76656
77128
  indexURL: r.getAttribute("index"),
76657
77129
  order: idx
76658
77130
  };
77131
+ if (r.hasAttribute("format")) {
77132
+ config.format = r.getAttribute("format");
77133
+ }
76659
77134
  resourceMap.set(config.url, config);
76660
77135
  if (!hasTrackElements) {
76661
77136
  tracks.push(config);
@@ -76743,6 +77218,13 @@ function extractTrackAttributes(track, config) {
76743
77218
 
76744
77219
  config.name = track.getAttribute("name");
76745
77220
 
77221
+ if(track.hasAttribute("type")) {
77222
+ config.type = track.getAttribute("type");
77223
+ }
77224
+ if(track.hasAttribute("format")) {
77225
+ config.format = track.getAttribute("format");
77226
+ }
77227
+
76746
77228
  const color = track.getAttribute("color");
76747
77229
  if (color) {
76748
77230
  config.color = "rgb(" + color + ")";
@@ -77054,7 +77536,7 @@ function createReferenceFrameList(loci, genome, browserFlanking, minimumBases, v
77054
77536
  })
77055
77537
  }
77056
77538
 
77057
- const _version = "3.8.1";
77539
+ const _version = "3.8.2";
77058
77540
  function version() {
77059
77541
  return _version
77060
77542
  }