@lwrjs/client-modules 0.23.6 → 0.23.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1347,6 +1347,22 @@ function consoleWarn$LWS(...args$LWS) {
1347
1347
  const gaterEnabledFeatures$LWS = toSafeSet$LWS(new SetCtor$LWS$1());
1348
1348
  const FEATURE_NAME_PREFIX$LWS = 'com.salesforce.locker.';
1349
1349
  const fullName$LWS = featureName$LWS => featureName$LWS.startsWith(FEATURE_NAME_PREFIX$LWS) ? featureName$LWS : `${FEATURE_NAME_PREFIX$LWS}${featureName$LWS}`;
1350
+ // The canonical set of LWS feature gates that are enabled in the test
1351
+ // harness (karma), and therefore in CI. This is the single source of truth
1352
+ // for "what gates a faithful LWS run turns on". Consumers register it as
1353
+ // their baseline so they reproduce CI's gate state: the karma evaluator
1354
+ // registers exactly this list before running tests, and the @locker/cli
1355
+ // tool registers it as the default for a `lws` run. Adding a gate here
1356
+ // turns it on by default in every consumer that registers this list.
1357
+ //
1358
+ // This is an inert exported constant, never auto-registered at module
1359
+ // load: registering here would change behavior for every @locker/shared
1360
+ // consumer. Each consumer opts in by passing it to
1361
+ // registerGaterEnabledFeatures. Names are fully qualified so the value
1362
+ // reads identically to what isGaterEnabledFeature stores (register and
1363
+ // deregister also accept the short form via fullName above). Frozen so a
1364
+ // consumer cannot mutate the shared array.
1365
+ Object.freeze([`${FEATURE_NAME_PREFIX$LWS}changesSince.256`, `${FEATURE_NAME_PREFIX$LWS}changesSince.258`, `${FEATURE_NAME_PREFIX$LWS}changesSince.260`, `${FEATURE_NAME_PREFIX$LWS}changesSince.262`, `${FEATURE_NAME_PREFIX$LWS}changesSince.264`, `${FEATURE_NAME_PREFIX$LWS}htmlAnchorElementHrefValidation`, `${FEATURE_NAME_PREFIX$LWS}enableSandboxedSameOriginIframe`, `${FEATURE_NAME_PREFIX$LWS}xmlEntityAttackPrologScan`]);
1350
1366
  function isGaterEnabledFeature$LWS(featureName$LWS) {
1351
1367
  return gaterEnabledFeatures$LWS.has(fullName$LWS(featureName$LWS));
1352
1368
  }
@@ -1511,7 +1527,7 @@ const {
1511
1527
  const PromiseResolve$LWS = PromiseCtor$LWS.resolve.bind(PromiseCtor$LWS);
1512
1528
  const PromiseReject$LWS = PromiseCtor$LWS.reject.bind(PromiseCtor$LWS);
1513
1529
  const trustedResources$LWS = toSafeSet$LWS(new SetCtor$LWS$1());
1514
- /*! version: 0.28.2 */
1530
+ /*! version: 0.28.4 */
1515
1531
 
1516
1532
  /*!
1517
1533
  * Copyright (C) 2019 salesforce.com, inc.
@@ -1979,6 +1995,69 @@ const DOCTYPE_WITH_INTERNAL_SUBSET_REGEX$LWS = /<!doctype\s+\S+\s*\[/;
1979
1995
  // Matches: <!DOCTYPE root SYSTEM "..."> or <!DOCTYPE root PUBLIC "..." "...">
1980
1996
  // External DTDs can define entities that get expanded with malicious content.
1981
1997
  const DOCTYPE_EXTERNAL_ENTITY_REGEX$LWS = /<!doctype\s+\S+\s+(?:system|public)\s/;
1998
+ const DOCTYPE_OPENER$LWS = '<!doctype';
1999
+ const PI_OPENER$LWS = '<?';
2000
+ const PI_CLOSER$LWS = '?>';
2001
+ const COMMENT_OPENER$LWS = '<!--';
2002
+ const COMMENT_CLOSER$LWS = '-->';
2003
+ // Locate a DOCTYPE that sits in the document prolog — the only position where a
2004
+ // DTD is actually parsed and where entity definitions can take effect. A DTD is
2005
+ // only meaningful before the root element's start tag; anything after the root
2006
+ // element opens (text, CDATA sections, comments, processing instructions) is
2007
+ // inert character data and can never act as a DTD, no matter what it spells.
2008
+ //
2009
+ // Returns the prolog slice beginning at the DOCTYPE so the existing
2010
+ // dangerous-form regexes can classify it, or null when the prolog contains no
2011
+ // DOCTYPE. Walks the prolog token by token, skipping the XML declaration and
2012
+ // processing instructions (`<?...?>`) and comments (`<!-- ... -->`), and stops
2013
+ // at the first other `<` — that is the root element's start tag. Skipping
2014
+ // comments here is what defeats the `<!-- <![CDATA[ -->` decoy: a real prolog
2015
+ // DOCTYPE after a comment is still found, and a DOCTYPE buried inside a comment
2016
+ // is correctly ignored.
2017
+ function findPrologDoctype$LWS(normalizedInput$LWS) {
2018
+ const {
2019
+ length: length$LWS
2020
+ } = normalizedInput$LWS;
2021
+ let index$LWS = 0;
2022
+ while (index$LWS < length$LWS) {
2023
+ const char$LWS = ReflectApply$LWS$1(StringProtoCharAt$LWS, normalizedInput$LWS, [index$LWS]);
2024
+ // Skip insignificant whitespace between prolog tokens.
2025
+ if (char$LWS === ' ' || char$LWS === '\t' || char$LWS === '\n' || char$LWS === '\r') {
2026
+ index$LWS += 1;
2027
+ continue;
2028
+ }
2029
+ // Anything that is not a markup-opening `<` at this point is either the
2030
+ // start of the root element's content model or malformed; in both cases
2031
+ // there is no prolog DOCTYPE to find.
2032
+ if (char$LWS !== '<') {
2033
+ return null;
2034
+ }
2035
+ if (ReflectApply$LWS$1(StringProtoStartsWith$LWS, normalizedInput$LWS, [DOCTYPE_OPENER$LWS, index$LWS])) {
2036
+ return ReflectApply$LWS$1(StringProtoSlice$LWS$1, normalizedInput$LWS, [index$LWS]);
2037
+ }
2038
+ if (ReflectApply$LWS$1(StringProtoStartsWith$LWS, normalizedInput$LWS, [COMMENT_OPENER$LWS, index$LWS])) {
2039
+ const closerOffset$LWS = ReflectApply$LWS$1(StringProtoIndexOf$LWS, normalizedInput$LWS, [COMMENT_CLOSER$LWS, index$LWS + COMMENT_OPENER$LWS.length]);
2040
+ // Unterminated comment: no well-formed prolog DOCTYPE can follow.
2041
+ if (closerOffset$LWS === -1) {
2042
+ return null;
2043
+ }
2044
+ index$LWS = closerOffset$LWS + COMMENT_CLOSER$LWS.length;
2045
+ continue;
2046
+ }
2047
+ if (ReflectApply$LWS$1(StringProtoStartsWith$LWS, normalizedInput$LWS, [PI_OPENER$LWS, index$LWS])) {
2048
+ const closerOffset$LWS = ReflectApply$LWS$1(StringProtoIndexOf$LWS, normalizedInput$LWS, [PI_CLOSER$LWS, index$LWS + PI_OPENER$LWS.length]);
2049
+ if (closerOffset$LWS === -1) {
2050
+ return null;
2051
+ }
2052
+ index$LWS = closerOffset$LWS + PI_CLOSER$LWS.length;
2053
+ continue;
2054
+ }
2055
+ // First `<` that is not a PI, comment, or DOCTYPE is the root element
2056
+ // start tag. The prolog has ended without a DOCTYPE.
2057
+ return null;
2058
+ }
2059
+ return null;
2060
+ }
1982
2061
  /* eslint-disable no-underscore-dangle */
1983
2062
  class Validator$LWS {
1984
2063
  constructor(document$LWS, {
@@ -1995,12 +2074,28 @@ class Validator$LWS {
1995
2074
  // Detect XML External Entity (XXE) injection attacks via DOCTYPE declarations.
1996
2075
  // Attackers can embed malicious script content inside ENTITY definitions that
1997
2076
  // get expanded when the XML/SVG is rendered, bypassing DOMPurify sanitization.
2077
+ //
2078
+ // A DTD only takes effect when it appears in the document prolog (before the
2079
+ // root element). The original guard scanned the entire input for a dangerous
2080
+ // DOCTYPE substring, which also rejected benign documents that merely quote a
2081
+ // DOCTYPE as inert text — inside a CDATA section, an XML comment, or element
2082
+ // text. The prolog-aware path keeps the dangerous-form classification
2083
+ // (internal subset, SYSTEM/PUBLIC external reference) exactly as-is, but only
2084
+ // applies it to a DOCTYPE that actually sits in the prolog. When the gate is
2085
+ // off, the original whole-input scan is preserved.
1998
2086
  // eslint-disable-next-line class-methods-use-this
1999
2087
  this.isXMLEntityAttack = input$LWS => {
2000
2088
  const normalizedInput$LWS = normalizeInput$LWS(input$LWS, ' ');
2001
2089
  // Block DOCTYPE with:
2002
2090
  // - Internal DTD subset (e.g., <!DOCTYPE svg [<!ENTITY foo "...">]>)
2003
2091
  // - SYSTEM or PUBLIC external entity references
2092
+ if (isGaterEnabledFeature$LWS('xmlEntityAttackPrologScan')) {
2093
+ const prologDoctype$LWS = findPrologDoctype$LWS(normalizedInput$LWS);
2094
+ if (prologDoctype$LWS === null) {
2095
+ return false;
2096
+ }
2097
+ return ReflectApply$LWS$1(RegExpProtoTest$LWS$1, DOCTYPE_WITH_INTERNAL_SUBSET_REGEX$LWS, [prologDoctype$LWS]) || ReflectApply$LWS$1(RegExpProtoTest$LWS$1, DOCTYPE_EXTERNAL_ENTITY_REGEX$LWS, [prologDoctype$LWS]);
2098
+ }
2004
2099
  return ReflectApply$LWS$1(RegExpProtoTest$LWS$1, DOCTYPE_WITH_INTERNAL_SUBSET_REGEX$LWS, [normalizedInput$LWS]) || ReflectApply$LWS$1(RegExpProtoTest$LWS$1, DOCTYPE_EXTERNAL_ENTITY_REGEX$LWS, [normalizedInput$LWS]);
2005
2100
  };
2006
2101
  // Detect namespaced script elements that execute in XML contexts.
@@ -2261,6 +2356,7 @@ const {
2261
2356
  } = ReflectGetOwnPropertyDescriptor$LWS(HTMLAnchorElementProto$LWS, 'href');
2262
2357
  const HTMLAnchorElementProtoPathnameGetter$LWS = ObjectLookupOwnGetter$LWS$1(HTMLAnchorElementProto$LWS, 'pathname');
2263
2358
  const HTMLAnchorElementProtoProtocolGetter$LWS = ObjectLookupOwnGetter$LWS$1(HTMLAnchorElementProto$LWS, 'protocol');
2359
+ const HTMLAnchorElementProtoProtocolSetter$LWS = ObjectLookupOwnSetter$LWS(HTMLAnchorElementProto$LWS, 'protocol');
2264
2360
  const {
2265
2361
  prototype: HTMLButtonElementProto$LWS
2266
2362
  } = HTMLButtonElement;
@@ -2514,7 +2610,7 @@ const {
2514
2610
  const XhrProtoResponseTextGetter$LWS = ObjectLookupOwnGetter$LWS$1(XhrProto$LWS, 'responseText');
2515
2611
  const XhrProtoStatusGetter$LWS = ObjectLookupOwnGetter$LWS$1(XhrProto$LWS, 'status');
2516
2612
  ObjectLookupOwnSetter$LWS(XhrProto$LWS, 'withCredentials');
2517
- /*! version: 0.28.2 */
2613
+ /*! version: 0.28.4 */
2518
2614
 
2519
2615
  /*!
2520
2616
  * Copyright (C) 2019 salesforce.com, inc.
@@ -2542,7 +2638,21 @@ const DISALLOWED_ENDPOINTS_LIST$LWS = ['/aura', '/webruntime'];
2542
2638
  const DISALLOWED_BROWSING_CONTEXT_ENDPOINTS_LIST$LWS = ['/chatter'];
2543
2639
  const TRUSTED_DOMAINS_REG_EXP$LWS = /\.(force|salesforce|visualforce|documentforce|my\.site|salesforce-sites)\.com$/;
2544
2640
  const URL_SCHEMES_LIST$LWS = toSafeArray$LWS$1(['about:', 'http:', 'https:']);
2545
- const newlinesAndTabsRegExp$LWS = /[\u2028\u2029\n\r\t]/g;
2641
+ // Characters that browsers strip or ignore when resolving a URL, but that defeat
2642
+ // LWS's string-based scheme/endpoint checks if left in place. A leading invisible
2643
+ // character (e.g. U+200B before "javascript:") makes the URL parser treat the input
2644
+ // as authority-relative, leaving the scheme empty so the allowlist check is fooled;
2645
+ // an embedded one (e.g. "/se\u200btup") slips past endpoint denylist matching.
2646
+ // Stripping them before parsing closes both for every URL-bearing distortion at once.
2647
+ //
2648
+ // \p{Cc} - control characters (covers \t \n \r and the NULL byte)
2649
+ // \p{Cf} - format characters (zero-width space/joiners, soft hyphen, BOM, bidi marks
2650
+ // U+200E/U+200F/U+202A-U+202E, word joiner, etc.)
2651
+ // \u034f - combining grapheme joiner (category Mn, not Cc/Cf, but perceptually
2652
+ // invisible and ignored by the URL parser, so listed explicitly)
2653
+ // \u2028 - line separator (category Zl, not covered by Cc)
2654
+ // \u2029 - paragraph separator (category Zp, not covered by Cc)
2655
+ const strippableURLCharsRegExp$LWS = /[\0-\x1F\x7F-\x9F\xAD\u034F\u0600-\u0605\u061C\u06DD\u070F\u0890\u0891\u08E2\u180E\u200B-\u200F\u2028-\u202E\u2060-\u2064\u2066-\u206F\uFEFF\uFFF9-\uFFFB\u{110BD}\u{110CD}\u{13430}-\u{1343F}\u{1BCA0}-\u{1BCA3}\u{1D173}-\u{1D17A}\u{E0001}\u{E0020}-\u{E007F}]/gu;
2546
2656
  const normalizerAnchor$LWS = ReflectApply$LWS$1(DocumentProtoCreateElement$LWS$1, rootDocument$LWS, ['a']);
2547
2657
  function isSameOriginURL$LWS(resourceValue$LWS) {
2548
2658
  let validParsedURL$LWS;
@@ -2566,13 +2676,18 @@ function isAttemptingToExploitURL$LWS(resourceValue$LWS) {
2566
2676
  const locationHref$LWS = rootWindow$LWS$1.location.href;
2567
2677
  return loweredResourceValue$LWS === '/' || loweredResourceValue$LWS[0] === '#' || loweredResourceValue$LWS[0] === '?' || ReflectApply$LWS$1(StringProtoStartsWith$LWS, loweredResourceValue$LWS, [`${locationHref$LWS}#`]) || ReflectApply$LWS$1(StringProtoStartsWith$LWS, loweredResourceValue$LWS, [`${locationHref$LWS}?`]);
2568
2678
  }
2569
- // Validates that a URL doesn't target disallowed endpoints
2679
+ // Validates that a URL doesn't target disallowed endpoints.
2570
2680
  // @TODO: W-7302311 Make paths and domains configurable.
2571
2681
  function isAllowedEndpointURL$LWS(parsedURL$LWS) {
2572
2682
  const loweredPathname$LWS = ReflectApply$LWS$1(StringProtoToLowerCase$LWS, parsedURL$LWS.pathname, []);
2573
2683
  // This MUST be done inside the function because the gate may not be enabled when the
2574
2684
  // module code is loaded and evaluated (as would be the case for test environments)
2575
2685
  if (isGaterEnabledFeature$LWS('changesSince.262')) {
2686
+ // Cross-origin URLs bypass the denylist — they cannot carry the user's session
2687
+ // credentials to this instance's platform-internal endpoints (W-23009170).
2688
+ if (!isSameOriginURL$LWS(parsedURL$LWS.normalizedURL)) {
2689
+ return true;
2690
+ }
2576
2691
  DISALLOWED_ENDPOINTS_LIST$LWS.push('/_nc_external', '/force', '/setup');
2577
2692
  }
2578
2693
  for (let i$LWS = 0, {
@@ -2623,7 +2738,7 @@ function sanitizeURLForElement$LWS(url$LWS) {
2623
2738
  return resolveURL$LWS(sanitizeURLString$LWS(url$LWS));
2624
2739
  }
2625
2740
  function sanitizeURLString$LWS(urlString$LWS) {
2626
- return urlString$LWS === '' ? urlString$LWS : ReflectApply$LWS$1(StringProtoReplace$LWS, urlString$LWS, [newlinesAndTabsRegExp$LWS, '']);
2741
+ return urlString$LWS === '' ? urlString$LWS : ReflectApply$LWS$1(StringProtoReplace$LWS, urlString$LWS, [strippableURLCharsRegExp$LWS, '']);
2627
2742
  }
2628
2743
  // Per the HTML spec, srcset candidates are comma-delimited. A candidate is a
2629
2744
  // URL optionally followed by whitespace and a width/density descriptor like
@@ -2663,26 +2778,67 @@ function sanitizeSrcsetAndValidateEndpoints$LWS(rawSrcset$LWS) {
2663
2778
  }
2664
2779
  return sanitized$LWS;
2665
2780
  }
2666
- /*! version: 0.28.2 */
2781
+ /*! version: 0.28.4 */
2667
2782
 
2668
- /*! @license DOMPurify 3.2.4 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.4/LICENSE */
2783
+ /*! @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 */
2669
2784
 
2670
- const {
2671
- entries,
2672
- setPrototypeOf,
2673
- isFrozen,
2674
- getPrototypeOf,
2675
- getOwnPropertyDescriptor
2676
- } = Object;
2677
- let {
2678
- freeze,
2679
- seal,
2680
- create
2681
- } = Object; // eslint-disable-line import/no-mutable-exports
2682
- let {
2683
- apply,
2684
- construct
2685
- } = typeof Reflect !== 'undefined' && Reflect;
2785
+ function _arrayLikeToArray(r, a) {
2786
+ (null == a || a > r.length) && (a = r.length);
2787
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
2788
+ return n;
2789
+ }
2790
+ function _arrayWithHoles(r) {
2791
+ if (Array.isArray(r)) return r;
2792
+ }
2793
+ function _iterableToArrayLimit(r, l) {
2794
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
2795
+ if (null != t) {
2796
+ var e,
2797
+ n,
2798
+ i,
2799
+ u,
2800
+ a = [],
2801
+ f = true,
2802
+ o = false;
2803
+ try {
2804
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
2805
+ } catch (r) {
2806
+ o = true, n = r;
2807
+ } finally {
2808
+ try {
2809
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
2810
+ } finally {
2811
+ if (o) throw n;
2812
+ }
2813
+ }
2814
+ return a;
2815
+ }
2816
+ }
2817
+ function _nonIterableRest() {
2818
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2819
+ }
2820
+ function _slicedToArray(r, e) {
2821
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
2822
+ }
2823
+ function _unsupportedIterableToArray(r, a) {
2824
+ if (r) {
2825
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
2826
+ var t = {}.toString.call(r).slice(8, -1);
2827
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
2828
+ }
2829
+ }
2830
+
2831
+ const entries = Object.entries,
2832
+ setPrototypeOf = Object.setPrototypeOf,
2833
+ isFrozen = Object.isFrozen,
2834
+ getPrototypeOf = Object.getPrototypeOf,
2835
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
2836
+ let freeze = Object.freeze,
2837
+ seal = Object.seal,
2838
+ create = Object.create; // eslint-disable-line import/no-mutable-exports
2839
+ let _ref = typeof Reflect !== 'undefined' && Reflect,
2840
+ apply = _ref.apply,
2841
+ construct = _ref.construct;
2686
2842
  if (!freeze) {
2687
2843
  freeze = function freeze(x) {
2688
2844
  return x;
@@ -2694,12 +2850,18 @@ if (!seal) {
2694
2850
  };
2695
2851
  }
2696
2852
  if (!apply) {
2697
- apply = function apply(fun, thisValue, args) {
2698
- return fun.apply(thisValue, args);
2853
+ apply = function apply(func, thisArg) {
2854
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
2855
+ args[_key - 2] = arguments[_key];
2856
+ }
2857
+ return func.apply(thisArg, args);
2699
2858
  };
2700
2859
  }
2701
2860
  if (!construct) {
2702
- construct = function construct(Func, args) {
2861
+ construct = function construct(Func) {
2862
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2863
+ args[_key2 - 1] = arguments[_key2];
2864
+ }
2703
2865
  return new Func(...args);
2704
2866
  };
2705
2867
  }
@@ -2708,13 +2870,19 @@ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
2708
2870
  const arrayPop = unapply(Array.prototype.pop);
2709
2871
  const arrayPush = unapply(Array.prototype.push);
2710
2872
  const arraySplice = unapply(Array.prototype.splice);
2873
+ const arrayIsArray = Array.isArray;
2711
2874
  const stringToLowerCase = unapply(String.prototype.toLowerCase);
2712
2875
  const stringToString = unapply(String.prototype.toString);
2713
2876
  const stringMatch = unapply(String.prototype.match);
2714
2877
  const stringReplace = unapply(String.prototype.replace);
2715
2878
  const stringIndexOf = unapply(String.prototype.indexOf);
2716
2879
  const stringTrim = unapply(String.prototype.trim);
2880
+ const numberToString = unapply(Number.prototype.toString);
2881
+ const booleanToString = unapply(Boolean.prototype.toString);
2882
+ const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
2883
+ const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
2717
2884
  const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
2885
+ const objectToString = unapply(Object.prototype.toString);
2718
2886
  const regExpTest = unapply(RegExp.prototype.test);
2719
2887
  const typeErrorCreate = unconstruct(TypeError);
2720
2888
  /**
@@ -2725,8 +2893,11 @@ const typeErrorCreate = unconstruct(TypeError);
2725
2893
  */
2726
2894
  function unapply(func) {
2727
2895
  return function (thisArg) {
2728
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2729
- args[_key - 1] = arguments[_key];
2896
+ if (thisArg instanceof RegExp) {
2897
+ thisArg.lastIndex = 0;
2898
+ }
2899
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2900
+ args[_key3 - 1] = arguments[_key3];
2730
2901
  }
2731
2902
  return apply(func, thisArg, args);
2732
2903
  };
@@ -2737,12 +2908,12 @@ function unapply(func) {
2737
2908
  * @param func - The constructor function to be wrapped and called.
2738
2909
  * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
2739
2910
  */
2740
- function unconstruct(func) {
2911
+ function unconstruct(Func) {
2741
2912
  return function () {
2742
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2743
- args[_key2] = arguments[_key2];
2913
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2914
+ args[_key4] = arguments[_key4];
2744
2915
  }
2745
- return construct(func, args);
2916
+ return construct(Func, args);
2746
2917
  };
2747
2918
  }
2748
2919
  /**
@@ -2761,6 +2932,9 @@ function addToSet(set, array) {
2761
2932
  // Prevent prototype setters from intercepting set as a this value.
2762
2933
  setPrototypeOf(set, null);
2763
2934
  }
2935
+ if (!arrayIsArray(array)) {
2936
+ return set;
2937
+ }
2764
2938
  let l = array.length;
2765
2939
  while (l--) {
2766
2940
  let element = array[l];
@@ -2801,10 +2975,13 @@ function cleanArray(array) {
2801
2975
  */
2802
2976
  function clone(object) {
2803
2977
  const newObject = create(null);
2804
- for (const [property, value] of entries(object)) {
2978
+ for (const _ref2 of entries(object)) {
2979
+ var _ref3 = _slicedToArray(_ref2, 2);
2980
+ const property = _ref3[0];
2981
+ const value = _ref3[1];
2805
2982
  const isPropertyExist = objectHasOwnProperty(object, property);
2806
2983
  if (isPropertyExist) {
2807
- if (Array.isArray(value)) {
2984
+ if (arrayIsArray(value)) {
2808
2985
  newObject[property] = cleanArray(value);
2809
2986
  } else if (value && typeof value === 'object' && value.constructor === Object) {
2810
2987
  newObject[property] = clone(value);
@@ -2815,6 +2992,58 @@ function clone(object) {
2815
2992
  }
2816
2993
  return newObject;
2817
2994
  }
2995
+ /**
2996
+ * Convert non-node values into strings without depending on direct property access.
2997
+ *
2998
+ * @param value - The value to stringify.
2999
+ * @returns A string representation of the provided value.
3000
+ */
3001
+ function stringifyValue(value) {
3002
+ switch (typeof value) {
3003
+ case 'string':
3004
+ {
3005
+ return value;
3006
+ }
3007
+ case 'number':
3008
+ {
3009
+ return numberToString(value);
3010
+ }
3011
+ case 'boolean':
3012
+ {
3013
+ return booleanToString(value);
3014
+ }
3015
+ case 'bigint':
3016
+ {
3017
+ return bigintToString ? bigintToString(value) : '0';
3018
+ }
3019
+ case 'symbol':
3020
+ {
3021
+ return symbolToString ? symbolToString(value) : 'Symbol()';
3022
+ }
3023
+ case 'undefined':
3024
+ {
3025
+ return objectToString(value);
3026
+ }
3027
+ case 'function':
3028
+ case 'object':
3029
+ {
3030
+ if (value === null) {
3031
+ return objectToString(value);
3032
+ }
3033
+ const valueAsRecord = value;
3034
+ const valueToString = lookupGetter(valueAsRecord, 'toString');
3035
+ if (typeof valueToString === 'function') {
3036
+ const stringified = valueToString(valueAsRecord);
3037
+ return typeof stringified === 'string' ? stringified : objectToString(stringified);
3038
+ }
3039
+ return objectToString(value);
3040
+ }
3041
+ default:
3042
+ {
3043
+ return objectToString(value);
3044
+ }
3045
+ }
3046
+ }
2818
3047
  /**
2819
3048
  * This method automatically checks if the prop is function or getter and behaves accordingly.
2820
3049
  *
@@ -2840,9 +3069,17 @@ function lookupGetter(object, prop) {
2840
3069
  }
2841
3070
  return fallbackValue;
2842
3071
  }
3072
+ function isRegex(value) {
3073
+ try {
3074
+ regExpTest(value, '');
3075
+ return true;
3076
+ } catch (_unused) {
3077
+ return false;
3078
+ }
3079
+ }
2843
3080
 
2844
- const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
2845
- const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
3081
+ const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
3082
+ const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
2846
3083
  const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
2847
3084
  // List of SVG elements that are disallowed by default.
2848
3085
  // We still need to know them so that we can do namespace
@@ -2855,40 +3092,31 @@ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mgly
2855
3092
  const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
2856
3093
  const text = freeze(['#text']);
2857
3094
 
2858
- const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
2859
- const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
2860
- const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
3095
+ const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'command', 'commandfor', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns']);
3096
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
3097
+ const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lquote', 'lspace', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
2861
3098
  const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
2862
3099
 
2863
- // eslint-disable-next-line unicorn/better-regex
2864
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
2865
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
2866
- const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
3100
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
3101
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
3102
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
2867
3103
  const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
2868
3104
  const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
2869
- const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
3105
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
2870
3106
  );
2871
3107
  const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
2872
3108
  const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
2873
3109
  );
2874
3110
  const DOCTYPE_NAME = seal(/^html$/i);
2875
3111
  const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
3112
+ // Markup-significant character probes used by _sanitizeElements.
3113
+ // Shared module-level instances are safe despite the sticky /g flags:
3114
+ // unapply() resets lastIndex for RegExp receivers before every call.
3115
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
3116
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
3117
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
3118
+ const SELF_CLOSING_TAG = seal(/\/>/i);
2876
3119
 
2877
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
2878
- __proto__: null,
2879
- ARIA_ATTR: ARIA_ATTR,
2880
- ATTR_WHITESPACE: ATTR_WHITESPACE,
2881
- CUSTOM_ELEMENT: CUSTOM_ELEMENT,
2882
- DATA_ATTR: DATA_ATTR,
2883
- DOCTYPE_NAME: DOCTYPE_NAME,
2884
- ERB_EXPR: ERB_EXPR,
2885
- IS_ALLOWED_URI: IS_ALLOWED_URI,
2886
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
2887
- MUSTACHE_EXPR: MUSTACHE_EXPR,
2888
- TMPLIT_EXPR: TMPLIT_EXPR
2889
- });
2890
-
2891
- /* eslint-disable @typescript-eslint/indent */
2892
3120
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
2893
3121
  const NODE_TYPE = {
2894
3122
  element: 1,
@@ -2899,7 +3127,7 @@ const NODE_TYPE = {
2899
3127
  // Deprecated
2900
3128
  entityNode: 6,
2901
3129
  // Deprecated
2902
- progressingInstruction: 7,
3130
+ processingInstruction: 7,
2903
3131
  comment: 8,
2904
3132
  document: 9,
2905
3133
  documentType: 10,
@@ -2960,10 +3188,25 @@ const _createHooksMap = function _createHooksMap() {
2960
3188
  uponSanitizeShadowNode: []
2961
3189
  };
2962
3190
  };
3191
+ /**
3192
+ * Resolve a set-valued configuration option: a fresh set built from
3193
+ * cfg[key] when it is an own array property (seeded with a clone of
3194
+ * options.base when given, case-normalized via options.transform),
3195
+ * the fallback set otherwise.
3196
+ *
3197
+ * @param cfg the cloned, prototype-free configuration object
3198
+ * @param key the configuration property to read
3199
+ * @param fallback the set to use when the option is absent or not an array
3200
+ * @param options transform and optional base set to merge into
3201
+ * @returns the resolved set
3202
+ */
3203
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
3204
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
3205
+ };
2963
3206
  function createDOMPurify() {
2964
3207
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
2965
3208
  const DOMPurify = root => createDOMPurify(root);
2966
- DOMPurify.version = '3.2.4';
3209
+ DOMPurify.version = '3.4.11';
2967
3210
  DOMPurify.removed = [];
2968
3211
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
2969
3212
  // Not running in a browser, provide a factory function
@@ -2971,28 +3214,29 @@ function createDOMPurify() {
2971
3214
  DOMPurify.isSupported = false;
2972
3215
  return DOMPurify;
2973
3216
  }
2974
- let {
2975
- document
2976
- } = window;
3217
+ let document = window.document;
2977
3218
  const originalDocument = document;
2978
3219
  const currentScript = originalDocument.currentScript;
2979
- const {
2980
- DocumentFragment,
2981
- HTMLTemplateElement,
2982
- Node,
2983
- Element,
2984
- NodeFilter,
2985
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
2986
- HTMLFormElement,
2987
- DOMParser,
2988
- trustedTypes
2989
- } = window;
3220
+ window.DocumentFragment;
3221
+ const HTMLTemplateElement = window.HTMLTemplateElement,
3222
+ Node = window.Node,
3223
+ Element = window.Element,
3224
+ NodeFilter = window.NodeFilter,
3225
+ _window$NamedNodeMap = window.NamedNodeMap;
3226
+ _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap;
3227
+ window.HTMLFormElement;
3228
+ const DOMParser = window.DOMParser,
3229
+ trustedTypes = window.trustedTypes;
2990
3230
  const ElementPrototype = Element.prototype;
2991
3231
  const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
2992
3232
  const remove = lookupGetter(ElementPrototype, 'remove');
2993
3233
  const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
2994
3234
  const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
2995
3235
  const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
3236
+ const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
3237
+ const getAttributes = lookupGetter(ElementPrototype, 'attributes');
3238
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
3239
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
2996
3240
  // As per issue #47, the web-components registry is inherited by a
2997
3241
  // new document created via createHTMLDocument. As per the spec
2998
3242
  // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
@@ -3007,33 +3251,74 @@ function createDOMPurify() {
3007
3251
  }
3008
3252
  let trustedTypesPolicy;
3009
3253
  let emptyHTML = '';
3010
- const {
3011
- implementation,
3012
- createNodeIterator,
3013
- createDocumentFragment,
3014
- getElementsByTagName
3015
- } = document;
3016
- const {
3017
- importNode
3018
- } = originalDocument;
3254
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
3255
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
3256
+ // on duplicate policy names — and is the only policy allowed to persist
3257
+ // across configurations and survive `clearConfig()`.
3258
+ let defaultTrustedTypesPolicy;
3259
+ let defaultTrustedTypesPolicyResolved = false;
3260
+ // Tracks whether we are already inside a call to the configured Trusted Types
3261
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
3262
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
3263
+ // re-enter the policy and recurse until the stack overflows. We detect that
3264
+ // re-entry and throw a clear, actionable error instead. The guard is shared
3265
+ // across both callbacks, because either one re-entering `sanitize` triggers
3266
+ // the same unbounded recursion.
3267
+ let IN_TRUSTED_TYPES_POLICY = 0;
3268
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
3269
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
3270
+ 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.');
3271
+ }
3272
+ };
3273
+ const _createTrustedHTML = function _createTrustedHTML(html) {
3274
+ _assertNotInTrustedTypesPolicy();
3275
+ IN_TRUSTED_TYPES_POLICY++;
3276
+ try {
3277
+ return trustedTypesPolicy.createHTML(html);
3278
+ } finally {
3279
+ IN_TRUSTED_TYPES_POLICY--;
3280
+ }
3281
+ };
3282
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
3283
+ _assertNotInTrustedTypesPolicy();
3284
+ IN_TRUSTED_TYPES_POLICY++;
3285
+ try {
3286
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
3287
+ } finally {
3288
+ IN_TRUSTED_TYPES_POLICY--;
3289
+ }
3290
+ };
3291
+ // Lazily resolve (and cache) the instance's internal default policy.
3292
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
3293
+ // repeated (Trusted Types throws on duplicate names), and a failed or
3294
+ // unsupported attempt must not be retried on every parse.
3295
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
3296
+ if (!defaultTrustedTypesPolicyResolved) {
3297
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
3298
+ defaultTrustedTypesPolicyResolved = true;
3299
+ }
3300
+ return defaultTrustedTypesPolicy;
3301
+ };
3302
+ const _document = document,
3303
+ implementation = _document.implementation,
3304
+ createNodeIterator = _document.createNodeIterator,
3305
+ createDocumentFragment = _document.createDocumentFragment,
3306
+ getElementsByTagName = _document.getElementsByTagName;
3307
+ const importNode = originalDocument.importNode;
3019
3308
  let hooks = _createHooksMap();
3020
3309
  /**
3021
3310
  * Expose whether this browser supports running the full DOMPurify.
3022
3311
  */
3023
3312
  DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
3024
- const {
3025
- MUSTACHE_EXPR,
3026
- ERB_EXPR,
3027
- TMPLIT_EXPR,
3028
- DATA_ATTR,
3029
- ARIA_ATTR,
3030
- IS_SCRIPT_OR_DATA,
3031
- ATTR_WHITESPACE,
3032
- CUSTOM_ELEMENT
3033
- } = EXPRESSIONS;
3034
- let {
3035
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
3036
- } = EXPRESSIONS;
3313
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
3314
+ ERB_EXPR$1 = ERB_EXPR,
3315
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
3316
+ DATA_ATTR$1 = DATA_ATTR,
3317
+ ARIA_ATTR$1 = ARIA_ATTR,
3318
+ IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
3319
+ ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
3320
+ CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
3321
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
3037
3322
  /**
3038
3323
  * We consider the elements and attributes below to be safe. Ideally
3039
3324
  * don't add any new ones but feel free to remove unwanted ones.
@@ -3074,6 +3359,21 @@ function createDOMPurify() {
3074
3359
  let FORBID_TAGS = null;
3075
3360
  /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
3076
3361
  let FORBID_ATTR = null;
3362
+ /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
3363
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
3364
+ tagCheck: {
3365
+ writable: true,
3366
+ configurable: false,
3367
+ enumerable: true,
3368
+ value: null
3369
+ },
3370
+ attributeCheck: {
3371
+ writable: true,
3372
+ configurable: false,
3373
+ enumerable: true,
3374
+ value: null
3375
+ }
3376
+ }));
3077
3377
  /* Decide if ARIA attributes are okay */
3078
3378
  let ALLOW_ARIA_ATTR = true;
3079
3379
  /* Decide if custom data attributes are okay */
@@ -3095,6 +3395,13 @@ function createDOMPurify() {
3095
3395
  let WHOLE_DOCUMENT = false;
3096
3396
  /* Track whether config is already set on this instance of DOMPurify. */
3097
3397
  let SET_CONFIG = false;
3398
+ /* Pristine allowlist bindings captured at setConfig() time. On the
3399
+ * persistent-config path sanitize() restores the sets from these before
3400
+ * the per-walk hook clone-guard, so a hook's in-call widening cannot
3401
+ * carry across calls. Null until setConfig() is called; reset by
3402
+ * clearConfig(). */
3403
+ let SET_CONFIG_ALLOWED_TAGS = null;
3404
+ let SET_CONFIG_ALLOWED_ATTR = null;
3098
3405
  /* Decide if all elements (e.g. style, script) must be children of
3099
3406
  * document.body. By default, browsers might move them to document.head */
3100
3407
  let FORCE_BODY = false;
@@ -3137,7 +3444,17 @@ function createDOMPurify() {
3137
3444
  let USE_PROFILES = {};
3138
3445
  /* Tags to ignore content of when KEEP_CONTENT is true */
3139
3446
  let FORBID_CONTENTS = null;
3140
- 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']);
3447
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
3448
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
3449
+ // the UA (customizable <select>) — including any on* handlers — and the
3450
+ // engine re-mirrors synchronously whenever a removal changes which
3451
+ // option/selectedcontent is current, even inside DOMPurify's inert
3452
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
3453
+ // mirror target ahead of the walk, which the engine refills, looping
3454
+ // forever (DoS) and amplifying output. Dropping its content on removal
3455
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
3456
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
3457
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
3141
3458
  /* Tags that are safe for data: URIs */
3142
3459
  let DATA_URI_TAGS = null;
3143
3460
  const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
@@ -3153,8 +3470,10 @@ function createDOMPurify() {
3153
3470
  /* Allowed XHTML+XML namespaces */
3154
3471
  let ALLOWED_NAMESPACES = null;
3155
3472
  const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
3156
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
3157
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
3473
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
3474
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
3475
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
3476
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
3158
3477
  // Certain elements are allowed in both SVG and HTML
3159
3478
  // namespace. We need to specify them explicitly
3160
3479
  // so that they don't get erroneously deleted from
@@ -3196,15 +3515,33 @@ function createDOMPurify() {
3196
3515
  // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
3197
3516
  transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
3198
3517
  /* Set configuration parameters */
3199
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
3200
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
3201
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
3202
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
3203
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
3204
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
3205
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
3206
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
3207
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
3518
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
3519
+ transform: transformCaseFunc
3520
+ });
3521
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
3522
+ transform: transformCaseFunc
3523
+ });
3524
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
3525
+ transform: stringToString
3526
+ });
3527
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
3528
+ transform: transformCaseFunc,
3529
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
3530
+ });
3531
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
3532
+ transform: transformCaseFunc,
3533
+ base: DEFAULT_DATA_URI_TAGS
3534
+ });
3535
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
3536
+ transform: transformCaseFunc
3537
+ });
3538
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
3539
+ transform: transformCaseFunc
3540
+ });
3541
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
3542
+ transform: transformCaseFunc
3543
+ });
3544
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
3208
3545
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
3209
3546
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
3210
3547
  ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
@@ -3220,20 +3557,22 @@ function createDOMPurify() {
3220
3557
  SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
3221
3558
  KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
3222
3559
  IN_PLACE = cfg.IN_PLACE || false; // Default false
3223
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
3224
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
3225
- MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
3226
- HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
3227
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
3228
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
3229
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
3230
- }
3231
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
3232
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
3233
- }
3234
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
3235
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
3236
- }
3560
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
3561
+ NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
3562
+ 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
3563
+ 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
3564
+ const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
3565
+ CUSTOM_ELEMENT_HANDLING = create(null);
3566
+ if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
3567
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
3568
+ }
3569
+ if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
3570
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
3571
+ }
3572
+ if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
3573
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
3574
+ }
3575
+ seal(CUSTOM_ELEMENT_HANDLING);
3237
3576
  if (SAFE_FOR_TEMPLATES) {
3238
3577
  ALLOW_DATA_ATTR = false;
3239
3578
  }
@@ -3243,7 +3582,7 @@ function createDOMPurify() {
3243
3582
  /* Parse profile info */
3244
3583
  if (USE_PROFILES) {
3245
3584
  ALLOWED_TAGS = addToSet({}, text);
3246
- ALLOWED_ATTR = [];
3585
+ ALLOWED_ATTR = create(null);
3247
3586
  if (USE_PROFILES.html === true) {
3248
3587
  addToSet(ALLOWED_TAGS, html$1);
3249
3588
  addToSet(ALLOWED_ATTR, html);
@@ -3264,28 +3603,46 @@ function createDOMPurify() {
3264
3603
  addToSet(ALLOWED_ATTR, xml);
3265
3604
  }
3266
3605
  }
3606
+ /* Always reset function-based ADD_TAGS / ADD_ATTR checks to prevent
3607
+ * leaking across calls when switching from function to array config */
3608
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
3609
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
3267
3610
  /* Merge configuration parameters */
3268
- if (cfg.ADD_TAGS) {
3269
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
3270
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
3611
+ if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
3612
+ if (typeof cfg.ADD_TAGS === 'function') {
3613
+ EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
3614
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
3615
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
3616
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
3617
+ }
3618
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
3271
3619
  }
3272
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
3273
3620
  }
3274
- if (cfg.ADD_ATTR) {
3275
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
3276
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
3621
+ if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
3622
+ if (typeof cfg.ADD_ATTR === 'function') {
3623
+ EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
3624
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
3625
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
3626
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
3627
+ }
3628
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
3277
3629
  }
3278
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
3279
3630
  }
3280
- if (cfg.ADD_URI_SAFE_ATTR) {
3631
+ if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
3281
3632
  addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
3282
3633
  }
3283
- if (cfg.FORBID_CONTENTS) {
3634
+ if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
3284
3635
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
3285
3636
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
3286
3637
  }
3287
3638
  addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
3288
3639
  }
3640
+ if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
3641
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
3642
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
3643
+ }
3644
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
3645
+ }
3289
3646
  /* Add #text in case KEEP_CONTENT is set to true */
3290
3647
  if (KEEP_CONTENT) {
3291
3648
  ALLOWED_TAGS['#text'] = true;
@@ -3299,6 +3656,13 @@ function createDOMPurify() {
3299
3656
  addToSet(ALLOWED_TAGS, ['tbody']);
3300
3657
  delete FORBID_TAGS.tbody;
3301
3658
  }
3659
+ // Re-derive the active Trusted Types policy from this configuration on
3660
+ // every parse. The active policy must never be sticky closure state that
3661
+ // outlives the config that set it: a caller-supplied policy left in place
3662
+ // after `clearConfig()` — or after a later call that supplied none, or
3663
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
3664
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
3665
+ // See GHSA-vxr8-fq34-vvx9.
3302
3666
  if (cfg.TRUSTED_TYPES_POLICY) {
3303
3667
  if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
3304
3668
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
@@ -3306,18 +3670,45 @@ function createDOMPurify() {
3306
3670
  if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
3307
3671
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
3308
3672
  }
3309
- // Overwrite existing TrustedTypes policy.
3673
+ // A caller-supplied policy applies to this configuration only.
3674
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
3310
3675
  trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
3311
- // Sign local variables required by `sanitize`.
3312
- emptyHTML = trustedTypesPolicy.createHTML('');
3676
+ // Sign local variables required by `sanitize`. If the supplied policy's
3677
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
3678
+ // throws via the re-entrancy guard. Restore the previous policy first so
3679
+ // the instance is not left in a poisoned state. See #1422.
3680
+ try {
3681
+ emptyHTML = _createTrustedHTML('');
3682
+ } catch (error) {
3683
+ trustedTypesPolicy = previousTrustedTypesPolicy;
3684
+ throw error;
3685
+ }
3686
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
3687
+ // Explicit opt-out for this call: perform no Trusted Types signing and
3688
+ // create nothing (so a strict `trusted-types` CSP that disallows a
3689
+ // `dompurify` policy can still call `sanitize` from inside its own
3690
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
3691
+ // `null` also drops any previously retained caller policy, so it cannot
3692
+ // resurface on a later call, while still allowing the next config-less
3693
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
3694
+ trustedTypesPolicy = undefined;
3695
+ emptyHTML = '';
3313
3696
  } else {
3314
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
3697
+ // No policy supplied: keep the currently active policy if one is set — a
3698
+ // previously supplied policy is intentionally sticky across config-less
3699
+ // calls — otherwise fall back to the instance's own internal policy,
3700
+ // created at most once. (A policy supplied for a *single* call still
3701
+ // lingers by design; what must not linger is a policy whose configuration
3702
+ // has been torn down via `clearConfig()`, which restores the default.)
3315
3703
  if (trustedTypesPolicy === undefined) {
3316
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
3704
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
3317
3705
  }
3318
- // If creating the internal policy succeeded sign internal variables.
3319
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
3320
- emptyHTML = trustedTypesPolicy.createHTML('');
3706
+ // Sign internal variables only when a policy is active. A falsy policy
3707
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
3708
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
3709
+ // a non-policy and throw. See #1422.
3710
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
3711
+ emptyHTML = _createTrustedHTML('');
3321
3712
  }
3322
3713
  }
3323
3714
  // Prevent further manipulation of configuration.
@@ -3332,6 +3723,77 @@ function createDOMPurify() {
3332
3723
  * correctly. */
3333
3724
  const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
3334
3725
  const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
3726
+ /**
3727
+ * Namespace rules for an element in the SVG namespace.
3728
+ *
3729
+ * @param tagName the element's lowercase tag name
3730
+ * @param parent the (possibly simulated) parent node
3731
+ * @param parentTagName the parent's lowercase tag name
3732
+ * @returns true if a spec-compliant parser could produce this element
3733
+ */
3734
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
3735
+ // The only way to switch from HTML namespace to SVG
3736
+ // is via <svg>. If it happens via any other tag, then
3737
+ // it should be killed.
3738
+ if (parent.namespaceURI === HTML_NAMESPACE) {
3739
+ return tagName === 'svg';
3740
+ }
3741
+ // The only way to switch from MathML to SVG is via <svg>
3742
+ // if the parent is either <annotation-xml> or a MathML
3743
+ // text integration point.
3744
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
3745
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
3746
+ }
3747
+ // We only allow elements that are defined in SVG
3748
+ // spec. All others are disallowed in SVG namespace.
3749
+ return Boolean(ALL_SVG_TAGS[tagName]);
3750
+ };
3751
+ /**
3752
+ * Namespace rules for an element in the MathML namespace.
3753
+ *
3754
+ * @param tagName the element's lowercase tag name
3755
+ * @param parent the (possibly simulated) parent node
3756
+ * @param parentTagName the parent's lowercase tag name
3757
+ * @returns true if a spec-compliant parser could produce this element
3758
+ */
3759
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
3760
+ // The only way to switch from HTML namespace to MathML
3761
+ // is via <math>. If it happens via any other tag, then
3762
+ // it should be killed.
3763
+ if (parent.namespaceURI === HTML_NAMESPACE) {
3764
+ return tagName === 'math';
3765
+ }
3766
+ // The only way to switch from SVG to MathML is via
3767
+ // <math> and HTML integration points
3768
+ if (parent.namespaceURI === SVG_NAMESPACE) {
3769
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
3770
+ }
3771
+ // We only allow elements that are defined in MathML
3772
+ // spec. All others are disallowed in MathML namespace.
3773
+ return Boolean(ALL_MATHML_TAGS[tagName]);
3774
+ };
3775
+ /**
3776
+ * Namespace rules for an element in the HTML namespace.
3777
+ *
3778
+ * @param tagName the element's lowercase tag name
3779
+ * @param parent the (possibly simulated) parent node
3780
+ * @param parentTagName the parent's lowercase tag name
3781
+ * @returns true if a spec-compliant parser could produce this element
3782
+ */
3783
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
3784
+ // The only way to switch from SVG to HTML is via
3785
+ // HTML integration points, and from MathML to HTML
3786
+ // is via MathML text integration points
3787
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
3788
+ return false;
3789
+ }
3790
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
3791
+ return false;
3792
+ }
3793
+ // We disallow tags that are specific for MathML
3794
+ // or SVG and should never appear in HTML namespace
3795
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
3796
+ };
3335
3797
  /**
3336
3798
  * @param element a DOM element whose namespace is being checked
3337
3799
  * @returns Return false if the element has a
@@ -3354,51 +3816,13 @@ function createDOMPurify() {
3354
3816
  return false;
3355
3817
  }
3356
3818
  if (element.namespaceURI === SVG_NAMESPACE) {
3357
- // The only way to switch from HTML namespace to SVG
3358
- // is via <svg>. If it happens via any other tag, then
3359
- // it should be killed.
3360
- if (parent.namespaceURI === HTML_NAMESPACE) {
3361
- return tagName === 'svg';
3362
- }
3363
- // The only way to switch from MathML to SVG is via`
3364
- // svg if parent is either <annotation-xml> or MathML
3365
- // text integration points.
3366
- if (parent.namespaceURI === MATHML_NAMESPACE) {
3367
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
3368
- }
3369
- // We only allow elements that are defined in SVG
3370
- // spec. All others are disallowed in SVG namespace.
3371
- return Boolean(ALL_SVG_TAGS[tagName]);
3819
+ return _checkSvgNamespace(tagName, parent, parentTagName);
3372
3820
  }
3373
3821
  if (element.namespaceURI === MATHML_NAMESPACE) {
3374
- // The only way to switch from HTML namespace to MathML
3375
- // is via <math>. If it happens via any other tag, then
3376
- // it should be killed.
3377
- if (parent.namespaceURI === HTML_NAMESPACE) {
3378
- return tagName === 'math';
3379
- }
3380
- // The only way to switch from SVG to MathML is via
3381
- // <math> and HTML integration points
3382
- if (parent.namespaceURI === SVG_NAMESPACE) {
3383
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
3384
- }
3385
- // We only allow elements that are defined in MathML
3386
- // spec. All others are disallowed in MathML namespace.
3387
- return Boolean(ALL_MATHML_TAGS[tagName]);
3822
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
3388
3823
  }
3389
3824
  if (element.namespaceURI === HTML_NAMESPACE) {
3390
- // The only way to switch from SVG to HTML is via
3391
- // HTML integration points, and from MathML to HTML
3392
- // is via MathML text integration points
3393
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
3394
- return false;
3395
- }
3396
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
3397
- return false;
3398
- }
3399
- // We disallow tags that are specific for MathML
3400
- // or SVG and should never appear in HTML namespace
3401
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
3825
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
3402
3826
  }
3403
3827
  // For XHTML and XML documents that support custom namespaces
3404
3828
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
@@ -3423,7 +3847,74 @@ function createDOMPurify() {
3423
3847
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
3424
3848
  getParentNode(node).removeChild(node);
3425
3849
  } catch (_) {
3850
+ /* The normal detach failed — this is reached for a parentless node
3851
+ (getParentNode() is null, so .removeChild throws). Element.prototype
3852
+ .remove() is itself a spec no-op on a parentless node, so a recorded
3853
+ "removal" would otherwise hand the caller back an intact,
3854
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
3855
+ the style-with-element-child rule decided to kill). Fail closed by
3856
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
3857
+ rather than trying to "neutralize" the node via its own methods.
3858
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
3859
+ on the node, both of which a <form> root can clobber via a named child
3860
+ (and _isClobbered does not even probe getAttributeNames), so the
3861
+ neutralize step could itself be silently defeated, leaving the payload
3862
+ intact. A throw touches only the cached, clobber-safe remove() and
3863
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
3864
+ to every root-kill reason. REPORT-3.
3865
+ This lives inside the catch, so it never fires for a normally-removed
3866
+ in-tree node: those have a parent, removeChild() succeeds, and the
3867
+ catch is not entered. Only a kept (parentless) root reaches here. */
3426
3868
  remove(node);
3869
+ if (!getParentNode(node)) {
3870
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
3871
+ }
3872
+ }
3873
+ };
3874
+ /**
3875
+ * _neutralizeRoot
3876
+ *
3877
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
3878
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
3879
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
3880
+ * parentless guard throws, or any other re-entrant engine mutation — would
3881
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
3882
+ * after the abort point still carrying its handlers. There is no safe way
3883
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
3884
+ * remove every child and every attribute, then let the caller's catch see
3885
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
3886
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
3887
+ *
3888
+ * @param root the in-place root to empty
3889
+ */
3890
+ const _neutralizeRoot = function _neutralizeRoot(root) {
3891
+ const childNodes = getChildNodes(root);
3892
+ if (childNodes) {
3893
+ const snapshot = [];
3894
+ arrayForEach(childNodes, child => {
3895
+ arrayPush(snapshot, child);
3896
+ });
3897
+ arrayForEach(snapshot, child => {
3898
+ try {
3899
+ remove(child);
3900
+ } catch (_) {
3901
+ /* Best-effort teardown; a still-attached child is handled below */
3902
+ }
3903
+ });
3904
+ }
3905
+ const attributes = getAttributes(root);
3906
+ if (attributes) {
3907
+ for (let i = attributes.length - 1; i >= 0; --i) {
3908
+ const attribute = attributes[i];
3909
+ const name = attribute && attribute.name;
3910
+ if (typeof name === 'string') {
3911
+ try {
3912
+ root.removeAttribute(name);
3913
+ } catch (_) {
3914
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
3915
+ }
3916
+ }
3917
+ }
3427
3918
  }
3428
3919
  };
3429
3920
  /**
@@ -3458,6 +3949,72 @@ function createDOMPurify() {
3458
3949
  }
3459
3950
  }
3460
3951
  };
3952
+ /**
3953
+ * _stripDisallowedAttributes
3954
+ *
3955
+ * Removes every attribute the active configuration does not allow from a
3956
+ * single element, using the same allowlist as the main attribute pass (so
3957
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
3958
+ * neutralise nodes that are being discarded from an in-place tree.
3959
+ *
3960
+ * @param element the element to strip
3961
+ */
3962
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
3963
+ const attributes = getAttributes(element);
3964
+ if (!attributes) {
3965
+ return;
3966
+ }
3967
+ for (let i = attributes.length - 1; i >= 0; --i) {
3968
+ const attribute = attributes[i];
3969
+ const name = attribute && attribute.name;
3970
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
3971
+ continue;
3972
+ }
3973
+ try {
3974
+ element.removeAttribute(name);
3975
+ } catch (_) {
3976
+ /* Clobbered removeAttribute on a doomed node — ignore */
3977
+ }
3978
+ }
3979
+ };
3980
+ /**
3981
+ * _neutralizeSubtree
3982
+ *
3983
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
3984
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
3985
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
3986
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
3987
+ * those dropped nodes are detached from the caller's LIVE tree but a
3988
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
3989
+ * loading) keeps its queued resource event, which fires in page scope after
3990
+ * sanitize returns. This walks a removed subtree and strips every attribute
3991
+ * the active configuration does not allow — so `on*` handlers are cancelled
3992
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
3993
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
3994
+ * queued event can fire. Hook-free by design: these nodes leave the output,
3995
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
3996
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
3997
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
3998
+ * the `<img>`, are reached and scrubbed).
3999
+ *
4000
+ * @param root the root of a removed subtree to neutralise
4001
+ */
4002
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
4003
+ const stack = [root];
4004
+ while (stack.length > 0) {
4005
+ const node = stack.pop();
4006
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
4007
+ if (nodeType === NODE_TYPE.element) {
4008
+ _stripDisallowedAttributes(node);
4009
+ }
4010
+ const childNodes = getChildNodes(node);
4011
+ if (childNodes) {
4012
+ for (let i = childNodes.length - 1; i >= 0; --i) {
4013
+ stack.push(childNodes[i]);
4014
+ }
4015
+ }
4016
+ }
4017
+ };
3461
4018
  /**
3462
4019
  * _initDocument
3463
4020
  *
@@ -3479,7 +4036,7 @@ function createDOMPurify() {
3479
4036
  // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
3480
4037
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
3481
4038
  }
3482
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
4039
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
3483
4040
  /*
3484
4041
  * Use the DOMParser API by default, fallback later if needs be
3485
4042
  * DOMParser not work for svg when has multiple root element.
@@ -3519,29 +4076,254 @@ function createDOMPurify() {
3519
4076
  // eslint-disable-next-line no-bitwise
3520
4077
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
3521
4078
  };
4079
+ /**
4080
+ * Replace template expression syntax (mustache, ERB, template
4081
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
4082
+ * sites. Order matters: mustache, then ERB, then template literal.
4083
+ *
4084
+ * @param value the string to scrub
4085
+ * @returns the scrubbed string
4086
+ */
4087
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
4088
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
4089
+ value = stringReplace(value, ERB_EXPR$1, ' ');
4090
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
4091
+ return value;
4092
+ };
4093
+ /**
4094
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
4095
+ * character data of an element subtree. Used as the final safety net for
4096
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
4097
+ * which only form after text-node normalization (e.g. fragments split across
4098
+ * stripped elements) cannot survive into a template-evaluating framework.
4099
+ *
4100
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
4101
+ * in place rather than round-tripping through innerHTML. This preserves
4102
+ * descendant node references (important for IN_PLACE callers), avoids a
4103
+ * serialize/reparse cycle, and reads literal character data — which means
4104
+ * `<%...%>` in text content matches the ERB regex against its real bytes
4105
+ * instead of the HTML-entity-escaped form innerHTML would produce.
4106
+ *
4107
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
4108
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
4109
+ *
4110
+ * @param node The root element whose character data should be scrubbed.
4111
+ */
4112
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
4113
+ var _node$querySelectorAl;
4114
+ node.normalize();
4115
+ const walker = createNodeIterator.call(node.ownerDocument || node, node,
4116
+ // eslint-disable-next-line no-bitwise
4117
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
4118
+ let currentNode = walker.nextNode();
4119
+ while (currentNode) {
4120
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
4121
+ currentNode = walker.nextNode();
4122
+ }
4123
+ // NodeIterator does not descend into <template>.content per the DOM spec,
4124
+ // so we must explicitly recurse into each template's content fragment,
4125
+ // mirroring the approach used by _sanitizeShadowDOM.
4126
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
4127
+ if (templates) {
4128
+ arrayForEach(templates, tmpl => {
4129
+ if (_isDocumentFragment(tmpl.content)) {
4130
+ _scrubTemplateExpressions2(tmpl.content);
4131
+ }
4132
+ });
4133
+ }
4134
+ };
3522
4135
  /**
3523
4136
  * _isClobbered
3524
4137
  *
4138
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
4139
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
4140
+ * `name` attribute matching a prototype property shadows that property
4141
+ * on direct reads. We use this check at the IN_PLACE entry-point and
4142
+ * during attribute sanitization to refuse clobbered forms.
4143
+ *
3525
4144
  * @param element element to check for clobbering attacks
3526
4145
  * @return true if clobbered, false if safe
3527
4146
  */
3528
4147
  const _isClobbered = function _isClobbered(element) {
3529
- return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
4148
+ // Realm-independent tag-name probe. If we can't determine the tag
4149
+ // name at all, we can't reason about clobbering — return false
4150
+ // (the caller's other defences still apply).
4151
+ const realTagName = getNodeName ? getNodeName(element) : null;
4152
+ if (typeof realTagName !== 'string') {
4153
+ return false;
4154
+ }
4155
+ if (transformCaseFunc(realTagName) !== 'form') {
4156
+ return false;
4157
+ }
4158
+ return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
4159
+ // Realm-safe NamedNodeMap detection: equality against the cached
4160
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
4161
+ // makes the direct read diverge from the cached read; a clean form
4162
+ // (same-realm OR foreign-realm) has both reads pointing at the same
4163
+ // canonical NamedNodeMap.
4164
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
4165
+ // NodeType clobbering probe. Cached Node.prototype.nodeType getter
4166
+ // returns the integer 1 for any Element regardless of realm; direct
4167
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
4168
+ // the named child element. Cheap addition — nodeType is read from
4169
+ // an internal slot, no serialization cost — and removes a residual
4170
+ // clobbering surface used by several mXSS / PI / comment branches
4171
+ // in _sanitizeElements that compare currentNode.nodeType directly.
4172
+ element.nodeType !== getNodeType(element) ||
4173
+ // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
4174
+ // "childNodes" shadows the prototype getter. Direct reads of
4175
+ // form.childNodes from a clobbered form return the named child
4176
+ // instead of the real NodeList, so any walk that reads it directly
4177
+ // skips the form's real children. Compare the direct read to the
4178
+ // cached Node.prototype getter — when the form's named-property
4179
+ // getter intercepts the read, the two values differ and we flag
4180
+ // the form. This catches every clobbering child type (input,
4181
+ // select, etc.) regardless of whether the named child happens to
4182
+ // carry a numeric .length, which a typeof-based probe would miss
4183
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
4184
+ element.childNodes !== getChildNodes(element);
4185
+ };
4186
+ /**
4187
+ * Checks whether the given value is a DocumentFragment from any realm.
4188
+ *
4189
+ * The realm-independent replacement reads `nodeType` through the cached
4190
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
4191
+ * constant (11). nodeType is a numeric value resolved from the node's
4192
+ * internal slot, identical across realms for the same kind of node.
4193
+ *
4194
+ * @param value object to check
4195
+ * @return true if value is a DocumentFragment-shaped node from any realm
4196
+ */
4197
+ const _isDocumentFragment = function _isDocumentFragment(value) {
4198
+ if (!getNodeType || typeof value !== 'object' || value === null) {
4199
+ return false;
4200
+ }
4201
+ try {
4202
+ return getNodeType(value) === NODE_TYPE.documentFragment;
4203
+ } catch (_) {
4204
+ return false;
4205
+ }
3530
4206
  };
3531
4207
  /**
3532
- * Checks whether the given object is a DOM node.
4208
+ * Checks whether the given object is a DOM node, including nodes that
4209
+ * originate from a different window/realm (e.g. an iframe's
4210
+ * contentDocument). The previous `value instanceof Node` check was
4211
+ * realm-bound: nodes from a different window failed it, causing
4212
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
4213
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
3533
4214
  *
3534
4215
  * @param value object to check whether it's a DOM node
3535
- * @return true is object is a DOM node
4216
+ * @return true if value is a DOM node from any realm
3536
4217
  */
3537
4218
  const _isNode = function _isNode(value) {
3538
- return typeof Node === 'function' && value instanceof Node;
4219
+ if (!getNodeType || typeof value !== 'object' || value === null) {
4220
+ return false;
4221
+ }
4222
+ try {
4223
+ return typeof getNodeType(value) === 'number';
4224
+ } catch (_) {
4225
+ return false;
4226
+ }
3539
4227
  };
3540
4228
  function _executeHooks(hooks, currentNode, data) {
4229
+ if (hooks.length === 0) {
4230
+ return;
4231
+ }
3541
4232
  arrayForEach(hooks, hook => {
3542
4233
  hook.call(DOMPurify, currentNode, data, CONFIG);
3543
4234
  });
3544
4235
  }
4236
+ /**
4237
+ * Structural-threat checks that condemn a node regardless of the
4238
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
4239
+ * processing instructions, markup-bearing comments. Pure predicate;
4240
+ * the caller removes. Check order is load-bearing.
4241
+ *
4242
+ * @param currentNode the node to inspect
4243
+ * @param tagName the node's transformCaseFunc'd tag name
4244
+ * @return true if the node must be removed
4245
+ */
4246
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
4247
+ /* Detect mXSS attempts abusing namespace confusion */
4248
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
4249
+ return true;
4250
+ }
4251
+ /* Remove risky CSS construction leading to mXSS */
4252
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
4253
+ return true;
4254
+ }
4255
+ /* Remove any occurrence of processing instructions */
4256
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
4257
+ return true;
4258
+ }
4259
+ /* Remove any kind of possibly harmful comments */
4260
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
4261
+ return true;
4262
+ }
4263
+ return false;
4264
+ };
4265
+ /**
4266
+ * Handle a node whose tag is forbidden or not allowlisted: keep
4267
+ * allowed custom elements (false return exits _sanitizeElements
4268
+ * early - namespace/fallback checks and the afterSanitizeElements
4269
+ * hook are intentionally skipped for kept custom elements), else
4270
+ * hoist content per KEEP_CONTENT and remove.
4271
+ *
4272
+ * @param currentNode the disallowed node
4273
+ * @param tagName the node's transformCaseFunc'd tag name
4274
+ * @return true if the node was removed, false if kept
4275
+ */
4276
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
4277
+ /* Check if we have a custom element to handle */
4278
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
4279
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
4280
+ return false;
4281
+ }
4282
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
4283
+ return false;
4284
+ }
4285
+ }
4286
+ /* Keep content except for bad-listed elements.
4287
+ Use the cached prototype getters exclusively — the previous code
4288
+ had `|| currentNode.parentNode` / `|| currentNode.childNodes`
4289
+ fallbacks, but the cached getters always return the canonical
4290
+ value (or null for a real parent-less node), so the fallback
4291
+ path was dead in safe cases and a clobbering surface in unsafe
4292
+ ones. Falsy cached results stay falsy; the `if (childNodes &&
4293
+ parentNode)` check already gates correctly. */
4294
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
4295
+ const parentNode = getParentNode(currentNode);
4296
+ const childNodes = getChildNodes(currentNode);
4297
+ if (childNodes && parentNode) {
4298
+ const childCount = childNodes.length;
4299
+ /* In-place: hoist the *original* children so the iterator visits
4300
+ and sanitises them through the same allowlist pass as every other
4301
+ node. The caller built the tree in the live document, so the
4302
+ originals carry already-queued resource events (`<img onerror>`,
4303
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
4304
+ those originals detached but still armed, firing in page scope
4305
+ while the returned tree looked clean. Moving is safe in-place: the
4306
+ root is pre-validated as an allowed tag and so is never the node
4307
+ being removed, which keeps `parentNode` inside the iterator root
4308
+ and the relocated child inside the serialised tree.
4309
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
4310
+ at — and the result serialised from — `body`, so a restrictive
4311
+ ALLOWED_TAGS that removes `body` itself must leave its content in
4312
+ place, which only cloning does; and those paths parse into an
4313
+ inert document, so their discarded originals never had a queued
4314
+ event to neutralise.
4315
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
4316
+ valid whether we move (drops the trailing entry) or clone (leaves
4317
+ the list intact). */
4318
+ for (let i = childCount - 1; i >= 0; --i) {
4319
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
4320
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
4321
+ }
4322
+ }
4323
+ }
4324
+ _forceRemove(currentNode);
4325
+ return true;
4326
+ };
3545
4327
  /**
3546
4328
  * _sanitizeElements
3547
4329
  *
@@ -3552,7 +4334,6 @@ function createDOMPurify() {
3552
4334
  * @return true if node was killed, false if left alive
3553
4335
  */
3554
4336
  const _sanitizeElements = function _sanitizeElements(currentNode) {
3555
- let content = null;
3556
4337
  /* Execute a hook if present */
3557
4338
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
3558
4339
  /* Check if element is clobbered or can clobber */
@@ -3561,71 +4342,41 @@ function createDOMPurify() {
3561
4342
  return true;
3562
4343
  }
3563
4344
  /* Now let's check the element's type and name */
3564
- const tagName = transformCaseFunc(currentNode.nodeName);
4345
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
3565
4346
  /* Execute a hook if present */
3566
4347
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
3567
4348
  tagName,
3568
4349
  allowedTags: ALLOWED_TAGS
3569
4350
  });
3570
- /* Detect mXSS attempts abusing namespace confusion */
3571
- if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
3572
- _forceRemove(currentNode);
3573
- return true;
3574
- }
3575
- /* Remove any occurrence of processing instructions */
3576
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
3577
- _forceRemove(currentNode);
3578
- return true;
3579
- }
3580
- /* Remove any kind of possibly harmful comments */
3581
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
4351
+ /* Remove mXSS vectors, processing instructions and risky comments */
4352
+ if (_isUnsafeNode(currentNode, tagName)) {
3582
4353
  _forceRemove(currentNode);
3583
4354
  return true;
3584
4355
  }
3585
4356
  /* Remove element if anything forbids its presence */
3586
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
3587
- /* Check if we have a custom element to handle */
3588
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
3589
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
3590
- return false;
3591
- }
3592
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
3593
- return false;
3594
- }
3595
- }
3596
- /* Keep content except for bad-listed elements */
3597
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
3598
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
3599
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
3600
- if (childNodes && parentNode) {
3601
- const childCount = childNodes.length;
3602
- for (let i = childCount - 1; i >= 0; --i) {
3603
- const childClone = cloneNode(childNodes[i], true);
3604
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
3605
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
3606
- }
3607
- }
3608
- }
3609
- _forceRemove(currentNode);
3610
- return true;
3611
- }
3612
- /* Check whether element has a valid namespace */
3613
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
4357
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
4358
+ return _sanitizeDisallowedNode(currentNode, tagName);
4359
+ }
4360
+ /* Check whether element has a valid namespace.
4361
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
4362
+ nodeType getter rather than `instanceof Element`, which is realm-
4363
+ bound and short-circuits to false for any node minted in a different
4364
+ realm — letting a foreign-realm element with a forbidden namespace
4365
+ slip past the namespace check entirely. */
4366
+ const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
4367
+ if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
3614
4368
  _forceRemove(currentNode);
3615
4369
  return true;
3616
4370
  }
3617
4371
  /* Make sure that older browsers don't get fallback-tag mXSS */
3618
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
4372
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
3619
4373
  _forceRemove(currentNode);
3620
4374
  return true;
3621
4375
  }
3622
4376
  /* Sanitize element content to be template-safe */
3623
4377
  if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
3624
4378
  /* Get the element's text content */
3625
- content = currentNode.textContent;
3626
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
3627
- content = stringReplace(content, expr, ' ');
3628
- });
4379
+ const content = _stripTemplateExpressions(currentNode.textContent);
3629
4380
  if (currentNode.textContent !== content) {
3630
4381
  arrayPush(DOMPurify.removed, {
3631
4382
  element: currentNode.cloneNode()
@@ -3647,31 +4398,40 @@ function createDOMPurify() {
3647
4398
  */
3648
4399
  // eslint-disable-next-line complexity
3649
4400
  const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
4401
+ /* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
4402
+ if (FORBID_ATTR[lcName]) {
4403
+ return false;
4404
+ }
3650
4405
  /* Make sure attribute cannot clobber */
3651
4406
  if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
3652
4407
  return false;
3653
4408
  }
4409
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
3654
4410
  /* Allow valid data-* attributes: At least one character after "-"
3655
4411
  (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
3656
4412
  XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
3657
4413
  We don't need to check the value; it's always URI safe. */
3658
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
4414
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
3659
4415
  if (
3660
4416
  // First condition does a very basic check if a) it's basically a valid custom element tagname AND
3661
4417
  // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
3662
4418
  // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
3663
- _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) ||
4419
+ _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||
3664
4420
  // Alternative, second condition checks if it's an `is`-attribute, AND
3665
4421
  // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
3666
4422
  lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
3667
4423
  return false;
3668
4424
  }
3669
4425
  /* Check value is safe. First, is attr inert? If so, is safe */
3670
- } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
4426
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if (value) {
3671
4427
  return false;
3672
4428
  } else ;
3673
4429
  return true;
3674
4430
  };
4431
+ /* Names the HTML spec reserves from valid-custom-element-name; these must
4432
+ * never be treated as basic custom elements even when a permissive
4433
+ * CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
4434
+ const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, ['annotation-xml', 'color-profile', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'missing-glyph']);
3675
4435
  /**
3676
4436
  * _isBasicCustomElement
3677
4437
  * checks if at least one dash is included in tagName, and it's not the first char
@@ -3681,7 +4441,64 @@ function createDOMPurify() {
3681
4441
  * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
3682
4442
  */
3683
4443
  const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
3684
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
4444
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
4445
+ };
4446
+ /**
4447
+ * Wrap an attribute value in the matching Trusted Types object when
4448
+ * the active policy requires it. Namespaced attributes pass through
4449
+ * unchanged (no TT support yet, see
4450
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
4451
+ *
4452
+ * @param lcTag lowercase tag name of the containing element
4453
+ * @param lcName lowercase attribute name
4454
+ * @param namespaceURI the attribute's namespace, if any
4455
+ * @param value the attribute value to wrap
4456
+ * @return the value, wrapped when Trusted Types demand it
4457
+ */
4458
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
4459
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
4460
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
4461
+ case 'TrustedHTML':
4462
+ {
4463
+ return _createTrustedHTML(value);
4464
+ }
4465
+ case 'TrustedScriptURL':
4466
+ {
4467
+ return _createTrustedScriptURL(value);
4468
+ }
4469
+ }
4470
+ }
4471
+ return value;
4472
+ };
4473
+ /**
4474
+ * Write a modified attribute value back onto the element. On
4475
+ * success, re-probe for clobbering introduced by the new value and
4476
+ * remove the element when found; otherwise pop the removal entry
4477
+ * recorded by the earlier _removeAttribute (long-standing pairing
4478
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
4479
+ * failure, remove the attribute instead.
4480
+ *
4481
+ * @param currentNode the element carrying the attribute
4482
+ * @param name the attribute name as present on the element
4483
+ * @param namespaceURI the attribute's namespace, if any
4484
+ * @param value the new attribute value
4485
+ */
4486
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
4487
+ try {
4488
+ if (namespaceURI) {
4489
+ currentNode.setAttributeNS(namespaceURI, name, value);
4490
+ } else {
4491
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
4492
+ currentNode.setAttribute(name, value);
4493
+ }
4494
+ if (_isClobbered(currentNode)) {
4495
+ _forceRemove(currentNode);
4496
+ } else {
4497
+ arrayPop(DOMPurify.removed);
4498
+ }
4499
+ } catch (_) {
4500
+ _removeAttribute(name, currentNode);
4501
+ }
3685
4502
  };
3686
4503
  /**
3687
4504
  * _sanitizeAttributes
@@ -3696,9 +4513,7 @@ function createDOMPurify() {
3696
4513
  const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
3697
4514
  /* Execute a hook if present */
3698
4515
  _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
3699
- const {
3700
- attributes
3701
- } = currentNode;
4516
+ const attributes = currentNode.attributes;
3702
4517
  /* Check if we have attributes; if not we might have a text node */
3703
4518
  if (!attributes || _isClobbered(currentNode)) {
3704
4519
  return;
@@ -3711,16 +4526,16 @@ function createDOMPurify() {
3711
4526
  forceKeepAttr: undefined
3712
4527
  };
3713
4528
  let l = attributes.length;
4529
+ const lcTag = transformCaseFunc(currentNode.nodeName);
3714
4530
  /* Go backwards over all attributes; safely remove bad ones */
3715
4531
  while (l--) {
3716
4532
  const attr = attributes[l];
3717
- const {
3718
- name,
3719
- namespaceURI,
3720
- value: attrValue
3721
- } = attr;
4533
+ const name = attr.name,
4534
+ namespaceURI = attr.namespaceURI,
4535
+ attrValue = attr.value;
3722
4536
  const lcName = transformCaseFunc(name);
3723
- let value = name === 'value' ? attrValue : stringTrim(attrValue);
4537
+ const initValue = attrValue;
4538
+ let value = name === 'value' ? initValue : stringTrim(initValue);
3724
4539
  /* Execute a hook if present */
3725
4540
  hookEvent.attrName = lcName;
3726
4541
  hookEvent.attrValue = value;
@@ -3731,74 +4546,53 @@ function createDOMPurify() {
3731
4546
  /* Full DOM Clobbering protection via namespace isolation,
3732
4547
  * Prefix id and name attributes with `user-content-`
3733
4548
  */
3734
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
4549
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
3735
4550
  // Remove the attribute with this value
3736
4551
  _removeAttribute(name, currentNode);
3737
4552
  // Prefix the value and later re-create the attribute with the sanitized value
3738
4553
  value = SANITIZE_NAMED_PROPS_PREFIX + value;
3739
4554
  }
4555
+ // Else: already prefixed, leave the attribute alone — the prefix is
4556
+ // itself the clobbering protection, and re-applying it is incorrect.
3740
4557
  /* Work around a security issue with comments inside attributes */
3741
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
4558
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
3742
4559
  _removeAttribute(name, currentNode);
3743
4560
  continue;
3744
4561
  }
3745
- /* Did the hooks approve of the attribute? */
4562
+ /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
4563
+ if (lcName === 'attributename' && stringMatch(value, 'href')) {
4564
+ _removeAttribute(name, currentNode);
4565
+ continue;
4566
+ }
4567
+ /* Did the hooks force-keep the attribute? */
3746
4568
  if (hookEvent.forceKeepAttr) {
3747
4569
  continue;
3748
4570
  }
3749
- /* Remove attribute */
3750
- _removeAttribute(name, currentNode);
3751
4571
  /* Did the hooks approve of the attribute? */
3752
4572
  if (!hookEvent.keepAttr) {
4573
+ _removeAttribute(name, currentNode);
3753
4574
  continue;
3754
4575
  }
3755
4576
  /* Work around a security issue in jQuery 3.0 */
3756
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
4577
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
3757
4578
  _removeAttribute(name, currentNode);
3758
4579
  continue;
3759
4580
  }
3760
4581
  /* Sanitize attribute content to be template-safe */
3761
4582
  if (SAFE_FOR_TEMPLATES) {
3762
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
3763
- value = stringReplace(value, expr, ' ');
3764
- });
4583
+ value = _stripTemplateExpressions(value);
3765
4584
  }
3766
4585
  /* Is `value` valid for this attribute? */
3767
- const lcTag = transformCaseFunc(currentNode.nodeName);
3768
4586
  if (!_isValidAttribute(lcTag, lcName, value)) {
4587
+ _removeAttribute(name, currentNode);
3769
4588
  continue;
3770
4589
  }
3771
4590
  /* Handle attributes that require Trusted Types */
3772
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
3773
- if (namespaceURI) ; else {
3774
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
3775
- case 'TrustedHTML':
3776
- {
3777
- value = trustedTypesPolicy.createHTML(value);
3778
- break;
3779
- }
3780
- case 'TrustedScriptURL':
3781
- {
3782
- value = trustedTypesPolicy.createScriptURL(value);
3783
- break;
3784
- }
3785
- }
3786
- }
3787
- }
4591
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
3788
4592
  /* Handle invalid data-* attribute set by try-catching it */
3789
- try {
3790
- if (namespaceURI) {
3791
- currentNode.setAttributeNS(namespaceURI, name, value);
3792
- } else {
3793
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
3794
- currentNode.setAttribute(name, value);
3795
- }
3796
- if (_isClobbered(currentNode)) {
3797
- _forceRemove(currentNode);
3798
- } else {
3799
- arrayPop(DOMPurify.removed);
3800
- }
3801
- } catch (_) {}
4593
+ if (value !== initValue) {
4594
+ _setAttributeValue(currentNode, name, namespaceURI, value);
4595
+ }
3802
4596
  }
3803
4597
  /* Execute a hook if present */
3804
4598
  _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
@@ -3808,7 +4602,7 @@ function createDOMPurify() {
3808
4602
  *
3809
4603
  * @param fragment to iterate over recursively
3810
4604
  */
3811
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
4605
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
3812
4606
  let shadowNode = null;
3813
4607
  const shadowIterator = _createNodeIterator(fragment);
3814
4608
  /* Execute a hook if present */
@@ -3820,14 +4614,133 @@ function createDOMPurify() {
3820
4614
  _sanitizeElements(shadowNode);
3821
4615
  /* Check attributes next */
3822
4616
  _sanitizeAttributes(shadowNode);
3823
- /* Deep shadow DOM detected */
3824
- if (shadowNode.content instanceof DocumentFragment) {
3825
- _sanitizeShadowDOM(shadowNode.content);
4617
+ /* Deep shadow DOM detected.
4618
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
4619
+ DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
4620
+ recurse into <template>.content from foreign realms too. */
4621
+ if (_isDocumentFragment(shadowNode.content)) {
4622
+ _sanitizeShadowDOM2(shadowNode.content);
4623
+ }
4624
+ /* An element iterated here may itself host an attached
4625
+ shadow root. The default NodeIterator does not enter shadow
4626
+ trees, so a shadow root nested inside template.content was
4627
+ previously reached by no walk at all (the pre-pass at
4628
+ _sanitizeAttachedShadowRoots descends via childNodes, which
4629
+ doesn't enter template.content; the template-content recursion
4630
+ above iterates the content but never inspected shadowRoot).
4631
+ Walk it explicitly. The nodeType guard avoids reading
4632
+ shadowRoot off text / comment / CDATA / PI nodes that the
4633
+ iterator also surfaces. */
4634
+ const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
4635
+ if (shadowNodeType === NODE_TYPE.element) {
4636
+ const innerSr = getShadowRoot(shadowNode);
4637
+ if (_isDocumentFragment(innerSr)) {
4638
+ _sanitizeAttachedShadowRoots(innerSr);
4639
+ _sanitizeShadowDOM2(innerSr);
4640
+ }
3826
4641
  }
3827
4642
  }
3828
4643
  /* Execute a hook if present */
3829
4644
  _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
3830
4645
  };
4646
+ /**
4647
+ * _sanitizeAttachedShadowRoots
4648
+ *
4649
+ * Walks `root` and feeds every attached shadow root we encounter into
4650
+ * the existing _sanitizeShadowDOM pipeline. The default node iterator
4651
+ * does not descend into shadow trees, so nodes inside an attached
4652
+ * shadow root would otherwise be skipped entirely.
4653
+ *
4654
+ * Two real input paths put attached shadow roots in front of us:
4655
+ * 1. IN_PLACE on a DOM node that already has shadow roots attached.
4656
+ * 2. DOM-node input where importNode(dirty, true) deep-clones the
4657
+ * shadow root because it was created with `clonable: true`.
4658
+ *
4659
+ * This pass runs once, up front, so the main iteration loop (and the
4660
+ * existing _sanitizeShadowDOM template-content recursion) stay
4661
+ * untouched — string-input paths are not affected.
4662
+ *
4663
+ * @param root the subtree root to walk for attached shadow roots
4664
+ */
4665
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
4666
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
4667
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
4668
+ built straight into the DOM — the IN_PLACE surface) deeper than the JS
4669
+ call-stack budget would otherwise overflow native recursion here and
4670
+ throw at the IN_PLACE entry pre-pass, before a single node is
4671
+ sanitized, leaving the caller's live tree untouched (fail-open). See
4672
+ campaign-3 F4. A heap stack keeps depth off the call stack.
4673
+ Each work item is either a node to descend into, or a deferred
4674
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
4675
+ form preserves the original post-order discipline: a shadow root's
4676
+ nested shadow roots are discovered before the outer shadow is
4677
+ sanitized (which may remove hosts). Pushes are in reverse of the
4678
+ desired processing order (LIFO): template content, then children, then
4679
+ the shadow-sanitize, then the shadow walk — so the order matches the
4680
+ previous recursion exactly. */
4681
+ const stack = [{
4682
+ node: root,
4683
+ shadow: null
4684
+ }];
4685
+ while (stack.length > 0) {
4686
+ const item = stack.pop();
4687
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
4688
+ if (item.shadow) {
4689
+ _sanitizeShadowDOM2(item.shadow);
4690
+ continue;
4691
+ }
4692
+ const node = item.node;
4693
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
4694
+ const isElement = nodeType === NODE_TYPE.element;
4695
+ /* (pushed last → processed first) Children, snapshotted in reverse so
4696
+ the first child is processed first. Snapshotting matters because a
4697
+ hook may detach siblings mid-walk. */
4698
+ const childNodes = getChildNodes(node);
4699
+ if (childNodes) {
4700
+ for (let i = childNodes.length - 1; i >= 0; --i) {
4701
+ stack.push({
4702
+ node: childNodes[i],
4703
+ shadow: null
4704
+ });
4705
+ }
4706
+ }
4707
+ /* (pushed before children → processed after them, matching the old
4708
+ "template content last" order) When the node is a <template>,
4709
+ descend into its content. */
4710
+ if (isElement) {
4711
+ const rootName = getNodeName ? getNodeName(node) : null;
4712
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
4713
+ const content = node.content;
4714
+ if (_isDocumentFragment(content)) {
4715
+ stack.push({
4716
+ node: content,
4717
+ shadow: null
4718
+ });
4719
+ }
4720
+ }
4721
+ }
4722
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
4723
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
4724
+ rather than `instanceof DocumentFragment`, which is realm-bound and
4725
+ silently skipped foreign-realm shadow roots (e.g.
4726
+ iframe.contentDocument attachShadow). */
4727
+ if (isElement) {
4728
+ const sr = getShadowRoot(node);
4729
+ if (_isDocumentFragment(sr)) {
4730
+ /* Push the deferred sanitise first so it pops after the shadow
4731
+ walk we push next, i.e. nested shadow roots are discovered
4732
+ before this one is sanitised. */
4733
+ stack.push({
4734
+ node: null,
4735
+ shadow: sr
4736
+ }, {
4737
+ node: sr,
4738
+ shadow: null
4739
+ });
4740
+ }
4741
+ }
4742
+ }
4743
+ };
3831
4744
  // eslint-disable-next-line complexity
3832
4745
  DOMPurify.sanitize = function (dirty) {
3833
4746
  let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -3844,13 +4757,9 @@ function createDOMPurify() {
3844
4757
  }
3845
4758
  /* Stringify, in case dirty is an object */
3846
4759
  if (typeof dirty !== 'string' && !_isNode(dirty)) {
3847
- if (typeof dirty.toString === 'function') {
3848
- dirty = dirty.toString();
3849
- if (typeof dirty !== 'string') {
3850
- throw typeErrorCreate('dirty is not a string, aborting');
3851
- }
3852
- } else {
3853
- throw typeErrorCreate('toString is not a function');
4760
+ dirty = stringifyValue(dirty);
4761
+ if (typeof dirty !== 'string') {
4762
+ throw typeErrorCreate('dirty is not a string, aborting');
3854
4763
  }
3855
4764
  }
3856
4765
  /* Return dirty HTML if DOMPurify cannot run */
@@ -3858,24 +4767,78 @@ function createDOMPurify() {
3858
4767
  return dirty;
3859
4768
  }
3860
4769
  /* Assign config vars */
3861
- if (!SET_CONFIG) {
4770
+ if (SET_CONFIG) {
4771
+ /* Persistent setConfig() path: _parseConfig is skipped, so the sets are
4772
+ * not re-derived per call. Restore them from the pristine bindings
4773
+ * captured at setConfig() time so a previous call's hook clone (mutated
4774
+ * below) does not carry over. */
4775
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
4776
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
4777
+ } else {
3862
4778
  _parseConfig(cfg);
3863
4779
  }
4780
+ /* Clone the hook-mutable allowlists before the walk whenever an
4781
+ * uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
4782
+ * and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
4783
+ * a hook that widens them would otherwise mutate the shared set
4784
+ * permanently: across later calls and across every element. Cloning per
4785
+ * walk keeps documented in-call widening working while scoping it to the
4786
+ * call. A single guard for both config paths - the per-call path rebinds
4787
+ * the sets in _parseConfig each call, the persistent path restores them
4788
+ * from the captured bindings just above - so the two cannot diverge. */
4789
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
4790
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
4791
+ }
4792
+ if (hooks.uponSanitizeAttribute.length > 0) {
4793
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
4794
+ }
3864
4795
  /* Clean up removed elements */
3865
4796
  DOMPurify.removed = [];
3866
- /* Check if dirty is correctly typed for IN_PLACE */
3867
- if (typeof dirty === 'string') {
3868
- IN_PLACE = false;
3869
- }
3870
- if (IN_PLACE) {
3871
- /* Do some early pre-sanitization to avoid unsafe root nodes */
3872
- if (dirty.nodeName) {
3873
- const tagName = transformCaseFunc(dirty.nodeName);
4797
+ /* Resolve IN_PLACE for this call without mutating persistent config.
4798
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
4799
+ where _parseConfig is skipped on later calls: a single string call would
4800
+ disable in-place mode for every subsequent node call, returning a
4801
+ sanitized copy while leaving the caller's node — which in-place callers
4802
+ keep using and whose return value they ignore unsanitized. REPORT-2. */
4803
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
4804
+ if (inPlace) {
4805
+ /* Do some early pre-sanitization to avoid unsafe root nodes.
4806
+ Read nodeName through the cached prototype getter — a clobbering
4807
+ child named "nodeName" on the form root would otherwise shadow
4808
+ the property and let this check skip the root-allowlist
4809
+ validation entirely. */
4810
+ const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
4811
+ if (typeof nn === 'string') {
4812
+ const tagName = transformCaseFunc(nn);
3874
4813
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
3875
4814
  throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
3876
4815
  }
3877
4816
  }
3878
- } else if (dirty instanceof Node) {
4817
+ /* Pre-flight the root through _isClobbered. The iterator-driven
4818
+ removal path can not detach a parent-less root: _forceRemove
4819
+ falls through to Element.prototype.remove(), which per spec
4820
+ is a no-op on a node with no parent. A clobbered root would
4821
+ then survive the main loop with its attributes uninspected,
4822
+ because _sanitizeAttributes early-returns on _isClobbered. The
4823
+ result would be an attacker-controlled form, complete with any
4824
+ event-handler attributes the caller passed in, handed back to
4825
+ the application unsanitized. Refuse to sanitize such a root
4826
+ the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
4827
+ if (_isClobbered(dirty)) {
4828
+ throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
4829
+ }
4830
+ /* Sanitize attached shadow roots before the main iterator runs.
4831
+ The iterator does not descend into shadow trees. Same fail-closed
4832
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
4833
+ inside a shadow root could abort this pre-pass before the walk runs,
4834
+ which would otherwise leave the entire live tree unsanitized. */
4835
+ try {
4836
+ _sanitizeAttachedShadowRoots(dirty);
4837
+ } catch (error) {
4838
+ _neutralizeRoot(dirty);
4839
+ throw error;
4840
+ }
4841
+ } else if (_isNode(dirty)) {
3879
4842
  /* If dirty is a DOM element, append to an empty document to avoid
3880
4843
  elements being stripped by the parser */
3881
4844
  body = _initDocument('<!---->');
@@ -3889,12 +4852,18 @@ function createDOMPurify() {
3889
4852
  // eslint-disable-next-line unicorn/prefer-dom-node-append
3890
4853
  body.appendChild(importedNode);
3891
4854
  }
4855
+ /* Clonable shadow roots are deep-cloned by importNode(); sanitize
4856
+ them before the main iterator runs, since the iterator does not
4857
+ descend into shadow trees. The walk routes every read through a
4858
+ cached prototype getter so clobbering descendants on a form root
4859
+ cannot hide a shadow host from this pass. */
4860
+ _sanitizeAttachedShadowRoots(importedNode);
3892
4861
  } else {
3893
4862
  /* Exit directly if we have nothing to do */
3894
4863
  if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
3895
4864
  // eslint-disable-next-line unicorn/prefer-includes
3896
4865
  dirty.indexOf('<') === -1) {
3897
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
4866
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
3898
4867
  }
3899
4868
  /* Initialize the document to work on */
3900
4869
  body = _initDocument(dirty);
@@ -3908,24 +4877,60 @@ function createDOMPurify() {
3908
4877
  _forceRemove(body.firstChild);
3909
4878
  }
3910
4879
  /* Get node iterator */
3911
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
3912
- /* Now start iterating over the created document */
3913
- while (currentNode = nodeIterator.nextNode()) {
3914
- /* Sanitize tags and elements */
3915
- _sanitizeElements(currentNode);
3916
- /* Check attributes next */
3917
- _sanitizeAttributes(currentNode);
3918
- /* Shadow DOM detected, sanitize it */
3919
- if (currentNode.content instanceof DocumentFragment) {
3920
- _sanitizeShadowDOM(currentNode.content);
4880
+ const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
4881
+ /* Now start iterating over the created document.
4882
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
4883
+ engine/custom-element mutation can detach a node mid-walk so
4884
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
4885
+ barrier the caller's in-place tree would be left half-sanitized with the
4886
+ unvisited tail still armed. On any throw we fail closed — strip the
4887
+ in-place root bare then rethrow so the existing throw contract is
4888
+ preserved. (String/DOM-copy paths never return the partial body, so the
4889
+ propagating throw is already fail-closed there.) */
4890
+ try {
4891
+ while (currentNode = nodeIterator.nextNode()) {
4892
+ /* Sanitize tags and elements */
4893
+ _sanitizeElements(currentNode);
4894
+ /* Check attributes next */
4895
+ _sanitizeAttributes(currentNode);
4896
+ /* Shadow DOM detected, sanitize it.
4897
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
4898
+ instead of instanceof, so foreign-realm <template>.content is
4899
+ walked correctly. */
4900
+ if (_isDocumentFragment(currentNode.content)) {
4901
+ _sanitizeShadowDOM2(currentNode.content);
4902
+ }
4903
+ }
4904
+ } catch (error) {
4905
+ if (inPlace) {
4906
+ _neutralizeRoot(dirty);
3921
4907
  }
4908
+ throw error;
3922
4909
  }
3923
4910
  /* If we sanitized `dirty` in-place, return it. */
3924
- if (IN_PLACE) {
4911
+ if (inPlace) {
4912
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
4913
+ the caller's live tree is detached but may still hold a queued
4914
+ resource-event handler that fires in page scope after we return. The
4915
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
4916
+ non-allow-listed attributes off every other removed subtree (clobber,
4917
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
4918
+ cancelled before any event can fire. Runs synchronously, pre-return. */
4919
+ arrayForEach(DOMPurify.removed, entry => {
4920
+ if (entry.element) {
4921
+ _neutralizeSubtree(entry.element);
4922
+ }
4923
+ });
4924
+ if (SAFE_FOR_TEMPLATES) {
4925
+ _scrubTemplateExpressions2(dirty);
4926
+ }
3925
4927
  return dirty;
3926
4928
  }
3927
4929
  /* Return sanitized string or DOM */
3928
4930
  if (RETURN_DOM) {
4931
+ if (SAFE_FOR_TEMPLATES) {
4932
+ _scrubTemplateExpressions2(body);
4933
+ }
3929
4934
  if (RETURN_DOM_FRAGMENT) {
3930
4935
  returnNode = createDocumentFragment.call(body.ownerDocument);
3931
4936
  while (body.firstChild) {
@@ -3954,20 +4959,28 @@ function createDOMPurify() {
3954
4959
  }
3955
4960
  /* Sanitize final string template-safe */
3956
4961
  if (SAFE_FOR_TEMPLATES) {
3957
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
3958
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
3959
- });
4962
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
3960
4963
  }
3961
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
4964
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
3962
4965
  };
3963
4966
  DOMPurify.setConfig = function () {
3964
4967
  let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3965
4968
  _parseConfig(cfg);
3966
4969
  SET_CONFIG = true;
4970
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
4971
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
3967
4972
  };
3968
4973
  DOMPurify.clearConfig = function () {
3969
4974
  CONFIG = null;
3970
4975
  SET_CONFIG = false;
4976
+ SET_CONFIG_ALLOWED_TAGS = null;
4977
+ SET_CONFIG_ALLOWED_ATTR = null;
4978
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
4979
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
4980
+ // never recreated — Trusted Types throws on duplicate names) is restored by
4981
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
4982
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
4983
+ emptyHTML = '';
3971
4984
  };
3972
4985
  DOMPurify.isValidAttribute = function (tag, attr, value) {
3973
4986
  /* Initialize shared config vars if necessary. */
@@ -3982,9 +4995,19 @@ function createDOMPurify() {
3982
4995
  if (typeof hookFunction !== 'function') {
3983
4996
  return;
3984
4997
  }
4998
+ /* Reject unknown entry points. Without this, a non-hook key (e.g.
4999
+ * '__proto__') indexes off the prototype chain rather than a real
5000
+ * hook array, and arrayPush then writes to Object.prototype. Guard
5001
+ * with an own-property check against the known hook names. */
5002
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
5003
+ return;
5004
+ }
3985
5005
  arrayPush(hooks[entryPoint], hookFunction);
3986
5006
  };
3987
5007
  DOMPurify.removeHook = function (entryPoint, hookFunction) {
5008
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
5009
+ return undefined;
5010
+ }
3988
5011
  if (hookFunction !== undefined) {
3989
5012
  const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
3990
5013
  return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
@@ -3992,6 +5015,9 @@ function createDOMPurify() {
3992
5015
  return arrayPop(hooks[entryPoint]);
3993
5016
  };
3994
5017
  DOMPurify.removeHooks = function (entryPoint) {
5018
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
5019
+ return;
5020
+ }
3995
5021
  hooks[entryPoint] = [];
3996
5022
  };
3997
5023
  DOMPurify.removeAllHooks = function () {
@@ -4075,7 +5101,7 @@ try {
4075
5101
  // swallow
4076
5102
  }
4077
5103
  const trusted = createPolicy('trusted', policyOptions);
4078
- /*! version: 0.28.2 */
5104
+ /*! version: 0.28.4 */
4079
5105
 
4080
5106
  /*!
4081
5107
  * Copyright (C) 2019 salesforce.com, inc.
@@ -4384,7 +5410,7 @@ function blobSanitizer$LWS(sandboxKey$LWS) {
4384
5410
  }
4385
5411
  return getSanitizerForConfig$LWS(sandboxKey$LWS, 'STRING_BLOB_HTML');
4386
5412
  }
4387
- /*! version: 0.28.2 */
5413
+ /*! version: 0.28.4 */
4388
5414
 
4389
5415
  /*!
4390
5416
  * Copyright (C) 2023 salesforce.com, inc.
@@ -4593,7 +5619,7 @@ function createScriptSrcURLSetter$LWS(targetElement$LWS) {
4593
5619
  ReflectApply$LWS$1(ElementProtoSetAttributeNS$LWS, targetElement$LWS, [attributeNamespaceURI$LWS, attributeName$LWS, src$LWS]);
4594
5620
  };
4595
5621
  }
4596
- /*! version: 0.28.2 */
5622
+ /*! version: 0.28.4 */
4597
5623
 
4598
5624
  /*!
4599
5625
  * Copyright (C) 2019 salesforce.com, inc.
@@ -8237,6 +9263,151 @@ function initDistortionEventTargetDispatchEvent$LWS({
8237
9263
  return [originalDispatchEvent$LWS, dispatchEvent$LWS];
8238
9264
  };
8239
9265
  }
9266
+
9267
+ // W-22602807: shared helper for distorting an iframe contentWindow realm's
9268
+ // function-invocation primitives (Function.prototype.call/apply/bind,
9269
+ // Reflect.apply/construct).
9270
+ //
9271
+ // The cross-realm leak: sandbox code obtains a same-origin iframe's invocation
9272
+ // primitive and uses it to invoke a constructor/evaluator. The callee can
9273
+ // arrive as a RAW callable whose realm's `document` is undistorted, so
9274
+ // `document.cookie` in a compiled body resolves to the native getter and leaks
9275
+ // the top-level cookie.
9276
+ //
9277
+ // Containment tracks the OUTERMOST primitive actually invoked through the
9278
+ // membrane (composition depth is irrelevant: in `apply.call(F, ...)` only the
9279
+ // outer `.call` is invoked). So every invocation primitive reachable on the
9280
+ // iframe realm must be distorted. Each re-resolves the callee (the function
9281
+ // being invoked) to its distorted counterpart in the ROOT record's map when
9282
+ // one exists, then delegates to the native primitive — so a raw native
9283
+ // Function/eval reached cross-realm becomes the sandbox-distorted version,
9284
+ // while ordinary usage is an untouched passthrough.
9285
+ // Returns the host iframe element if `globalObject
9286
+ // ` is a same-origin iframe
9287
+ // contentWindow realm (the only realm we distort), else undefined. Gated on
9288
+ // changesSince.264: when the gate is off, no entry is installed and the
9289
+ // primitive keeps its native behavior. One check here covers all five
9290
+ // invocation-primitive distortions.
9291
+ function getDistortableFrameElement$LWS(globalObject$LWS) {
9292
+ if (!isGaterEnabledFeature$LWS('changesSince.264')) {
9293
+ return undefined;
9294
+ }
9295
+ let frameElement$LWS;
9296
+ try {
9297
+ frameElement$LWS = ReflectApply$LWS$1(WindowFrameElementGetter$LWS, globalObject$LWS, []);
9298
+ } catch (_unused2$LWS) {
9299
+ // Cross-origin / non-window realm: not our target.
9300
+ return undefined;
9301
+ }
9302
+ return frameElement$LWS || undefined;
9303
+ }
9304
+ // Re-resolve `callee` to its distorted counterpart from the root distortion
9305
+ // map, if one exists; otherwise return it unchanged.
9306
+ //
9307
+ // This reads the assembled `root.distortions` map at invocation time — the same
9308
+ // map the near-membrane's distortionCallback consults. That is deliberate: a
9309
+ // foreign invocation primitive can deliver a callee (e.g. the sandbox `Function`
9310
+ // ctor) that has crossed the membrane as a RAW reference, bypassing the
9311
+ // distortion the membrane would normally apply on a direct call. Looking the
9312
+ // callee up in the map re-attaches that distortion. We rely on the map's
9313
+ // invariant that a callable key maps to a callable replacement; the
9314
+ // `distorted !== callee` check skips identity mappings (e.g. `document`,
9315
+ // `location`, the global object, which map to themselves), and the invocation
9316
+ // primitives require a callable target regardless, so a non-callable could
9317
+ // never be reached here without throwing at the call site.
9318
+ function substituteDistortedCallee$LWS(root$LWS, callee$LWS) {
9319
+ const distorted$LWS = root$LWS.distortions.get(callee$LWS);
9320
+ if (distorted$LWS !== undefined && distorted$LWS !== callee$LWS) {
9321
+ return distorted$LWS;
9322
+ }
9323
+ return callee$LWS;
9324
+ }
9325
+
9326
+ // W-22602807: distort an iframe contentWindow realm's Function.prototype.apply.
9327
+ // See cross-realm-invocation.ts for the threat model.
9328
+ function initDistortionFunctionApply$LWS({
9329
+ globalObject: {
9330
+ Function: {
9331
+ prototype: {
9332
+ apply: originalApply$LWS
9333
+ }
9334
+ }
9335
+ }
9336
+ }) {
9337
+ return function distortionFunctionApply$LWS({
9338
+ globalObject: globalObject$LWS,
9339
+ root: root$LWS
9340
+ }) {
9341
+ if (!getDistortableFrameElement$LWS(globalObject$LWS)) {
9342
+ return undefined;
9343
+ }
9344
+ return [originalApply$LWS,
9345
+ // `this` is the callee; (thisArg, argsArray) its binding and args.
9346
+ // `apply` accepts a null/undefined argsArray, which ReflectApply
9347
+ // rejects, so normalize to [].
9348
+ function apply$LWS(thisArg$LWS, argsArray$LWS) {
9349
+ return ReflectApply$LWS$1(substituteDistortedCallee$LWS(root$LWS, this), thisArg$LWS, argsArray$LWS == null ? [] : argsArray$LWS);
9350
+ }];
9351
+ };
9352
+ }
9353
+
9354
+ // W-22602807: distort an iframe contentWindow realm's Function.prototype.bind.
9355
+ // See cross-realm-invocation.ts for the threat model.
9356
+ //
9357
+ // bind defers invocation: it returns a bound function invoked later. We
9358
+ // substitute the callee for its distorted counterpart FIRST, then bind that,
9359
+ // so the returned bound function wraps the sandbox-distorted callee.
9360
+ function initDistortionFunctionBind$LWS({
9361
+ globalObject: {
9362
+ Function: {
9363
+ prototype: {
9364
+ bind: originalBind$LWS
9365
+ }
9366
+ }
9367
+ }
9368
+ }) {
9369
+ return function distortionFunctionBind$LWS({
9370
+ globalObject: globalObject$LWS,
9371
+ root: root$LWS
9372
+ }) {
9373
+ if (!getDistortableFrameElement$LWS(globalObject$LWS)) {
9374
+ return undefined;
9375
+ }
9376
+ return [originalBind$LWS,
9377
+ // `this` is the callee; (thisArg, ...boundArgs) the binding and
9378
+ // partially-applied args. Bind the substituted callee with the
9379
+ // sandbox-realm bind so the result is a sandbox-realm bound function.
9380
+ function bind$LWS(thisArg$LWS, ...boundArgs$LWS) {
9381
+ return ReflectApply$LWS$1(FunctionProtoBind$LWS, substituteDistortedCallee$LWS(root$LWS, this), [thisArg$LWS, ...boundArgs$LWS]);
9382
+ }];
9383
+ };
9384
+ }
9385
+
9386
+ // W-22602807: distort an iframe contentWindow realm's Function.prototype.call.
9387
+ // See cross-realm-invocation.ts for the threat model.
9388
+ function initDistortionFunctionCall$LWS({
9389
+ globalObject: {
9390
+ Function: {
9391
+ prototype: {
9392
+ call: originalCall$LWS
9393
+ }
9394
+ }
9395
+ }
9396
+ }) {
9397
+ return function distortionFunctionCall$LWS({
9398
+ globalObject: globalObject$LWS,
9399
+ root: root$LWS
9400
+ }) {
9401
+ if (!getDistortableFrameElement$LWS(globalObject$LWS)) {
9402
+ return undefined;
9403
+ }
9404
+ return [originalCall$LWS,
9405
+ // `this` is the callee; (thisArg, ...args) its binding and arguments.
9406
+ function call$LWS(thisArg$LWS, ...args$LWS) {
9407
+ return ReflectApply$LWS$1(substituteDistortedCallee$LWS(root$LWS, this), thisArg$LWS, args$LWS);
9408
+ }];
9409
+ };
9410
+ }
8240
9411
  function initDistortionFunction$LWS({
8241
9412
  UNCOMPILED_CONTEXT: UNCOMPILED_CONTEXT$LWS,
8242
9413
  globalObject: {
@@ -8337,11 +9508,35 @@ function initDistortionHistoryReplaceState$LWS({
8337
9508
  };
8338
9509
  }
8339
9510
 
8340
- // Anchor elements allow blob: URLs in addition to standard schemes for download links
8341
- const ANCHOR_URL_SCHEMES_LIST$LWS = toSafeArray$LWS$1(['about:', 'blob:', 'http:', 'https:']);
8342
- function isValidAnchorURLScheme$LWS(url$LWS) {
9511
+ // Only schemes that can trigger arbitrary JavaScript execution when an anchor is
9512
+ // navigated are blocked. Everything else (mailto:, tel:, sms:, http:, https:,
9513
+ // blob:, about:, relative urls) is permitted: those navigate or hand off to an
9514
+ // external app and cannot execute script.
9515
+ // eslint-disable-next-line no-script-url
9516
+ const ANCHOR_BLOCKED_URL_SCHEMES_LIST$LWS = toSafeArray$LWS$1(['data:', 'javascript:', 'vbscript:']);
9517
+ const ANCHOR_BLOCKED_SCHEME_ERROR_MESSAGE$LWS = 'HTMLAnchorElement href does not support data:, javascript: or vbscript: schemes.';
9518
+ // The scheme is read back through the browser's own URL parser via the
9519
+ // normalizer anchor, so case/whitespace/zero-width evasion variants resolve to
9520
+ // the same normalized protocol the browser would execute. A payload that does
9521
+ // not normalize to a blocked scheme is also not executed as one by the browser.
9522
+ function normalizedSchemeIsBlocked$LWS() {
9523
+ return ANCHOR_BLOCKED_URL_SCHEMES_LIST$LWS.includes(ReflectApply$LWS$1(HTMLAnchorElementProtoProtocolGetter$LWS, normalizerAnchor$LWS, []));
9524
+ }
9525
+ // Guards the `href` setter / `href` attribute: the whole URL is assigned to the
9526
+ // normalizer, then its resolved protocol is checked.
9527
+ function isBlockedAnchorHref$LWS(url$LWS) {
8343
9528
  ReflectApply$LWS$1(HTMLAnchorElementProtoHrefSetter$LWS, normalizerAnchor$LWS, [url$LWS]);
8344
- return ANCHOR_URL_SCHEMES_LIST$LWS.includes(ReflectApply$LWS$1(HTMLAnchorElementProtoProtocolGetter$LWS, normalizerAnchor$LWS, []));
9529
+ return normalizedSchemeIsBlocked$LWS();
9530
+ }
9531
+ // Guards the `protocol` setter: `a.protocol = value` resolves against the
9532
+ // anchor's current href, so the same current href is replayed onto the
9533
+ // normalizer before applying the new scheme. This mirrors exactly what the
9534
+ // native setter would produce, on a throwaway anchor.
9535
+ function isBlockedAnchorProtocolChange$LWS(anchor$LWS, value$LWS) {
9536
+ const currentHref$LWS = ReflectApply$LWS$1(HTMLAnchorElementProtoHrefGetter$LWS, anchor$LWS, []);
9537
+ ReflectApply$LWS$1(HTMLAnchorElementProtoHrefSetter$LWS, normalizerAnchor$LWS, [currentHref$LWS]);
9538
+ ReflectApply$LWS$1(HTMLAnchorElementProtoProtocolSetter$LWS, normalizerAnchor$LWS, [value$LWS]);
9539
+ return normalizedSchemeIsBlocked$LWS();
8345
9540
  }
8346
9541
  function initDistortionHTMLAnchorElementHrefSetter$LWS({
8347
9542
  globalObject: {
@@ -8352,8 +9547,8 @@ function initDistortionHTMLAnchorElementHrefSetter$LWS({
8352
9547
  function href$LWS(value$LWS) {
8353
9548
  const urlString$LWS = sanitizeURLForElement$LWS(value$LWS);
8354
9549
  if (isGaterEnabledFeature$LWS('htmlAnchorElementHrefValidation')) {
8355
- if (!isValidAnchorURLScheme$LWS(urlString$LWS)) {
8356
- throw new LockerSecurityError$LWS('HTMLAnchorElement.href supports http://, https://, blob: schemes, relative urls and about:blank.');
9550
+ if (isBlockedAnchorHref$LWS(urlString$LWS)) {
9551
+ throw new LockerSecurityError$LWS(ANCHOR_BLOCKED_SCHEME_ERROR_MESSAGE$LWS);
8357
9552
  }
8358
9553
  const parsedURL$LWS = parseURL$LWS(urlString$LWS);
8359
9554
  if (!isAllowedEndpointURL$LWS(parsedURL$LWS)) {
@@ -8371,6 +9566,25 @@ function initDistortionHTMLAnchorElementHrefSetter$LWS({
8371
9566
  return distortionEntry$LWS;
8372
9567
  };
8373
9568
  }
9569
+ function initDistortionHTMLAnchorElementProtocolSetter$LWS({
9570
+ globalObject: {
9571
+ HTMLAnchorElement: HTMLAnchorElement$LWS
9572
+ }
9573
+ }) {
9574
+ const originalProtocolSetter$LWS = ObjectLookupOwnSetter$LWS(HTMLAnchorElement$LWS.prototype, 'protocol');
9575
+ function protocol$LWS(value$LWS) {
9576
+ if (isGaterEnabledFeature$LWS('changesSince.264')) {
9577
+ if (isBlockedAnchorProtocolChange$LWS(this, value$LWS)) {
9578
+ throw new LockerSecurityError$LWS(ANCHOR_BLOCKED_SCHEME_ERROR_MESSAGE$LWS);
9579
+ }
9580
+ }
9581
+ ReflectApply$LWS$1(originalProtocolSetter$LWS, this, [value$LWS]);
9582
+ }
9583
+ const distortionEntry$LWS = [originalProtocolSetter$LWS, protocol$LWS];
9584
+ return function distortionHTMLAnchorElementProtocolSetter$LWS() {
9585
+ return distortionEntry$LWS;
9586
+ };
9587
+ }
8374
9588
  function initDistortionHTMLBaseElementHrefSetter$LWS({
8375
9589
  globalObject: {
8376
9590
  HTMLBaseElement: HTMLBaseElement$LWS
@@ -8848,7 +10062,7 @@ function enforceSandboxAllowScriptsForSameOriginIframeRealm$LWS(iframe$LWS, srcV
8848
10062
  if (!isSameOriginURL$LWS(srcValue$LWS)) {
8849
10063
  return;
8850
10064
  }
8851
- } catch (_unused2$LWS) {
10065
+ } catch (_unused3$LWS) {
8852
10066
  /* empty */
8853
10067
  }
8854
10068
  if (!ReflectApply$LWS$1(DOMTokenListProtoContains$LWS, sandboxTokenList$LWS, [ALLOW_SCRIPTS_TOKEN$LWS])) {
@@ -11640,6 +12854,63 @@ function initDistortionRangeToString$LWS({
11640
12854
  return distortionEntry$LWS;
11641
12855
  };
11642
12856
  }
12857
+
12858
+ // W-22602807: distort an iframe contentWindow realm's Reflect.apply.
12859
+ // See Function/cross-realm-invocation.ts for the threat model.
12860
+ //
12861
+ // Unlike Function.prototype.apply, the callee is the FIRST ARGUMENT (not
12862
+ // `this`) and the invocation never routes through Function.prototype.call, so
12863
+ // it is an independent doorway that must be distorted separately.
12864
+ function initDistortionReflectApply$LWS({
12865
+ globalObject: {
12866
+ Reflect: {
12867
+ apply: originalReflectApply$LWS
12868
+ }
12869
+ }
12870
+ }) {
12871
+ return function distortionReflectApply$LWS({
12872
+ globalObject: globalObject$LWS,
12873
+ root: root$LWS
12874
+ }) {
12875
+ if (!getDistortableFrameElement$LWS(globalObject$LWS)) {
12876
+ return undefined;
12877
+ }
12878
+ return [originalReflectApply$LWS, function apply$LWS(target$LWS, thisArg$LWS, argsArray$LWS) {
12879
+ return ReflectApply$LWS$1(substituteDistortedCallee$LWS(root$LWS, target$LWS), thisArg$LWS, argsArray$LWS == null ? [] : argsArray$LWS);
12880
+ }];
12881
+ };
12882
+ }
12883
+
12884
+ // W-22602807: distort an iframe contentWindow realm's Reflect.construct.
12885
+ // See Function/cross-realm-invocation.ts for the threat model.
12886
+ //
12887
+ // Construct semantics (not call): the callee is the FIRST ARGUMENT and is
12888
+ // invoked as a constructor. Substitute it for its distorted counterpart, then
12889
+ // construct with the sandbox-realm Reflect.construct, preserving the optional
12890
+ // newTarget argument.
12891
+ function initDistortionReflectConstruct$LWS({
12892
+ globalObject: {
12893
+ Reflect: {
12894
+ construct: originalReflectConstruct$LWS
12895
+ }
12896
+ }
12897
+ }) {
12898
+ return function distortionReflectConstruct$LWS({
12899
+ globalObject: globalObject$LWS,
12900
+ root: root$LWS
12901
+ }) {
12902
+ if (!getDistortableFrameElement$LWS(globalObject$LWS)) {
12903
+ return undefined;
12904
+ }
12905
+ return [originalReflectConstruct$LWS, function construct$LWS(target$LWS, argsArray$LWS, newTarget$LWS) {
12906
+ const substituted$LWS = substituteDistortedCallee$LWS(root$LWS, target$LWS);
12907
+ if (arguments.length > 2) {
12908
+ return ReflectConstruct$LWS(substituted$LWS, argsArray$LWS == null ? [] : argsArray$LWS, newTarget$LWS);
12909
+ }
12910
+ return ReflectConstruct$LWS(substituted$LWS, argsArray$LWS == null ? [] : argsArray$LWS);
12911
+ }];
12912
+ };
12913
+ }
11643
12914
  function initDistortionReportingObserverCtor$LWS({
11644
12915
  globalObject: {
11645
12916
  ReportingObserver: originalReportingObserverCtor$LWS
@@ -12287,7 +13558,7 @@ function createDistortionStorageFactoryInitializer$LWS(storageName$LWS) {
12287
13558
  try {
12288
13559
  originalStorageObject$LWS = globalObject$LWS[storageName$LWS];
12289
13560
  // eslint-disable-next-line no-empty
12290
- } catch (_unused3$LWS) {}
13561
+ } catch (_unused4$LWS) {}
12291
13562
  // istanbul ignore if: currently unreachable via tests
12292
13563
  if (!isObject$LWS$1(originalStorageObject$LWS)) {
12293
13564
  return noop$LWS$1;
@@ -12713,7 +13984,7 @@ function initDistortionTrustedTypePolicyFactoryCreatePolicy$LWS({
12713
13984
  try {
12714
13985
  // istanbul ignore next: needs default platform behavior test
12715
13986
  return ReflectApply$LWS$1(originalCreatePolicy$LWS, this, args$LWS);
12716
- } catch (_unused4$LWS) {
13987
+ } catch (_unused5$LWS) {
12717
13988
  // istanbul ignore next: this is tested, but currently cannot be tested in the coverage environment
12718
13989
  consoleWarn$LWS(`${createTrustedTypesExceptionMessage$LWS(name$LWS)} Substituting with Lightning Web Security policy.`);
12719
13990
  }
@@ -12786,7 +14057,7 @@ function initDistortionURLCreateObjectURL$LWS({
12786
14057
  ReflectApply$LWS$1(XhrProtoOpen$LWS, xhr$LWS, ['GET', outURL$LWS, false]);
12787
14058
  try {
12788
14059
  ReflectApply$LWS$1(XhrProtoSend$LWS, xhr$LWS, []);
12789
- } catch (_unused5$LWS) {
14060
+ } catch (_unused6$LWS) {
12790
14061
  throw new LockerSecurityError$LWS(`Unable to verify ${toSafeTemplateStringValue$LWS(blobObject$LWS)} is secure.`);
12791
14062
  }
12792
14063
  const responseText$LWS = ReflectApply$LWS$1(XhrProtoResponseTextGetter$LWS, xhr$LWS, []);
@@ -13573,7 +14844,7 @@ initDistortionDOMTokenListAdd$LWS, initDistortionDOMTokenListReplace$LWS, initDi
13573
14844
  // Element
13574
14845
  initDistortionElementAttributesGetter$LWS, initDistortionElementGetInnerHTML$LWS, initDistortionElementInnerHTMLGetter$LWS, initDistortionElementOuterHTMLGetter$LWS, initDistortionElementRemove$LWS, initDistortionElementRemoveAttribute$LWS, initDistortionElementRemoveAttributeNS$LWS, initDistortionElementRemoveAttributeNode$LWS, initDistortionElementReplaceChildren$LWS, initDistortionElementReplaceWith$LWS,
13575
14846
  // Function
13576
- initDistortionFunction$LWS,
14847
+ initDistortionFunction$LWS, initDistortionFunctionApply$LWS, initDistortionFunctionBind$LWS, initDistortionFunctionCall$LWS,
13577
14848
  // History
13578
14849
  initDistortionHistoryPushState$LWS, initDistortionHistoryReplaceState$LWS,
13579
14850
  // HTMLElement
@@ -13626,6 +14897,8 @@ initDistortionPromiseAll$LWS, initDistortionPromiseAllSettled$LWS, initDistortio
13626
14897
  initDistortionNotificationCtor$LWS,
13627
14898
  // Range
13628
14899
  initDistortionRangeCloneContents$LWS, initDistortionRangeCloneRange$LWS, initDistortionRangeDeleteContents$LWS, initDistortionRangeExtractContents$LWS, initDistortionRangeGetBoundingClientRect$LWS, initDistortionRangeInsertNode$LWS, initDistortionRangeSelectNode$LWS, initDistortionRangeSelectNodeContents$LWS, initDistortionRangeSetEnd$LWS, initDistortionRangeSetEndAfter$LWS, initDistortionRangeSetEndBefore$LWS, initDistortionRangeSetStart$LWS, initDistortionRangeSetStartAfter$LWS, initDistortionRangeSetStartBefore$LWS, initDistortionRangeSurroundContents$LWS, initDistortionRangeToString$LWS,
14900
+ // Reflect
14901
+ initDistortionReflectApply$LWS, initDistortionReflectConstruct$LWS,
13629
14902
  // Selection
13630
14903
  initDistortionSelectionAnchorNodeGetter$LWS, initDistortionSelectionCollapse$LWS, initDistortionSelectionExtend$LWS, initDistortionSelectionFocusNodeGetter$LWS, initDistortionSelectionSelectAllChildren$LWS, initDistortionSelectionSetBaseAndExtent$LWS, initDistortionSelectionSetPosition$LWS, initDistortionSelectionToString$LWS,
13631
14904
  // ServiceWorkerContainer
@@ -13678,7 +14951,7 @@ initDistortionEventComposedPath$LWS, initDistortionEventPathGetter$LWS,
13678
14951
  // EventTarget
13679
14952
  initDistortionEventTargetAddEventListener$LWS, initDistortionEventTargetDispatchEvent$LWS,
13680
14953
  // HTMLAnchorElement
13681
- initDistortionHTMLAnchorElementHrefSetter$LWS,
14954
+ initDistortionHTMLAnchorElementHrefSetter$LWS, initDistortionHTMLAnchorElementProtocolSetter$LWS,
13682
14955
  // HTMLBaseElement
13683
14956
  initDistortionHTMLBaseElementHrefSetter$LWS,
13684
14957
  // HTMLBodyElement
@@ -13751,7 +15024,7 @@ const SVGElementProtoBlockedProperties$LWS = ['nonce'];
13751
15024
  const UIEventProtoBlockedProperties$LWS = ['rangeParent'];
13752
15025
  const WindowBlockedProperties$LWS = ['find', 'requestFileSystem', 'webkitRequestFileSystem'];
13753
15026
  const XSLTProcessorProtoBlockedProperties$LWS = ['transformToDocument', 'transformToFragment'];
13754
- /*! version: 0.28.2 */
15027
+ /*! version: 0.28.4 */
13755
15028
 
13756
15029
  /*!
13757
15030
  * Copyright (C) 2021 salesforce.com, inc.
@@ -13760,7 +15033,7 @@ let pdpSchema$LWS;
13760
15033
  function getPdpSchema$LWS() {
13761
15034
  return pdpSchema$LWS;
13762
15035
  }
13763
- /*! version: 0.28.2 */
15036
+ /*! version: 0.28.4 */
13764
15037
 
13765
15038
  /*!
13766
15039
  * Copyright (C) 2019 salesforce.com, inc.
@@ -19152,7 +20425,7 @@ function toSourceText$LWS(value$LWS, sourceType$LWS) {
19152
20425
  // tools from mistaking the regexp or the replacement string for an
19153
20426
  // actual source mapping URL.
19154
20427
  /\/\/# sandbox(?=MappingURL=.*?\s*$)/, '//# source']);
19155
- sourceText$LWS = `\n//# LWS Version = "0.28.2"\n${sourceText$LWS}`;
20428
+ sourceText$LWS = `\n//# LWS Version = "0.28.4"\n${sourceText$LWS}`;
19156
20429
  return sourceType$LWS === 1 /* SourceType.Module */ && indexOfPragma$LWS(sourceText$LWS, 'use strict') === -1 ?
19157
20430
  // Append "'use strict'" to the extracted function body so it is
19158
20431
  // evaluated in strict mode.
@@ -19956,7 +21229,7 @@ function wrapPlatformResourceLoader$LWS(dep$LWS, key$LWS) {
19956
21229
  depRegistry$LWS.set(dep$LWS, secureDep$LWS);
19957
21230
  return secureDep$LWS;
19958
21231
  }
19959
- /*! version: 0.28.2 */
21232
+ /*! version: 0.28.4 */
19960
21233
 
19961
21234
  const loaderDefine = (globalThis ).LWR.define;
19962
21235