dompurify 3.4.13 → 3.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/purify.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @license DOMPurify 3.4.13 | (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.13/LICENSE */
1
+ /*! @license DOMPurify 3.4.14 | (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.14/LICENSE */
2
2
 
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -317,7 +317,7 @@
317
317
  const text = freeze(['#text']);
318
318
 
319
319
  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']);
320
- 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', 'dominant-baseline', '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-orientation', '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']);
320
+ 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', 'dominant-baseline', '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', 'pointer-events', '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-orientation', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'vector-effect', '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']);
321
321
  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']);
322
322
  const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
323
323
 
@@ -358,6 +358,37 @@
358
358
  documentFragment: 11,
359
359
  notation: 12 // Deprecated
360
360
  };
361
+ /* HTML-namespace elements whose child text nodes are serialized *literally*
362
+ (unescaped) by the HTML fragment-serialization algorithm. Two reparse-mXSS
363
+ shapes ride on that literal serialization:
364
+ (a) an element child - a tree the HTML parser can never build, but the DOM
365
+ API and an XML/XHTML parse can - after which a `</tag>`-bearing text
366
+ sibling breaks the element open on reparse; and
367
+ (b) text-only content that already carries the element's OWN end tag, e.g.
368
+ `<style>...</style><img onerror=x>` built as a node, which the literal
369
+ serializer emits verbatim for the HTML parser to re-open.
370
+ Shape (a) is handled by the firstElementChild branch in _isUnsafeNode; shape
371
+ (b) by the LITERAL_TEXT_CLOSE probe. Both read textContent (the raw-serialized
372
+ form for these elements) rather than innerHTML, because an XML/XHTML working
373
+ document serializes innerHTML with `<` escaped, which silently blinds the
374
+ innerHTML-based probes (rule 1's second probe and FALLBACK_TAG_CLOSE) there.
375
+ `script` is never allow-listed, but is kept here so the guard matches the
376
+ serializer's own literal-text list exactly. */
377
+ const LITERAL_TEXT_ELEMENT_NAMES = ['style', 'script', 'xmp', 'iframe', 'noembed', 'noframes', 'plaintext', 'noscript'];
378
+ const LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, LITERAL_TEXT_ELEMENT_NAMES));
379
+ /* Per-element end-tag matcher. On an HTML reparse the ONLY token that
380
+ terminates a literal-text element's raw content is its own end tag; a foreign
381
+ literal-text close (e.g. `</xmp>` sitting inside `<style>`) does not break
382
+ out, so matching is per-element, not a shared alternation. The lookahead
383
+ requires an HTML tag-name terminator (whitespace, `/` or `>`) so a longer
384
+ name such as `</styles` is not mistaken for `</style`. */
385
+ const LITERAL_TEXT_CLOSE = function () {
386
+ const map = {};
387
+ arrayForEach(LITERAL_TEXT_ELEMENT_NAMES, name => {
388
+ map[name] = seal(new RegExp('</' + name + '(?=[\\t\\n\\f\\r />])', 'i'));
389
+ });
390
+ return freeze(map);
391
+ }();
361
392
  const getGlobal = function getGlobal() {
362
393
  return typeof window === 'undefined' ? null : window;
363
394
  };
@@ -427,10 +458,25 @@
427
458
  const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
428
459
  return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
429
460
  };
461
+ /**
462
+ * Resolve an object-valued configuration option: a prototype-free clone
463
+ * of cfg[key] when it is an own, truthy object property, else a fresh
464
+ * fallback built by makeFallback (fresh on every parse, so a previous
465
+ * parse can never leak state into the next one).
466
+ *
467
+ * @param cfg the cloned, prototype-free configuration object
468
+ * @param key the configuration property to read
469
+ * @param makeFallback builds the fallback value when the option is absent
470
+ * @returns the resolved object
471
+ */
472
+ const _resolveObjectOption = function _resolveObjectOption(cfg, key, makeFallback) {
473
+ const value = objectHasOwnProperty(cfg, key) ? cfg[key] : undefined;
474
+ return value && typeof value === 'object' ? clone(value) : makeFallback();
475
+ };
430
476
  function createDOMPurify() {
431
477
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
432
478
  const DOMPurify = root => createDOMPurify(root);
433
- DOMPurify.version = '3.4.13';
479
+ DOMPurify.version = '3.4.14';
434
480
  DOMPurify.removed = [];
435
481
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
436
482
  // Not running in a browser, provide a factory function
@@ -462,6 +508,16 @@
462
508
  const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
463
509
  const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
464
510
  const getOwnerDocument = Node && Node.prototype ? lookupGetter(Node.prototype, 'ownerDocument') : null;
511
+ /* Clobber-safe nodeType / nodeName reads through the cached Node.prototype
512
+ getters, with a direct-property fallback for environments that lack
513
+ Node.prototype. Sites that need a different fallback (e.g. _isClobbered
514
+ returns early on a null name) intentionally keep their own reads. */
515
+ const _readNodeType = function _readNodeType(node) {
516
+ return getNodeType ? getNodeType(node) : node.nodeType;
517
+ };
518
+ const _readNodeName = function _readNodeName(node) {
519
+ return getNodeName ? getNodeName(node) : node.nodeName;
520
+ };
465
521
  // As per issue #47, the web-components registry is inherited by a
466
522
  // new document created via createHTMLDocument. As per the spec
467
523
  // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
@@ -784,9 +840,11 @@
784
840
  IN_PLACE = cfg.IN_PLACE || false; // Default false
785
841
  IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
786
842
  NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
787
- 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
788
- 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
789
- const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
843
+ MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, 'MATHML_TEXT_INTEGRATION_POINTS', () => addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS) // Default built-in map
844
+ );
845
+ HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, 'HTML_INTEGRATION_POINTS', () => addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS) // Default built-in map
846
+ );
847
+ const customElementHandling = _resolveObjectOption(cfg, 'CUSTOM_ELEMENT_HANDLING', () => create(null));
790
848
  CUSTOM_ELEMENT_HANDLING = create(null);
791
849
  if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
792
850
  CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
@@ -853,15 +911,6 @@
853
911
  addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
854
912
  }
855
913
  }
856
- if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
857
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
858
- }
859
- if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
860
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
861
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
862
- }
863
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
864
- }
865
914
  if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
866
915
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
867
916
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
@@ -1096,6 +1145,32 @@
1096
1145
  }
1097
1146
  }
1098
1147
  };
1148
+ /**
1149
+ * _stripAttributeNode
1150
+ *
1151
+ * Remove a single Attr node case/namespace-exactly on an attribute-teardown
1152
+ * path. Name-based removeAttribute() ASCII-lowercases its lookup key for an
1153
+ * HTML element in an HTML document and so silently misses a case-preserved
1154
+ * handler (e.g. `ONERROR` off an XML/XHTML import) - the same defect
1155
+ * _removeAttribute() was fixed for, which a name-based call would reintroduce
1156
+ * on these IN_PLACE teardown paths. Unlike _removeAttribute this does not
1157
+ * record into DOMPurify.removed: the neutralize passes intentionally do not
1158
+ * book-keep. A clobbered/detached node falls back to best-effort name-based
1159
+ * removal.
1160
+ *
1161
+ * @param element the element to strip the attribute from
1162
+ * @param attribute the Attr node to remove
1163
+ * @param name the attribute's name, for the fallback path
1164
+ */
1165
+ const _stripAttributeNode = function _stripAttributeNode(element, attribute, name) {
1166
+ try {
1167
+ element.removeAttributeNode(attribute);
1168
+ } catch (_) {
1169
+ try {
1170
+ element.removeAttribute(name);
1171
+ } catch (_) {}
1172
+ }
1173
+ };
1099
1174
  /**
1100
1175
  * _neutralizeRoot
1101
1176
  *
@@ -1140,11 +1215,7 @@
1140
1215
  const attribute = attributes[i];
1141
1216
  const name = attribute && attribute.name;
1142
1217
  if (typeof name === 'string') {
1143
- try {
1144
- root.removeAttribute(name);
1145
- } catch (_) {
1146
- /* Clobbered removeAttribute — ignore (fail-closed best effort) */
1147
- }
1218
+ _stripAttributeNode(root, attribute, name);
1148
1219
  }
1149
1220
  }
1150
1221
  }
@@ -1152,22 +1223,46 @@
1152
1223
  /**
1153
1224
  * _removeAttribute
1154
1225
  *
1226
+ * Name-based getAttributeNode()/removeAttribute() ASCII-lowercase their
1227
+ * lookup key for HTML elements in an HTML document, so they silently miss an
1228
+ * attribute whose stored qualified name still contains uppercase ASCII
1229
+ * letters. That happens when the node came from a case-preserving source
1230
+ * (an XML/XHTML document imported via importNode(), or createAttributeNS()),
1231
+ * where e.g. `ONERROR` survives the walk: the policy check lowercases to
1232
+ * `onerror` and rejects it, but `removeAttribute('ONERROR')` looks up
1233
+ * `onerror` and finds nothing. Remove the exact Attr node instead, which is
1234
+ * case- and namespace-exact, and fall back to name-based removal only when
1235
+ * the caller could not supply the node.
1236
+ *
1155
1237
  * @param name an Attribute name
1156
1238
  * @param element a DOM node
1239
+ * @param attr the exact Attr node to remove, when the caller has it
1157
1240
  */
1158
- const _removeAttribute = function _removeAttribute(name, element) {
1241
+ const _removeAttribute = function _removeAttribute(name, element, attr) {
1242
+ if (!attr) {
1243
+ try {
1244
+ attr = element.getAttributeNode(name);
1245
+ } catch (_) {
1246
+ attr = null;
1247
+ }
1248
+ }
1249
+ arrayPush(DOMPurify.removed, {
1250
+ attribute: attr || null,
1251
+ from: element
1252
+ });
1159
1253
  try {
1160
- arrayPush(DOMPurify.removed, {
1161
- attribute: element.getAttributeNode(name),
1162
- from: element
1163
- });
1254
+ if (attr) {
1255
+ element.removeAttributeNode(attr);
1256
+ } else {
1257
+ element.removeAttribute(name);
1258
+ }
1164
1259
  } catch (_) {
1165
- arrayPush(DOMPurify.removed, {
1166
- attribute: null,
1167
- from: element
1168
- });
1260
+ /* Clobbered or already-detached node - best-effort fall back to a
1261
+ name-based removal so the "is" handling below still runs. */
1262
+ try {
1263
+ element.removeAttribute(name);
1264
+ } catch (_) {}
1169
1265
  }
1170
- element.removeAttribute(name);
1171
1266
  // We void attribute values for unremovable "is" attributes
1172
1267
  if (name === 'is') {
1173
1268
  if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
@@ -1202,11 +1297,7 @@
1202
1297
  if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
1203
1298
  continue;
1204
1299
  }
1205
- try {
1206
- element.removeAttribute(name);
1207
- } catch (_) {
1208
- /* Clobbered removeAttribute on a doomed node — ignore */
1209
- }
1300
+ _stripAttributeNode(element, attribute, name);
1210
1301
  }
1211
1302
  };
1212
1303
  /**
@@ -1235,7 +1326,7 @@
1235
1326
  const stack = [root];
1236
1327
  while (stack.length > 0) {
1237
1328
  const node = stack.pop();
1238
- const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1329
+ const nodeType = _readNodeType(node);
1239
1330
  if (nodeType === NODE_TYPE.element) {
1240
1331
  _stripDisallowedAttributes(node);
1241
1332
  }
@@ -1282,6 +1373,26 @@
1282
1373
  *
1283
1374
  * @param root the in-place root to sweep
1284
1375
  */
1376
+ /**
1377
+ * Central policy for declarative-partial-updates patch-linkage attributes,
1378
+ * shared by the _neutralizePatchLinkage pre-pass and _isValidAttribute so
1379
+ * the two sites cannot drift: `patchsrc` always links, `for` links
1380
+ * everywhere except on <label>/<output>, and the whole policy is gated on
1381
+ * SAFE_FOR_XML (see the rationale block in _isValidAttribute).
1382
+ *
1383
+ * @param lcName the transformCaseFunc'd attribute name
1384
+ * @param lcTag the transformCaseFunc'd tag name of the carrying element
1385
+ * @return true if the attribute is patch linkage and must be dropped
1386
+ */
1387
+ const _isPatchLinkageAttribute = function _isPatchLinkageAttribute(lcName, lcTag) {
1388
+ if (!SAFE_FOR_XML) {
1389
+ return false;
1390
+ }
1391
+ if (lcName === 'patchsrc') {
1392
+ return true;
1393
+ }
1394
+ return lcName === 'for' && lcTag !== 'label' && lcTag !== 'output';
1395
+ };
1285
1396
  const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
1286
1397
  if (!SAFE_FOR_XML) {
1287
1398
  return;
@@ -1289,7 +1400,7 @@
1289
1400
  const stack = [root];
1290
1401
  while (stack.length > 0) {
1291
1402
  const node = stack.pop();
1292
- const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1403
+ const nodeType = _readNodeType(node);
1293
1404
  /* Remove range markers (the target side of a patch linkage): every
1294
1405
  processing instruction, and any markup-bearing comment. */
1295
1406
  if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
@@ -1303,12 +1414,12 @@
1303
1414
  /* Strip patch-source attributes (the source side) off elements. */
1304
1415
  if (nodeType === NODE_TYPE.element) {
1305
1416
  const element = node;
1306
- const lcTag = transformCaseFunc(getNodeName ? getNodeName(node) : node.nodeName);
1417
+ const lcTag = transformCaseFunc(_readNodeName(node));
1307
1418
  try {
1308
1419
  if (element.hasAttribute && element.hasAttribute('patchsrc')) {
1309
1420
  element.removeAttribute('patchsrc');
1310
1421
  }
1311
- if (element.hasAttribute && element.hasAttribute('for') && lcTag !== 'label' && lcTag !== 'output') {
1422
+ if (element.hasAttribute && element.hasAttribute('for') && _isPatchLinkageAttribute('for', lcTag)) {
1312
1423
  element.removeAttribute('for');
1313
1424
  }
1314
1425
  } catch (_) {
@@ -1570,8 +1681,16 @@
1570
1681
  if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
1571
1682
  return true;
1572
1683
  }
1573
- /* Remove risky CSS construction leading to mXSS */
1574
- if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
1684
+ /* Remove rawtext/literal-text elements whose literal serialization
1685
+ re-opens markup on an HTML reparse - shapes (a) and (b) documented at
1686
+ LITERAL_TEXT_ELEMENTS. Both are invisible to rule 1 above (which
1687
+ self-disables once there is an element child, and whose second probe
1688
+ reads the innerHTML an XML/XHTML document serializes escaped), which
1689
+ is why both probes here read textContent instead. Previously only
1690
+ `style`-with-element-child was covered; every element in
1691
+ LITERAL_TEXT_ELEMENTS shares this literal serialization and is
1692
+ equally affected. */
1693
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && LITERAL_TEXT_ELEMENTS[tagName] && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === 'string' && regExpTest(LITERAL_TEXT_CLOSE[tagName], currentNode.textContent))) {
1575
1694
  return true;
1576
1695
  }
1577
1696
  /* Remove any occurrence of processing instructions */
@@ -1584,6 +1703,30 @@
1584
1703
  }
1585
1704
  return false;
1586
1705
  };
1706
+ /**
1707
+ * Evaluate a CUSTOM_ELEMENT_HANDLING check (a RegExp or a predicate
1708
+ * function, per the validation in _parseConfig) against a name.
1709
+ * Additional arguments are forwarded to predicate functions - the
1710
+ * attributeNameCheck predicate receives the tag name as its second
1711
+ * argument. A null/absent check never matches.
1712
+ *
1713
+ * @param check the configured tagNameCheck / attributeNameCheck value
1714
+ * @param name the name to test
1715
+ * @param args extra arguments forwarded to a predicate function
1716
+ * @return true if the check matches the name
1717
+ */
1718
+ const _matchesNameCheck = function _matchesNameCheck(check, name) {
1719
+ if (check instanceof RegExp) {
1720
+ return regExpTest(check, name);
1721
+ }
1722
+ if (check instanceof Function) {
1723
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1724
+ args[_key - 2] = arguments[_key];
1725
+ }
1726
+ return Boolean(check(name, ...args));
1727
+ }
1728
+ return false;
1729
+ };
1587
1730
  /**
1588
1731
  * Handle a node whose tag is forbidden or not allowlisted: keep
1589
1732
  * allowed custom elements (false return exits _sanitizeElements
@@ -1603,13 +1746,8 @@
1603
1746
  */
1604
1747
  const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName, root) {
1605
1748
  /* Check if we have a custom element to handle */
1606
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
1607
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1608
- return false;
1609
- }
1610
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
1611
- return false;
1612
- }
1749
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1750
+ return false;
1613
1751
  }
1614
1752
  /* Keep content except for bad-listed elements.
1615
1753
  Use the cached prototype getters exclusively — the previous code
@@ -1671,6 +1809,46 @@
1671
1809
  }
1672
1810
  return set === defaultSet || set === setConfigSet ? clone(set) : set;
1673
1811
  };
1812
+ /**
1813
+ * Shared guard for a node that a hook has detached from the walk tree,
1814
+ * used after each element-hook site in _sanitizeElements. Detaching is a
1815
+ * long-standing user pattern (issue #469; draw.io-style foreignObject
1816
+ * filtering). Per the cached, unclobberable parentNode getter the node is
1817
+ * genuinely out of the tree, so it can reach neither the serialized
1818
+ * output nor an IN_PLACE live tree; treat it as removed and stop
1819
+ * processing it. Without this guard, the unsafe-node / namespace checks
1820
+ * would call _forceRemove on a parentless node and hit the REPORT-3
1821
+ * fail-closed throw — which exists for nodes DOMPurify wants gone but
1822
+ * *cannot* detach (clobbered / parentless roots), the opposite of a node
1823
+ * that is already safely gone. The walk root is exempt: a detached
1824
+ * IN_PLACE root is legitimate input and must still be fully sanitized,
1825
+ * and a kill-decision on it must keep hitting the REPORT-3 throw.
1826
+ *
1827
+ * Nodes detached by hooks stay the hook's responsibility for placement:
1828
+ * they are not recorded in DOMPurify.removed, so the post-walk IN_PLACE
1829
+ * pass (which iterates DOMPurify.removed) does not reach them. But a
1830
+ * hook-detached subtree can still hold a queued resource-event handler -
1831
+ * e.g. an <img onload> that began loading when the caller built the live
1832
+ * tree - which fires in page scope after sanitize returns even though the
1833
+ * handler never reached the returned tree. That is the audit-5 F1 hazard,
1834
+ * and the documented node.remove() hook pattern walks straight into it.
1835
+ * So on the IN_PLACE path we neutralize the detached subtree inline,
1836
+ * stripping its non-allow-listed attributes before returning, exactly as
1837
+ * the post-walk pass does for _forceRemove'd subtrees.
1838
+ *
1839
+ * @param currentNode the node a hook may have detached
1840
+ * @param root the current walk root
1841
+ * @return true if the node is detached and now handled, false otherwise
1842
+ */
1843
+ const _handleHookDetachedNode = function _handleHookDetachedNode(currentNode, root) {
1844
+ if (currentNode === root || getParentNode(currentNode) !== null) {
1845
+ return false;
1846
+ }
1847
+ if (IN_PLACE) {
1848
+ _neutralizeSubtree(currentNode);
1849
+ }
1850
+ return true;
1851
+ };
1674
1852
  /**
1675
1853
  * _sanitizeElements
1676
1854
  *
@@ -1680,18 +1858,12 @@
1680
1858
  * @param currentNode to check for permission to exist
1681
1859
  * @return true if node was killed, false if left alive
1682
1860
  */
1683
- // eslint-disable-next-line complexity
1684
1861
  const _sanitizeElements = function _sanitizeElements(currentNode, root) {
1685
1862
  /* Execute a hook if present */
1686
1863
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
1687
- /* A hook may have detached the node - treat it as removed (see the
1688
- detached-node comment after the uponSanitizeElement hook below). On
1689
- the IN_PLACE path, neutralize the detached subtree first so a queued
1690
- resource handler on it cannot fire in page scope after we return. */
1691
- if (currentNode !== root && getParentNode(currentNode) === null) {
1692
- if (IN_PLACE) {
1693
- _neutralizeSubtree(currentNode);
1694
- }
1864
+ /* A hook may have detached the node - treat it as removed (see
1865
+ _handleHookDetachedNode for the full rationale). */
1866
+ if (_handleHookDetachedNode(currentNode, root)) {
1695
1867
  return true;
1696
1868
  }
1697
1869
  /* Check if element is clobbered or can clobber */
@@ -1700,7 +1872,7 @@
1700
1872
  return true;
1701
1873
  }
1702
1874
  /* Now let's check the element's type and name */
1703
- const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
1875
+ const tagName = transformCaseFunc(_readNodeName(currentNode));
1704
1876
  /* Close the pre-walk clone-guard's timing gap: an uponSanitizeElement
1705
1877
  hook may have been installed after that guard sampled the hook arrays
1706
1878
  (e.g. lazily from beforeSanitizeElements), leaving ALLOWED_TAGS still
@@ -1712,34 +1884,9 @@
1712
1884
  tagName,
1713
1885
  allowedTags: ALLOWED_TAGS
1714
1886
  });
1715
- /* A hook may have detached the node from the tree — a long-standing
1716
- user pattern (issue #469; draw.io-style foreignObject filtering).
1717
- Per the cached, unclobberable parentNode getter the node is
1718
- genuinely out of the tree, so it can reach neither the serialized
1719
- output nor an IN_PLACE live tree; treat it as removed and stop
1720
- processing it. Without this guard, the unsafe-node / namespace
1721
- checks below would call _forceRemove on a parentless node and hit
1722
- the REPORT-3 fail-closed throw — which exists for nodes DOMPurify
1723
- wants gone but *cannot* detach (clobbered / parentless roots), the
1724
- opposite of a node that is already safely gone. The walk root is
1725
- exempt: a detached IN_PLACE root is legitimate input and must still
1726
- be fully sanitized, and a kill-decision on it must keep hitting the
1727
- REPORT-3 throw. Nodes detached by hooks stay the hook's
1728
- responsibility for placement: they are not recorded in
1729
- DOMPurify.removed, so the post-walk IN_PLACE pass (which iterates
1730
- DOMPurify.removed) does not reach them. But a hook-detached subtree
1731
- can still hold a queued resource-event handler - e.g. an <img onload>
1732
- that began loading when the caller built the live tree - which fires
1733
- in page scope after sanitize returns even though the handler never
1734
- reached the returned tree. That is the audit-5 F1 hazard, and the
1735
- documented node.remove() hook pattern walks straight into it. So on
1736
- the IN_PLACE path we neutralize the detached subtree inline here,
1737
- stripping its non-allow-listed attributes before returning, exactly
1738
- as the post-walk pass does for _forceRemove'd subtrees. */
1739
- if (currentNode !== root && getParentNode(currentNode) === null) {
1740
- if (IN_PLACE) {
1741
- _neutralizeSubtree(currentNode);
1742
- }
1887
+ /* The uponSanitizeElement hook may have detached the node, exactly as
1888
+ above (see _handleHookDetachedNode for the full rationale). */
1889
+ if (_handleHookDetachedNode(currentNode, root)) {
1743
1890
  return true;
1744
1891
  }
1745
1892
  /* Remove mXSS vectors, processing instructions and risky comments */
@@ -1772,7 +1919,7 @@
1772
1919
  bound and short-circuits to false for any node minted in a different
1773
1920
  realm — letting a foreign-realm element with a forbidden namespace
1774
1921
  slip past the namespace check entirely. */
1775
- const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
1922
+ const nt = _readNodeType(currentNode);
1776
1923
  if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
1777
1924
  _forceRemove(currentNode);
1778
1925
  return true;
@@ -1832,10 +1979,7 @@
1832
1979
  other structural-threat checks and stays overridable, consistent with
1833
1980
  the rest of the codebase. PI range markers are already removed by
1834
1981
  _isUnsafeNode. */
1835
- if (SAFE_FOR_XML && lcName === 'patchsrc') {
1836
- return false;
1837
- }
1838
- if (SAFE_FOR_XML && lcName === 'for' && lcTag !== 'label' && lcTag !== 'output') {
1982
+ if (_isPatchLinkageAttribute(lcName, lcTag)) {
1839
1983
  return false;
1840
1984
  }
1841
1985
  /* Make sure attribute cannot clobber */
@@ -1847,22 +1991,54 @@
1847
1991
  (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1848
1992
  XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1849
1993
  We don't need to check the value; it's always URI safe. */
1850
- if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
1851
- if (
1852
- // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1853
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1854
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1855
- _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)) ||
1856
- // Alternative, second condition checks if it's an `is`-attribute, AND
1857
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1858
- 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 {
1859
- return false;
1860
- }
1861
- /* Check value is safe. First, is attr inert? If so, is safe */
1862
- } 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) {
1863
- return false;
1864
- } else ;
1865
- return true;
1994
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) {
1995
+ return true;
1996
+ }
1997
+ /* Allow valid aria-* attributes, the value is always URI safe */
1998
+ if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) {
1999
+ return true;
2000
+ }
2001
+ /* A name outside the allowlist is acceptable on custom-element terms
2002
+ only. The value checks below are intentionally skipped in that case:
2003
+ if the user supplied a tagNameCheck we also allow derived custom
2004
+ elements using the same test, and attributes passing the configured
2005
+ attributeNameCheck are allowed as custom elements define these at
2006
+ their own discretion. */
2007
+ if (!nameIsPermitted) {
2008
+ return (
2009
+ // Condition a) covers a basically valid custom element tag name whose
2010
+ // tag passes the configured tagNameCheck and whose attribute name
2011
+ // passes the configured attributeNameCheck ...
2012
+ _isBasicCustomElement(lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName, lcTag) ||
2013
+ // Condition b) covers an `is` attribute whose value passes the
2014
+ // configured tagNameCheck while customized built-in elements are
2015
+ // allowed.
2016
+ lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value)
2017
+ );
2018
+ }
2019
+ /* Check value is safe. First, is attr inert? If so, is safe */
2020
+ if (URI_SAFE_ATTRIBUTES[lcName]) {
2021
+ return true;
2022
+ }
2023
+ /* Check no script, data or unknown possibly unsafe URI
2024
+ unless we know URI values are safe for that attribute */
2025
+ if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) {
2026
+ return true;
2027
+ }
2028
+ /* Keep image data URIs alive if src/xlink:href is allowed */
2029
+ /* Further prevent gadget XSS for dynamically built script tags */
2030
+ if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) {
2031
+ return true;
2032
+ }
2033
+ /* Allow unknown protocols: This provides support for links that
2034
+ are handled by protocol handlers which may be unknown ahead of
2035
+ time, e.g. fb:, spotify: */
2036
+ if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) {
2037
+ return true;
2038
+ }
2039
+ /* Only an empty (binary) value remains safe at this point;
2040
+ anything else is presumed unsafe, do not add it back */
2041
+ return !value;
1866
2042
  };
1867
2043
  /* Names the HTML spec reserves from valid-custom-element-name; these must
1868
2044
  * never be treated as basic custom elements even when a permissive
@@ -1987,7 +2163,7 @@
1987
2163
  */
1988
2164
  if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
1989
2165
  // Remove the attribute with this value
1990
- _removeAttribute(name, currentNode);
2166
+ _removeAttribute(name, currentNode, attr);
1991
2167
  // Prefix the value and later re-create the attribute with the sanitized value
1992
2168
  value = SANITIZE_NAMED_PROPS_PREFIX + value;
1993
2169
  }
@@ -1995,12 +2171,12 @@
1995
2171
  // itself the clobbering protection, and re-applying it is incorrect.
1996
2172
  /* Work around a security issue with comments inside attributes */
1997
2173
  if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
1998
- _removeAttribute(name, currentNode);
2174
+ _removeAttribute(name, currentNode, attr);
1999
2175
  continue;
2000
2176
  }
2001
2177
  /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
2002
2178
  if (lcName === 'attributename' && stringMatch(value, 'href')) {
2003
- _removeAttribute(name, currentNode);
2179
+ _removeAttribute(name, currentNode, attr);
2004
2180
  continue;
2005
2181
  }
2006
2182
  /* Did the hooks force-keep the attribute? */
@@ -2009,12 +2185,12 @@
2009
2185
  }
2010
2186
  /* Did the hooks approve of the attribute? */
2011
2187
  if (!hookEvent.keepAttr) {
2012
- _removeAttribute(name, currentNode);
2188
+ _removeAttribute(name, currentNode, attr);
2013
2189
  continue;
2014
2190
  }
2015
2191
  /* Work around a security issue in jQuery 3.0 */
2016
2192
  if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
2017
- _removeAttribute(name, currentNode);
2193
+ _removeAttribute(name, currentNode, attr);
2018
2194
  continue;
2019
2195
  }
2020
2196
  /* Sanitize attribute content to be template-safe */
@@ -2023,7 +2199,7 @@
2023
2199
  }
2024
2200
  /* Is `value` valid for this attribute? */
2025
2201
  if (!_isValidAttribute(lcTag, lcName, value)) {
2026
- _removeAttribute(name, currentNode);
2202
+ _removeAttribute(name, currentNode, attr);
2027
2203
  continue;
2028
2204
  }
2029
2205
  /* Handle attributes that require Trusted Types */
@@ -2070,8 +2246,7 @@
2070
2246
  Walk it explicitly. The nodeType guard avoids reading
2071
2247
  shadowRoot off text / comment / CDATA / PI nodes that the
2072
2248
  iterator also surfaces. */
2073
- const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
2074
- if (shadowNodeType === NODE_TYPE.element) {
2249
+ if (_readNodeType(shadowNode) === NODE_TYPE.element) {
2075
2250
  const innerSr = getShadowRoot(shadowNode);
2076
2251
  if (_isDocumentFragment(innerSr)) {
2077
2252
  _sanitizeAttachedShadowRoots(innerSr);
@@ -2129,7 +2304,7 @@
2129
2304
  continue;
2130
2305
  }
2131
2306
  const node = item.node;
2132
- const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
2307
+ const nodeType = _readNodeType(node);
2133
2308
  const isElement = nodeType === NODE_TYPE.element;
2134
2309
  /* (pushed last → processed first) Children, snapshotted in reverse so
2135
2310
  the first child is processed first. Snapshotting matters because a
@@ -2251,7 +2426,7 @@
2251
2426
  child named "nodeName" on the form root would otherwise shadow
2252
2427
  the property and let this check skip the root-allowlist
2253
2428
  validation entirely. */
2254
- const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
2429
+ const nn = _readNodeName(dirty);
2255
2430
  if (typeof nn === 'string') {
2256
2431
  const tagName = transformCaseFunc(nn);
2257
2432
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {