opentiny 6.9.33 → 6.9.35

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/tinymce.js CHANGED
@@ -15217,14 +15217,65 @@
15217
15217
  }
15218
15218
  };
15219
15219
 
15220
- const {entries, setPrototypeOf, isFrozen, getPrototypeOf, getOwnPropertyDescriptor} = Object;
15221
- let {freeze, seal, create: create$7} = Object;
15222
- let {apply, construct} = typeof Reflect !== 'undefined' && Reflect;
15223
- if (!apply) {
15224
- apply = function apply(fun, thisValue, args) {
15225
- return fun.apply(thisValue, args);
15226
- };
15220
+ /*! @license DOMPurify 3.4.5 | (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.5/LICENSE */
15221
+
15222
+ function _arrayLikeToArray(r, a) {
15223
+ (null == a || a > r.length) && (a = r.length);
15224
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
15225
+ return n;
15226
+ }
15227
+ function _arrayWithHoles(r) {
15228
+ if (Array.isArray(r)) return r;
15229
+ }
15230
+ function _iterableToArrayLimit(r, l) {
15231
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
15232
+ if (null != t) {
15233
+ var e,
15234
+ n,
15235
+ i,
15236
+ u,
15237
+ a = [],
15238
+ f = true,
15239
+ o = false;
15240
+ try {
15241
+ 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);
15242
+ } catch (r) {
15243
+ o = true, n = r;
15244
+ } finally {
15245
+ try {
15246
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
15247
+ } finally {
15248
+ if (o) throw n;
15249
+ }
15250
+ }
15251
+ return a;
15252
+ }
15253
+ }
15254
+ function _nonIterableRest() {
15255
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
15227
15256
  }
15257
+ function _slicedToArray(r, e) {
15258
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
15259
+ }
15260
+ function _unsupportedIterableToArray(r, a) {
15261
+ if (r) {
15262
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
15263
+ var t = {}.toString.call(r).slice(8, -1);
15264
+ 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;
15265
+ }
15266
+ }
15267
+
15268
+ const entries = Object.entries,
15269
+ setPrototypeOf = Object.setPrototypeOf,
15270
+ isFrozen = Object.isFrozen,
15271
+ getPrototypeOf = Object.getPrototypeOf,
15272
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
15273
+ let freeze = Object.freeze,
15274
+ seal = Object.seal,
15275
+ create$7 = Object.create; // eslint-disable-line import/no-mutable-exports
15276
+ let _ref = typeof Reflect !== 'undefined' && Reflect,
15277
+ apply = _ref.apply,
15278
+ construct = _ref.construct;
15228
15279
  if (!freeze) {
15229
15280
  freeze = function freeze(x) {
15230
15281
  return x;
@@ -15235,50 +15286,99 @@
15235
15286
  return x;
15236
15287
  };
15237
15288
  }
15289
+ if (!apply) {
15290
+ apply = function apply(func, thisArg) {
15291
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
15292
+ args[_key - 2] = arguments[_key];
15293
+ }
15294
+ return func.apply(thisArg, args);
15295
+ };
15296
+ }
15238
15297
  if (!construct) {
15239
- construct = function construct(Func, args) {
15298
+ construct = function construct(Func) {
15299
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
15300
+ args[_key2 - 1] = arguments[_key2];
15301
+ }
15240
15302
  return new Func(...args);
15241
15303
  };
15242
15304
  }
15243
15305
  const arrayForEach = unapply(Array.prototype.forEach);
15306
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
15244
15307
  const arrayPop = unapply(Array.prototype.pop);
15245
15308
  const arrayPush = unapply(Array.prototype.push);
15309
+ const arraySplice = unapply(Array.prototype.splice);
15310
+ const arrayIsArray = Array.isArray;
15246
15311
  const stringToLowerCase = unapply(String.prototype.toLowerCase);
15247
15312
  const stringToString = unapply(String.prototype.toString);
15248
15313
  const stringMatch = unapply(String.prototype.match);
15249
15314
  const stringReplace = unapply(String.prototype.replace);
15250
15315
  const stringIndexOf = unapply(String.prototype.indexOf);
15251
15316
  const stringTrim = unapply(String.prototype.trim);
15317
+ const numberToString = unapply(Number.prototype.toString);
15318
+ const booleanToString = unapply(Boolean.prototype.toString);
15319
+ const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
15320
+ const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
15321
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
15322
+ const objectToString = unapply(Object.prototype.toString);
15252
15323
  const regExpTest = unapply(RegExp.prototype.test);
15253
15324
  const typeErrorCreate = unconstruct(TypeError);
15325
+ /**
15326
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
15327
+ *
15328
+ * @param func - The function to be wrapped and called.
15329
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
15330
+ */
15254
15331
  function unapply(func) {
15255
15332
  return function (thisArg) {
15256
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
15257
- args[_key - 1] = arguments[_key];
15333
+ if (thisArg instanceof RegExp) {
15334
+ thisArg.lastIndex = 0;
15335
+ }
15336
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
15337
+ args[_key3 - 1] = arguments[_key3];
15258
15338
  }
15259
15339
  return apply(func, thisArg, args);
15260
15340
  };
15261
15341
  }
15262
- function unconstruct(func) {
15342
+ /**
15343
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
15344
+ *
15345
+ * @param func - The constructor function to be wrapped and called.
15346
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
15347
+ */
15348
+ function unconstruct(Func) {
15263
15349
  return function () {
15264
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
15265
- args[_key2] = arguments[_key2];
15350
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
15351
+ args[_key4] = arguments[_key4];
15266
15352
  }
15267
- return construct(func, args);
15353
+ return construct(Func, args);
15268
15354
  };
15269
15355
  }
15270
- function addToSet(set, array, transformCaseFunc) {
15271
- var _transformCaseFunc;
15272
- transformCaseFunc = (_transformCaseFunc = transformCaseFunc) !== null && _transformCaseFunc !== void 0 ? _transformCaseFunc : stringToLowerCase;
15356
+ /**
15357
+ * Add properties to a lookup table
15358
+ *
15359
+ * @param set - The set to which elements will be added.
15360
+ * @param array - The array containing elements to be added to the set.
15361
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
15362
+ * @returns The modified set with added elements.
15363
+ */
15364
+ function addToSet(set, array) {
15365
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
15273
15366
  if (setPrototypeOf) {
15367
+ // Make 'in' and truthy checks like Boolean(set.constructor)
15368
+ // independent of any properties defined on Object.prototype.
15369
+ // Prevent prototype setters from intercepting set as a this value.
15274
15370
  setPrototypeOf(set, null);
15275
15371
  }
15372
+ if (!arrayIsArray(array)) {
15373
+ return set;
15374
+ }
15276
15375
  let l = array.length;
15277
15376
  while (l--) {
15278
15377
  let element = array[l];
15279
15378
  if (typeof element === 'string') {
15280
15379
  const lcElement = transformCaseFunc(element);
15281
15380
  if (lcElement !== element) {
15381
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
15282
15382
  if (!isFrozen(array)) {
15283
15383
  array[l] = lcElement;
15284
15384
  }
@@ -15289,13 +15389,105 @@
15289
15389
  }
15290
15390
  return set;
15291
15391
  }
15392
+ /**
15393
+ * Clean up an array to harden against CSPP
15394
+ *
15395
+ * @param array - The array to be cleaned.
15396
+ * @returns The cleaned version of the array
15397
+ */
15398
+ function cleanArray(array) {
15399
+ for (let index = 0; index < array.length; index++) {
15400
+ const isPropertyExist = objectHasOwnProperty(array, index);
15401
+ if (!isPropertyExist) {
15402
+ array[index] = null;
15403
+ }
15404
+ }
15405
+ return array;
15406
+ }
15407
+ /**
15408
+ * Shallow clone an object
15409
+ *
15410
+ * @param object - The object to be cloned.
15411
+ * @returns A new object that copies the original.
15412
+ */
15292
15413
  function clone(object) {
15293
15414
  const newObject = create$7(null);
15294
- for (const [property, value] of entries(object)) {
15295
- newObject[property] = value;
15415
+ for (const _ref2 of entries(object)) {
15416
+ var _ref3 = _slicedToArray(_ref2, 2);
15417
+ const property = _ref3[0];
15418
+ const value = _ref3[1];
15419
+ const isPropertyExist = objectHasOwnProperty(object, property);
15420
+ if (isPropertyExist) {
15421
+ if (arrayIsArray(value)) {
15422
+ newObject[property] = cleanArray(value);
15423
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
15424
+ newObject[property] = clone(value);
15425
+ } else {
15426
+ newObject[property] = value;
15427
+ }
15428
+ }
15296
15429
  }
15297
15430
  return newObject;
15298
15431
  }
15432
+ /**
15433
+ * Convert non-node values into strings without depending on direct property access.
15434
+ *
15435
+ * @param value - The value to stringify.
15436
+ * @returns A string representation of the provided value.
15437
+ */
15438
+ function stringifyValue(value) {
15439
+ switch (typeof value) {
15440
+ case 'string':
15441
+ {
15442
+ return value;
15443
+ }
15444
+ case 'number':
15445
+ {
15446
+ return numberToString(value);
15447
+ }
15448
+ case 'boolean':
15449
+ {
15450
+ return booleanToString(value);
15451
+ }
15452
+ case 'bigint':
15453
+ {
15454
+ return bigintToString ? bigintToString(value) : '0';
15455
+ }
15456
+ case 'symbol':
15457
+ {
15458
+ return symbolToString ? symbolToString(value) : 'Symbol()';
15459
+ }
15460
+ case 'undefined':
15461
+ {
15462
+ return objectToString(value);
15463
+ }
15464
+ case 'function':
15465
+ case 'object':
15466
+ {
15467
+ if (value === null) {
15468
+ return objectToString(value);
15469
+ }
15470
+ const valueAsRecord = value;
15471
+ const valueToString = lookupGetter(valueAsRecord, 'toString');
15472
+ if (typeof valueToString === 'function') {
15473
+ const stringified = valueToString(valueAsRecord);
15474
+ return typeof stringified === 'string' ? stringified : objectToString(stringified);
15475
+ }
15476
+ return objectToString(value);
15477
+ }
15478
+ default:
15479
+ {
15480
+ return objectToString(value);
15481
+ }
15482
+ }
15483
+ }
15484
+ /**
15485
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
15486
+ *
15487
+ * @param object - The object to look up the getter function in its prototype chain.
15488
+ * @param prop - The property name for which to find the getter function.
15489
+ * @returns The getter function found in the prototype chain or a fallback function.
15490
+ */
15299
15491
  function lookupGetter(object, prop) {
15300
15492
  while (object !== null) {
15301
15493
  const desc = getOwnPropertyDescriptor(object, prop);
@@ -15309,660 +15501,79 @@
15309
15501
  }
15310
15502
  object = getPrototypeOf(object);
15311
15503
  }
15312
- function fallbackValue(element) {
15313
- console.warn('fallback value for', element);
15504
+ function fallbackValue() {
15314
15505
  return null;
15315
15506
  }
15316
15507
  return fallbackValue;
15317
15508
  }
15318
- const html$1 = freeze([
15319
- 'a',
15320
- 'abbr',
15321
- 'acronym',
15322
- 'address',
15323
- 'area',
15324
- 'article',
15325
- 'aside',
15326
- 'audio',
15327
- 'b',
15328
- 'bdi',
15329
- 'bdo',
15330
- 'big',
15331
- 'blink',
15332
- 'blockquote',
15333
- 'body',
15334
- 'br',
15335
- 'button',
15336
- 'canvas',
15337
- 'caption',
15338
- 'center',
15339
- 'cite',
15340
- 'code',
15341
- 'col',
15342
- 'colgroup',
15343
- 'content',
15344
- 'data',
15345
- 'datalist',
15346
- 'dd',
15347
- 'decorator',
15348
- 'del',
15349
- 'details',
15350
- 'dfn',
15351
- 'dialog',
15352
- 'dir',
15353
- 'div',
15354
- 'dl',
15355
- 'dt',
15356
- 'element',
15357
- 'em',
15358
- 'fieldset',
15359
- 'figcaption',
15360
- 'figure',
15361
- 'font',
15362
- 'footer',
15363
- 'form',
15364
- 'h1',
15365
- 'h2',
15366
- 'h3',
15367
- 'h4',
15368
- 'h5',
15369
- 'h6',
15370
- 'head',
15371
- 'header',
15372
- 'hgroup',
15373
- 'hr',
15374
- 'html',
15375
- 'i',
15376
- 'img',
15377
- 'input',
15378
- 'ins',
15379
- 'kbd',
15380
- 'label',
15381
- 'legend',
15382
- 'li',
15383
- 'main',
15384
- 'map',
15385
- 'mark',
15386
- 'marquee',
15387
- 'menu',
15388
- 'menuitem',
15389
- 'meter',
15390
- 'nav',
15391
- 'nobr',
15392
- 'ol',
15393
- 'optgroup',
15394
- 'option',
15395
- 'output',
15396
- 'p',
15397
- 'picture',
15398
- 'pre',
15399
- 'progress',
15400
- 'q',
15401
- 'rp',
15402
- 'rt',
15403
- 'ruby',
15404
- 's',
15405
- 'samp',
15406
- 'section',
15407
- 'select',
15408
- 'shadow',
15409
- 'small',
15410
- 'source',
15411
- 'spacer',
15412
- 'span',
15413
- 'strike',
15414
- 'strong',
15415
- 'style',
15416
- 'sub',
15417
- 'summary',
15418
- 'sup',
15419
- 'table',
15420
- 'tbody',
15421
- 'td',
15422
- 'template',
15423
- 'textarea',
15424
- 'tfoot',
15425
- 'th',
15426
- 'thead',
15427
- 'time',
15428
- 'tr',
15429
- 'track',
15430
- 'tt',
15431
- 'u',
15432
- 'ul',
15433
- 'var',
15434
- 'video',
15435
- 'wbr'
15436
- ]);
15437
- const svg$1 = freeze([
15438
- 'svg',
15439
- 'a',
15440
- 'altglyph',
15441
- 'altglyphdef',
15442
- 'altglyphitem',
15443
- 'animatecolor',
15444
- 'animatemotion',
15445
- 'animatetransform',
15446
- 'circle',
15447
- 'clippath',
15448
- 'defs',
15449
- 'desc',
15450
- 'ellipse',
15451
- 'filter',
15452
- 'font',
15453
- 'g',
15454
- 'glyph',
15455
- 'glyphref',
15456
- 'hkern',
15457
- 'image',
15458
- 'line',
15459
- 'lineargradient',
15460
- 'marker',
15461
- 'mask',
15462
- 'metadata',
15463
- 'mpath',
15464
- 'path',
15465
- 'pattern',
15466
- 'polygon',
15467
- 'polyline',
15468
- 'radialgradient',
15469
- 'rect',
15470
- 'stop',
15471
- 'style',
15472
- 'switch',
15473
- 'symbol',
15474
- 'text',
15475
- 'textpath',
15476
- 'title',
15477
- 'tref',
15478
- 'tspan',
15479
- 'view',
15480
- 'vkern'
15481
- ]);
15482
- const svgFilters = freeze([
15483
- 'feBlend',
15484
- 'feColorMatrix',
15485
- 'feComponentTransfer',
15486
- 'feComposite',
15487
- 'feConvolveMatrix',
15488
- 'feDiffuseLighting',
15489
- 'feDisplacementMap',
15490
- 'feDistantLight',
15491
- 'feDropShadow',
15492
- 'feFlood',
15493
- 'feFuncA',
15494
- 'feFuncB',
15495
- 'feFuncG',
15496
- 'feFuncR',
15497
- 'feGaussianBlur',
15498
- 'feImage',
15499
- 'feMerge',
15500
- 'feMergeNode',
15501
- 'feMorphology',
15502
- 'feOffset',
15503
- 'fePointLight',
15504
- 'feSpecularLighting',
15505
- 'feSpotLight',
15506
- 'feTile',
15507
- 'feTurbulence'
15508
- ]);
15509
- const svgDisallowed = freeze([
15510
- 'animate',
15511
- 'color-profile',
15512
- 'cursor',
15513
- 'discard',
15514
- 'font-face',
15515
- 'font-face-format',
15516
- 'font-face-name',
15517
- 'font-face-src',
15518
- 'font-face-uri',
15519
- 'foreignobject',
15520
- 'hatch',
15521
- 'hatchpath',
15522
- 'mesh',
15523
- 'meshgradient',
15524
- 'meshpatch',
15525
- 'meshrow',
15526
- 'missing-glyph',
15527
- 'script',
15528
- 'set',
15529
- 'solidcolor',
15530
- 'unknown',
15531
- 'use'
15532
- ]);
15533
- const mathMl$1 = freeze([
15534
- 'math',
15535
- 'menclose',
15536
- 'merror',
15537
- 'mfenced',
15538
- 'mfrac',
15539
- 'mglyph',
15540
- 'mi',
15541
- 'mlabeledtr',
15542
- 'mmultiscripts',
15543
- 'mn',
15544
- 'mo',
15545
- 'mover',
15546
- 'mpadded',
15547
- 'mphantom',
15548
- 'mroot',
15549
- 'mrow',
15550
- 'ms',
15551
- 'mspace',
15552
- 'msqrt',
15553
- 'mstyle',
15554
- 'msub',
15555
- 'msup',
15556
- 'msubsup',
15557
- 'mtable',
15558
- 'mtd',
15559
- 'mtext',
15560
- 'mtr',
15561
- 'munder',
15562
- 'munderover',
15563
- 'mprescripts'
15564
- ]);
15565
- const mathMlDisallowed = freeze([
15566
- 'maction',
15567
- 'maligngroup',
15568
- 'malignmark',
15569
- 'mlongdiv',
15570
- 'mscarries',
15571
- 'mscarry',
15572
- 'msgroup',
15573
- 'mstack',
15574
- 'msline',
15575
- 'msrow',
15576
- 'semantics',
15577
- 'annotation',
15578
- 'annotation-xml',
15579
- 'mprescripts',
15580
- 'none'
15581
- ]);
15509
+ function isRegex(value) {
15510
+ try {
15511
+ regExpTest(value, '');
15512
+ return true;
15513
+ } catch (_unused) {
15514
+ return false;
15515
+ }
15516
+ }
15517
+
15518
+ 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']);
15519
+ 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']);
15520
+ 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']);
15521
+ // List of SVG elements that are disallowed by default.
15522
+ // We still need to know them so that we can do namespace
15523
+ // checks properly in case one wants to add them to
15524
+ // allow-list.
15525
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
15526
+ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
15527
+ // Similarly to SVG, we want to know all MathML elements,
15528
+ // even those that we disallow by default.
15529
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
15582
15530
  const text = freeze(['#text']);
15583
- const html = freeze([
15584
- 'accept',
15585
- 'action',
15586
- 'align',
15587
- 'alt',
15588
- 'autocapitalize',
15589
- 'autocomplete',
15590
- 'autopictureinpicture',
15591
- 'autoplay',
15592
- 'background',
15593
- 'bgcolor',
15594
- 'border',
15595
- 'capture',
15596
- 'cellpadding',
15597
- 'cellspacing',
15598
- 'checked',
15599
- 'cite',
15600
- 'class',
15601
- 'clear',
15602
- 'color',
15603
- 'cols',
15604
- 'colspan',
15605
- 'controls',
15606
- 'controlslist',
15607
- 'coords',
15608
- 'crossorigin',
15609
- 'datetime',
15610
- 'decoding',
15611
- 'default',
15612
- 'dir',
15613
- 'disabled',
15614
- 'disablepictureinpicture',
15615
- 'disableremoteplayback',
15616
- 'download',
15617
- 'draggable',
15618
- 'enctype',
15619
- 'enterkeyhint',
15620
- 'face',
15621
- 'for',
15622
- 'headers',
15623
- 'height',
15624
- 'hidden',
15625
- 'high',
15626
- 'href',
15627
- 'hreflang',
15628
- 'id',
15629
- 'inputmode',
15630
- 'integrity',
15631
- 'ismap',
15632
- 'kind',
15633
- 'label',
15634
- 'lang',
15635
- 'list',
15636
- 'loading',
15637
- 'loop',
15638
- 'low',
15639
- 'max',
15640
- 'maxlength',
15641
- 'media',
15642
- 'method',
15643
- 'min',
15644
- 'minlength',
15645
- 'multiple',
15646
- 'muted',
15647
- 'name',
15648
- 'nonce',
15649
- 'noshade',
15650
- 'novalidate',
15651
- 'nowrap',
15652
- 'open',
15653
- 'optimum',
15654
- 'pattern',
15655
- 'placeholder',
15656
- 'playsinline',
15657
- 'poster',
15658
- 'preload',
15659
- 'pubdate',
15660
- 'radiogroup',
15661
- 'readonly',
15662
- 'rel',
15663
- 'required',
15664
- 'rev',
15665
- 'reversed',
15666
- 'role',
15667
- 'rows',
15668
- 'rowspan',
15669
- 'spellcheck',
15670
- 'scope',
15671
- 'selected',
15672
- 'shape',
15673
- 'size',
15674
- 'sizes',
15675
- 'span',
15676
- 'srclang',
15677
- 'start',
15678
- 'src',
15679
- 'srcset',
15680
- 'step',
15681
- 'style',
15682
- 'summary',
15683
- 'tabindex',
15684
- 'title',
15685
- 'translate',
15686
- 'type',
15687
- 'usemap',
15688
- 'valign',
15689
- 'value',
15690
- 'width',
15691
- 'xmlns',
15692
- 'slot'
15693
- ]);
15694
- const svg = freeze([
15695
- 'accent-height',
15696
- 'accumulate',
15697
- 'additive',
15698
- 'alignment-baseline',
15699
- 'ascent',
15700
- 'attributename',
15701
- 'attributetype',
15702
- 'azimuth',
15703
- 'basefrequency',
15704
- 'baseline-shift',
15705
- 'begin',
15706
- 'bias',
15707
- 'by',
15708
- 'class',
15709
- 'clip',
15710
- 'clippathunits',
15711
- 'clip-path',
15712
- 'clip-rule',
15713
- 'color',
15714
- 'color-interpolation',
15715
- 'color-interpolation-filters',
15716
- 'color-profile',
15717
- 'color-rendering',
15718
- 'cx',
15719
- 'cy',
15720
- 'd',
15721
- 'dx',
15722
- 'dy',
15723
- 'diffuseconstant',
15724
- 'direction',
15725
- 'display',
15726
- 'divisor',
15727
- 'dur',
15728
- 'edgemode',
15729
- 'elevation',
15730
- 'end',
15731
- 'fill',
15732
- 'fill-opacity',
15733
- 'fill-rule',
15734
- 'filter',
15735
- 'filterunits',
15736
- 'flood-color',
15737
- 'flood-opacity',
15738
- 'font-family',
15739
- 'font-size',
15740
- 'font-size-adjust',
15741
- 'font-stretch',
15742
- 'font-style',
15743
- 'font-variant',
15744
- 'font-weight',
15745
- 'fx',
15746
- 'fy',
15747
- 'g1',
15748
- 'g2',
15749
- 'glyph-name',
15750
- 'glyphref',
15751
- 'gradientunits',
15752
- 'gradienttransform',
15753
- 'height',
15754
- 'href',
15755
- 'id',
15756
- 'image-rendering',
15757
- 'in',
15758
- 'in2',
15759
- 'k',
15760
- 'k1',
15761
- 'k2',
15762
- 'k3',
15763
- 'k4',
15764
- 'kerning',
15765
- 'keypoints',
15766
- 'keysplines',
15767
- 'keytimes',
15768
- 'lang',
15769
- 'lengthadjust',
15770
- 'letter-spacing',
15771
- 'kernelmatrix',
15772
- 'kernelunitlength',
15773
- 'lighting-color',
15774
- 'local',
15775
- 'marker-end',
15776
- 'marker-mid',
15777
- 'marker-start',
15778
- 'markerheight',
15779
- 'markerunits',
15780
- 'markerwidth',
15781
- 'maskcontentunits',
15782
- 'maskunits',
15783
- 'max',
15784
- 'mask',
15785
- 'media',
15786
- 'method',
15787
- 'mode',
15788
- 'min',
15789
- 'name',
15790
- 'numoctaves',
15791
- 'offset',
15792
- 'operator',
15793
- 'opacity',
15794
- 'order',
15795
- 'orient',
15796
- 'orientation',
15797
- 'origin',
15798
- 'overflow',
15799
- 'paint-order',
15800
- 'path',
15801
- 'pathlength',
15802
- 'patterncontentunits',
15803
- 'patterntransform',
15804
- 'patternunits',
15805
- 'points',
15806
- 'preservealpha',
15807
- 'preserveaspectratio',
15808
- 'primitiveunits',
15809
- 'r',
15810
- 'rx',
15811
- 'ry',
15812
- 'radius',
15813
- 'refx',
15814
- 'refy',
15815
- 'repeatcount',
15816
- 'repeatdur',
15817
- 'restart',
15818
- 'result',
15819
- 'rotate',
15820
- 'scale',
15821
- 'seed',
15822
- 'shape-rendering',
15823
- 'specularconstant',
15824
- 'specularexponent',
15825
- 'spreadmethod',
15826
- 'startoffset',
15827
- 'stddeviation',
15828
- 'stitchtiles',
15829
- 'stop-color',
15830
- 'stop-opacity',
15831
- 'stroke-dasharray',
15832
- 'stroke-dashoffset',
15833
- 'stroke-linecap',
15834
- 'stroke-linejoin',
15835
- 'stroke-miterlimit',
15836
- 'stroke-opacity',
15837
- 'stroke',
15838
- 'stroke-width',
15839
- 'style',
15840
- 'surfacescale',
15841
- 'systemlanguage',
15842
- 'tabindex',
15843
- 'targetx',
15844
- 'targety',
15845
- 'transform',
15846
- 'transform-origin',
15847
- 'text-anchor',
15848
- 'text-decoration',
15849
- 'text-rendering',
15850
- 'textlength',
15851
- 'type',
15852
- 'u1',
15853
- 'u2',
15854
- 'unicode',
15855
- 'values',
15856
- 'viewbox',
15857
- 'visibility',
15858
- 'version',
15859
- 'vert-adv-y',
15860
- 'vert-origin-x',
15861
- 'vert-origin-y',
15862
- 'width',
15863
- 'word-spacing',
15864
- 'wrap',
15865
- 'writing-mode',
15866
- 'xchannelselector',
15867
- 'ychannelselector',
15868
- 'x',
15869
- 'x1',
15870
- 'x2',
15871
- 'xmlns',
15872
- 'y',
15873
- 'y1',
15874
- 'y2',
15875
- 'z',
15876
- 'zoomandpan'
15877
- ]);
15878
- const mathMl = freeze([
15879
- 'accent',
15880
- 'accentunder',
15881
- 'align',
15882
- 'bevelled',
15883
- 'close',
15884
- 'columnsalign',
15885
- 'columnlines',
15886
- 'columnspan',
15887
- 'denomalign',
15888
- 'depth',
15889
- 'dir',
15890
- 'display',
15891
- 'displaystyle',
15892
- 'encoding',
15893
- 'fence',
15894
- 'frame',
15895
- 'height',
15896
- 'href',
15897
- 'id',
15898
- 'largeop',
15899
- 'length',
15900
- 'linethickness',
15901
- 'lspace',
15902
- 'lquote',
15903
- 'mathbackground',
15904
- 'mathcolor',
15905
- 'mathsize',
15906
- 'mathvariant',
15907
- 'maxsize',
15908
- 'minsize',
15909
- 'movablelimits',
15910
- 'notation',
15911
- 'numalign',
15912
- 'open',
15913
- 'rowalign',
15914
- 'rowlines',
15915
- 'rowspacing',
15916
- 'rowspan',
15917
- 'rspace',
15918
- 'rquote',
15919
- 'scriptlevel',
15920
- 'scriptminsize',
15921
- 'scriptsizemultiplier',
15922
- 'selection',
15923
- 'separator',
15924
- 'separators',
15925
- 'stretchy',
15926
- 'subscriptshift',
15927
- 'supscriptshift',
15928
- 'symmetric',
15929
- 'voffset',
15930
- 'width',
15931
- 'xmlns'
15932
- ]);
15933
- const xml = freeze([
15934
- 'xlink:href',
15935
- 'xml:id',
15936
- 'xlink:title',
15937
- 'xml:space',
15938
- 'xmlns:xlink'
15939
- ]);
15940
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
15941
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
15942
- const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
15943
- const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/);
15944
- const ARIA_ATTR = seal(/^aria-[\-\w]+$/);
15945
- const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
15531
+
15532
+ 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']);
15533
+ 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']);
15534
+ 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']);
15535
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
15536
+
15537
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
15538
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
15539
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
15540
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
15541
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
15542
+ 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
15543
+ );
15946
15544
  const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
15947
- const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g);
15545
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
15546
+ );
15948
15547
  const DOCTYPE_NAME = seal(/^html$/i);
15949
- var EXPRESSIONS = Object.freeze({
15950
- __proto__: null,
15951
- MUSTACHE_EXPR: MUSTACHE_EXPR,
15952
- ERB_EXPR: ERB_EXPR,
15953
- TMPLIT_EXPR: TMPLIT_EXPR,
15954
- DATA_ATTR: DATA_ATTR,
15955
- ARIA_ATTR: ARIA_ATTR,
15956
- IS_ALLOWED_URI: IS_ALLOWED_URI,
15957
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
15958
- ATTR_WHITESPACE: ATTR_WHITESPACE,
15959
- DOCTYPE_NAME: DOCTYPE_NAME
15960
- });
15961
- const getGlobal = () => typeof window === 'undefined' ? null : window;
15548
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
15549
+
15550
+ /* eslint-disable @typescript-eslint/indent */
15551
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
15552
+ const NODE_TYPE = {
15553
+ element: 1,
15554
+ text: 3,
15555
+ // Deprecated
15556
+ progressingInstruction: 7,
15557
+ comment: 8,
15558
+ document: 9};
15559
+ const getGlobal = function getGlobal() {
15560
+ return typeof window === 'undefined' ? null : window;
15561
+ };
15562
+ /**
15563
+ * Creates a no-op policy for internal use only.
15564
+ * Don't export this function outside this module!
15565
+ * @param trustedTypes The policy factory.
15566
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
15567
+ * @return The policy created (or null, if Trusted Types
15568
+ * are not supported or creating the policy failed).
15569
+ */
15962
15570
  const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
15963
15571
  if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
15964
15572
  return null;
15965
15573
  }
15574
+ // Allow the callers to control the unique policy name
15575
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
15576
+ // Policy creation with duplicate names throws in Trusted Types.
15966
15577
  let suffix = null;
15967
15578
  const ATTR_NAME = 'data-tt-policy-suffix';
15968
15579
  if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
@@ -15979,28 +15590,63 @@
15979
15590
  }
15980
15591
  });
15981
15592
  } catch (_) {
15593
+ // Policy creation failed (most likely another DOMPurify script has
15594
+ // already run). Skip creating the policy, as this will only cause errors
15595
+ // if TT are enforced.
15982
15596
  console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
15983
15597
  return null;
15984
15598
  }
15985
15599
  };
15600
+ const _createHooksMap = function _createHooksMap() {
15601
+ return {
15602
+ afterSanitizeAttributes: [],
15603
+ afterSanitizeElements: [],
15604
+ afterSanitizeShadowDOM: [],
15605
+ beforeSanitizeAttributes: [],
15606
+ beforeSanitizeElements: [],
15607
+ beforeSanitizeShadowDOM: [],
15608
+ uponSanitizeAttribute: [],
15609
+ uponSanitizeElement: [],
15610
+ uponSanitizeShadowNode: []
15611
+ };
15612
+ };
15986
15613
  function createDOMPurify() {
15987
15614
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
15988
15615
  const DOMPurify = root => createDOMPurify(root);
15989
- DOMPurify.version = '3.0.5';
15616
+ DOMPurify.version = '3.4.5';
15990
15617
  DOMPurify.removed = [];
15991
- if (!window || !window.document || window.document.nodeType !== 9) {
15618
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
15619
+ // Not running in a browser, provide a factory function
15620
+ // so that you can pass your own Window
15992
15621
  DOMPurify.isSupported = false;
15993
15622
  return DOMPurify;
15994
15623
  }
15995
- const originalDocument = window.document;
15624
+ let document = window.document;
15625
+ const originalDocument = document;
15996
15626
  const currentScript = originalDocument.currentScript;
15997
- let {document} = window;
15998
- const {DocumentFragment, HTMLTemplateElement, Node, Element, NodeFilter, NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap, HTMLFormElement, DOMParser, trustedTypes} = window;
15627
+ const DocumentFragment = window.DocumentFragment,
15628
+ HTMLTemplateElement = window.HTMLTemplateElement,
15629
+ Node = window.Node,
15630
+ Element = window.Element,
15631
+ NodeFilter = window.NodeFilter,
15632
+ _window$NamedNodeMap = window.NamedNodeMap,
15633
+ NamedNodeMap = _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap,
15634
+ HTMLFormElement = window.HTMLFormElement,
15635
+ DOMParser = window.DOMParser,
15636
+ trustedTypes = window.trustedTypes;
15999
15637
  const ElementPrototype = Element.prototype;
16000
15638
  const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
15639
+ const remove = lookupGetter(ElementPrototype, 'remove');
16001
15640
  const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
16002
15641
  const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
16003
15642
  const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
15643
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
15644
+ // As per issue #47, the web-components registry is inherited by a
15645
+ // new document created via createHTMLDocument. As per the spec
15646
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
15647
+ // a new empty registry is used when creating a template contents owner
15648
+ // document, so we use that as our parent document to ensure nothing
15649
+ // is inherited.
16004
15650
  if (typeof HTMLTemplateElement === 'function') {
16005
15651
  const template = document.createElement('template');
16006
15652
  if (template.content && template.content.ownerDocument) {
@@ -16009,28 +15655,43 @@
16009
15655
  }
16010
15656
  let trustedTypesPolicy;
16011
15657
  let emptyHTML = '';
16012
- const {implementation, createNodeIterator, createDocumentFragment, getElementsByTagName} = document;
16013
- const {importNode} = originalDocument;
16014
- let hooks = {};
15658
+ const _document = document,
15659
+ implementation = _document.implementation,
15660
+ createNodeIterator = _document.createNodeIterator,
15661
+ createDocumentFragment = _document.createDocumentFragment,
15662
+ getElementsByTagName = _document.getElementsByTagName;
15663
+ const importNode = originalDocument.importNode;
15664
+ let hooks = _createHooksMap();
15665
+ /**
15666
+ * Expose whether this browser supports running the full DOMPurify.
15667
+ */
16015
15668
  DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
16016
- const {MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR, DATA_ATTR, ARIA_ATTR, IS_SCRIPT_OR_DATA, ATTR_WHITESPACE} = EXPRESSIONS;
16017
- let {IS_ALLOWED_URI: IS_ALLOWED_URI$1} = EXPRESSIONS;
15669
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
15670
+ ERB_EXPR$1 = ERB_EXPR,
15671
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
15672
+ DATA_ATTR$1 = DATA_ATTR,
15673
+ ARIA_ATTR$1 = ARIA_ATTR,
15674
+ IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
15675
+ ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
15676
+ CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
15677
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
15678
+ /**
15679
+ * We consider the elements and attributes below to be safe. Ideally
15680
+ * don't add any new ones but feel free to remove unwanted ones.
15681
+ */
15682
+ /* allowed element names */
16018
15683
  let ALLOWED_TAGS = null;
16019
- const DEFAULT_ALLOWED_TAGS = addToSet({}, [
16020
- ...html$1,
16021
- ...svg$1,
16022
- ...svgFilters,
16023
- ...mathMl$1,
16024
- ...text
16025
- ]);
15684
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
15685
+ /* Allowed attribute names */
16026
15686
  let ALLOWED_ATTR = null;
16027
- const DEFAULT_ALLOWED_ATTR = addToSet({}, [
16028
- ...html,
16029
- ...svg,
16030
- ...mathMl,
16031
- ...xml
16032
- ]);
16033
- let CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
15687
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
15688
+ /*
15689
+ * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
15690
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
15691
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
15692
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
15693
+ */
15694
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create$7(null, {
16034
15695
  tagNameCheck: {
16035
15696
  writable: true,
16036
15697
  configurable: false,
@@ -16050,146 +15711,185 @@
16050
15711
  value: false
16051
15712
  }
16052
15713
  }));
15714
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
16053
15715
  let FORBID_TAGS = null;
15716
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
16054
15717
  let FORBID_ATTR = null;
15718
+ /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
15719
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create$7(null, {
15720
+ tagCheck: {
15721
+ writable: true,
15722
+ configurable: false,
15723
+ enumerable: true,
15724
+ value: null
15725
+ },
15726
+ attributeCheck: {
15727
+ writable: true,
15728
+ configurable: false,
15729
+ enumerable: true,
15730
+ value: null
15731
+ }
15732
+ }));
15733
+ /* Decide if ARIA attributes are okay */
16055
15734
  let ALLOW_ARIA_ATTR = true;
15735
+ /* Decide if custom data attributes are okay */
16056
15736
  let ALLOW_DATA_ATTR = true;
15737
+ /* Decide if unknown protocols are okay */
16057
15738
  let ALLOW_UNKNOWN_PROTOCOLS = false;
15739
+ /* Decide if self-closing tags in attributes are allowed.
15740
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
16058
15741
  let ALLOW_SELF_CLOSE_IN_ATTR = true;
15742
+ /* Output should be safe for common template engines.
15743
+ * This means, DOMPurify removes data attributes, mustaches and ERB
15744
+ */
16059
15745
  let SAFE_FOR_TEMPLATES = false;
15746
+ /* Output should be safe even for XML used within HTML and alike.
15747
+ * This means, DOMPurify removes comments when containing risky content.
15748
+ */
15749
+ let SAFE_FOR_XML = true;
15750
+ /* Decide if document with <html>... should be returned */
16060
15751
  let WHOLE_DOCUMENT = false;
15752
+ /* Track whether config is already set on this instance of DOMPurify. */
16061
15753
  let SET_CONFIG = false;
15754
+ /* Decide if all elements (e.g. style, script) must be children of
15755
+ * document.body. By default, browsers might move them to document.head */
16062
15756
  let FORCE_BODY = false;
15757
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
15758
+ * string (or a TrustedHTML object if Trusted Types are supported).
15759
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
15760
+ */
16063
15761
  let RETURN_DOM = false;
15762
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
15763
+ * string (or a TrustedHTML object if Trusted Types are supported) */
16064
15764
  let RETURN_DOM_FRAGMENT = false;
15765
+ /* Try to return a Trusted Type object instead of a string, return a string in
15766
+ * case Trusted Types are not supported */
16065
15767
  let RETURN_TRUSTED_TYPE = false;
15768
+ /* Output should be free from DOM clobbering attacks?
15769
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
15770
+ */
16066
15771
  let SANITIZE_DOM = true;
15772
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
15773
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
15774
+ *
15775
+ * HTML/DOM spec rules that enable DOM Clobbering:
15776
+ * - Named Access on Window (§7.3.3)
15777
+ * - DOM Tree Accessors (§3.1.5)
15778
+ * - Form Element Parent-Child Relations (§4.10.3)
15779
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
15780
+ * - HTMLCollection (§4.2.10.2)
15781
+ *
15782
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
15783
+ * with a constant string, i.e., `user-content-`
15784
+ */
16067
15785
  let SANITIZE_NAMED_PROPS = false;
16068
15786
  const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
15787
+ /* Keep element content when removing element? */
16069
15788
  let KEEP_CONTENT = true;
15789
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
15790
+ * of importing it into a new Document and returning a sanitized copy */
16070
15791
  let IN_PLACE = false;
15792
+ /* Allow usage of profiles like html, svg and mathMl */
16071
15793
  let USE_PROFILES = {};
15794
+ /* Tags to ignore content of when KEEP_CONTENT is true */
16072
15795
  let FORBID_CONTENTS = null;
16073
- const DEFAULT_FORBID_CONTENTS = addToSet({}, [
16074
- 'annotation-xml',
16075
- 'audio',
16076
- 'colgroup',
16077
- 'desc',
16078
- 'foreignobject',
16079
- 'head',
16080
- 'iframe',
16081
- 'math',
16082
- 'mi',
16083
- 'mn',
16084
- 'mo',
16085
- 'ms',
16086
- 'mtext',
16087
- 'noembed',
16088
- 'noframes',
16089
- 'noscript',
16090
- 'plaintext',
16091
- 'script',
16092
- 'style',
16093
- 'svg',
16094
- 'template',
16095
- 'thead',
16096
- 'title',
16097
- 'video',
16098
- 'xmp'
16099
- ]);
15796
+ 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']);
15797
+ /* Tags that are safe for data: URIs */
16100
15798
  let DATA_URI_TAGS = null;
16101
- const DEFAULT_DATA_URI_TAGS = addToSet({}, [
16102
- 'audio',
16103
- 'video',
16104
- 'img',
16105
- 'source',
16106
- 'image',
16107
- 'track'
16108
- ]);
15799
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
15800
+ /* Attributes safe for values like "javascript:" */
16109
15801
  let URI_SAFE_ATTRIBUTES = null;
16110
- const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
16111
- 'alt',
16112
- 'class',
16113
- 'for',
16114
- 'id',
16115
- 'label',
16116
- 'name',
16117
- 'pattern',
16118
- 'placeholder',
16119
- 'role',
16120
- 'summary',
16121
- 'title',
16122
- 'value',
16123
- 'style',
16124
- 'xmlns'
16125
- ]);
15802
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
16126
15803
  const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
16127
15804
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
16128
15805
  const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
15806
+ /* Document namespace */
16129
15807
  let NAMESPACE = HTML_NAMESPACE;
16130
15808
  let IS_EMPTY_INPUT = false;
15809
+ /* Allowed XHTML+XML namespaces */
16131
15810
  let ALLOWED_NAMESPACES = null;
16132
- const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [
16133
- MATHML_NAMESPACE,
16134
- SVG_NAMESPACE,
16135
- HTML_NAMESPACE
16136
- ], stringToString);
16137
- let PARSER_MEDIA_TYPE;
16138
- const SUPPORTED_PARSER_MEDIA_TYPES = [
16139
- 'application/xhtml+xml',
16140
- 'text/html'
16141
- ];
15811
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
15812
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
15813
+ let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
15814
+ // Certain elements are allowed in both SVG and HTML
15815
+ // namespace. We need to specify them explicitly
15816
+ // so that they don't get erroneously deleted from
15817
+ // HTML namespace.
15818
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
15819
+ /* Parsing of strict XHTML documents */
15820
+ let PARSER_MEDIA_TYPE = null;
15821
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
16142
15822
  const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
16143
- let transformCaseFunc;
15823
+ let transformCaseFunc = null;
15824
+ /* Keep a reference to config to pass to hooks */
16144
15825
  let CONFIG = null;
15826
+ /* Ideally, do not touch anything below this line */
15827
+ /* ______________________________________________ */
16145
15828
  const formElement = document.createElement('form');
16146
15829
  const isRegexOrFunction = function isRegexOrFunction(testValue) {
16147
15830
  return testValue instanceof RegExp || testValue instanceof Function;
16148
15831
  };
16149
- const _parseConfig = function _parseConfig(cfg) {
15832
+ /**
15833
+ * _parseConfig
15834
+ *
15835
+ * @param cfg optional config literal
15836
+ */
15837
+ // eslint-disable-next-line complexity
15838
+ const _parseConfig = function _parseConfig() {
15839
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16150
15840
  if (CONFIG && CONFIG === cfg) {
16151
15841
  return;
16152
15842
  }
15843
+ /* Shield configuration object from tampering */
16153
15844
  if (!cfg || typeof cfg !== 'object') {
16154
15845
  cfg = {};
16155
15846
  }
15847
+ /* Shield configuration object from prototype pollution */
16156
15848
  cfg = clone(cfg);
16157
- PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE;
15849
+ PARSER_MEDIA_TYPE =
15850
+ // eslint-disable-next-line unicorn/prefer-includes
15851
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
15852
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
16158
15853
  transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
16159
- ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
16160
- ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
16161
- ALLOWED_NAMESPACES = 'ALLOWED_NAMESPACES' in cfg ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
16162
- URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
16163
- DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
16164
- FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
16165
- FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
16166
- FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
16167
- USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
16168
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
16169
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
16170
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
16171
- ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
16172
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
16173
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
16174
- RETURN_DOM = cfg.RETURN_DOM || false;
16175
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
16176
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
16177
- FORCE_BODY = cfg.FORCE_BODY || false;
16178
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
16179
- SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
16180
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
16181
- IN_PLACE = cfg.IN_PLACE || false;
16182
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
16183
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
16184
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
16185
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
16186
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
16187
- }
16188
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
16189
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
16190
- }
16191
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
16192
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
15854
+ /* Set configuration parameters */
15855
+ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') && arrayIsArray(cfg.ALLOWED_TAGS) ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
15856
+ ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') && arrayIsArray(cfg.ALLOWED_ATTR) ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
15857
+ ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') && arrayIsArray(cfg.ALLOWED_NAMESPACES) ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
15858
+ URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR) ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
15859
+ DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') && arrayIsArray(cfg.ADD_DATA_URI_TAGS) ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
15860
+ FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS) ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
15861
+ FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') && arrayIsArray(cfg.FORBID_TAGS) ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
15862
+ FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') && arrayIsArray(cfg.FORBID_ATTR) ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
15863
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
15864
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
15865
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
15866
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
15867
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
15868
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
15869
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
15870
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
15871
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
15872
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
15873
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
15874
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
15875
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
15876
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
15877
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
15878
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
15879
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
15880
+ NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
15881
+ MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']); // Default built-in map
15882
+ HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, ['annotation-xml']); // Default built-in map
15883
+ const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create$7(null);
15884
+ CUSTOM_ELEMENT_HANDLING = create$7(null);
15885
+ if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
15886
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
15887
+ }
15888
+ if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
15889
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
15890
+ }
15891
+ if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
15892
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
16193
15893
  }
16194
15894
  if (SAFE_FOR_TEMPLATES) {
16195
15895
  ALLOW_DATA_ATTR = false;
@@ -16197,9 +15897,10 @@
16197
15897
  if (RETURN_DOM_FRAGMENT) {
16198
15898
  RETURN_DOM = true;
16199
15899
  }
15900
+ /* Parse profile info */
16200
15901
  if (USE_PROFILES) {
16201
- ALLOWED_TAGS = addToSet({}, [...text]);
16202
- ALLOWED_ATTR = [];
15902
+ ALLOWED_TAGS = addToSet({}, text);
15903
+ ALLOWED_ATTR = create$7(null);
16203
15904
  if (USE_PROFILES.html === true) {
16204
15905
  addToSet(ALLOWED_TAGS, html$1);
16205
15906
  addToSet(ALLOWED_ATTR, html);
@@ -16220,37 +15921,55 @@
16220
15921
  addToSet(ALLOWED_ATTR, xml);
16221
15922
  }
16222
15923
  }
16223
- if (cfg.ADD_TAGS) {
16224
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
16225
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
15924
+ /* Always reset function-based ADD_TAGS / ADD_ATTR checks to prevent
15925
+ * leaking across calls when switching from function to array config */
15926
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
15927
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
15928
+ /* Merge configuration parameters */
15929
+ if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
15930
+ if (typeof cfg.ADD_TAGS === 'function') {
15931
+ EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
15932
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
15933
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
15934
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
15935
+ }
15936
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
16226
15937
  }
16227
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
16228
15938
  }
16229
- if (cfg.ADD_ATTR) {
16230
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
16231
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
15939
+ if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
15940
+ if (typeof cfg.ADD_ATTR === 'function') {
15941
+ EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
15942
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
15943
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
15944
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
15945
+ }
15946
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
16232
15947
  }
16233
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
16234
15948
  }
16235
- if (cfg.ADD_URI_SAFE_ATTR) {
15949
+ if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
16236
15950
  addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
16237
15951
  }
16238
- if (cfg.FORBID_CONTENTS) {
15952
+ if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
16239
15953
  if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
16240
15954
  FORBID_CONTENTS = clone(FORBID_CONTENTS);
16241
15955
  }
16242
15956
  addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
16243
15957
  }
15958
+ if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
15959
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
15960
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
15961
+ }
15962
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
15963
+ }
15964
+ /* Add #text in case KEEP_CONTENT is set to true */
16244
15965
  if (KEEP_CONTENT) {
16245
15966
  ALLOWED_TAGS['#text'] = true;
16246
15967
  }
15968
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
16247
15969
  if (WHOLE_DOCUMENT) {
16248
- addToSet(ALLOWED_TAGS, [
16249
- 'html',
16250
- 'head',
16251
- 'body'
16252
- ]);
15970
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
16253
15971
  }
15972
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
16254
15973
  if (ALLOWED_TAGS.table) {
16255
15974
  addToSet(ALLOWED_TAGS, ['tbody']);
16256
15975
  delete FORBID_TAGS.tbody;
@@ -16262,48 +15981,42 @@
16262
15981
  if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
16263
15982
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
16264
15983
  }
15984
+ // Overwrite existing TrustedTypes policy.
16265
15985
  trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
15986
+ // Sign local variables required by `sanitize`.
16266
15987
  emptyHTML = trustedTypesPolicy.createHTML('');
16267
15988
  } else {
15989
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
16268
15990
  if (trustedTypesPolicy === undefined) {
16269
15991
  trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
16270
15992
  }
15993
+ // If creating the internal policy succeeded sign internal variables.
16271
15994
  if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
16272
15995
  emptyHTML = trustedTypesPolicy.createHTML('');
16273
15996
  }
16274
15997
  }
15998
+ // Prevent further manipulation of configuration.
15999
+ // Not available in IE8, Safari 5, etc.
16275
16000
  if (freeze) {
16276
16001
  freeze(cfg);
16277
16002
  }
16278
16003
  CONFIG = cfg;
16279
16004
  };
16280
- const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, [
16281
- 'mi',
16282
- 'mo',
16283
- 'mn',
16284
- 'ms',
16285
- 'mtext'
16286
- ]);
16287
- const HTML_INTEGRATION_POINTS = addToSet({}, [
16288
- 'foreignobject',
16289
- 'desc',
16290
- 'title',
16291
- 'annotation-xml'
16292
- ]);
16293
- const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
16294
- 'title',
16295
- 'style',
16296
- 'font',
16297
- 'a',
16298
- 'script'
16299
- ]);
16300
- const ALL_SVG_TAGS = addToSet({}, svg$1);
16301
- addToSet(ALL_SVG_TAGS, svgFilters);
16302
- addToSet(ALL_SVG_TAGS, svgDisallowed);
16303
- const ALL_MATHML_TAGS = addToSet({}, mathMl$1);
16304
- addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
16005
+ /* Keep track of all possible SVG and MathML tags
16006
+ * so that we can perform the namespace checks
16007
+ * correctly. */
16008
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
16009
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
16010
+ /**
16011
+ * @param element a DOM element whose namespace is being checked
16012
+ * @returns Return false if the element has a
16013
+ * namespace that a spec-compliant parser would never
16014
+ * return. Return true otherwise.
16015
+ */
16305
16016
  const _checkValidNamespace = function _checkValidNamespace(element) {
16306
16017
  let parent = getParentNode(element);
16018
+ // In JSDOM, if we're inside shadow DOM, then parentNode
16019
+ // can be null. We just simulate parent in this case.
16307
16020
  if (!parent || !parent.tagName) {
16308
16021
  parent = {
16309
16022
  namespaceURI: NAMESPACE,
@@ -16316,401 +16029,740 @@
16316
16029
  return false;
16317
16030
  }
16318
16031
  if (element.namespaceURI === SVG_NAMESPACE) {
16032
+ // The only way to switch from HTML namespace to SVG
16033
+ // is via <svg>. If it happens via any other tag, then
16034
+ // it should be killed.
16319
16035
  if (parent.namespaceURI === HTML_NAMESPACE) {
16320
16036
  return tagName === 'svg';
16321
16037
  }
16038
+ // The only way to switch from MathML to SVG is via`
16039
+ // svg if parent is either <annotation-xml> or MathML
16040
+ // text integration points.
16322
16041
  if (parent.namespaceURI === MATHML_NAMESPACE) {
16323
16042
  return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
16324
16043
  }
16044
+ // We only allow elements that are defined in SVG
16045
+ // spec. All others are disallowed in SVG namespace.
16325
16046
  return Boolean(ALL_SVG_TAGS[tagName]);
16326
16047
  }
16327
16048
  if (element.namespaceURI === MATHML_NAMESPACE) {
16049
+ // The only way to switch from HTML namespace to MathML
16050
+ // is via <math>. If it happens via any other tag, then
16051
+ // it should be killed.
16328
16052
  if (parent.namespaceURI === HTML_NAMESPACE) {
16329
16053
  return tagName === 'math';
16330
16054
  }
16055
+ // The only way to switch from SVG to MathML is via
16056
+ // <math> and HTML integration points
16331
16057
  if (parent.namespaceURI === SVG_NAMESPACE) {
16332
16058
  return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
16333
16059
  }
16060
+ // We only allow elements that are defined in MathML
16061
+ // spec. All others are disallowed in MathML namespace.
16334
16062
  return Boolean(ALL_MATHML_TAGS[tagName]);
16335
16063
  }
16336
16064
  if (element.namespaceURI === HTML_NAMESPACE) {
16065
+ // The only way to switch from SVG to HTML is via
16066
+ // HTML integration points, and from MathML to HTML
16067
+ // is via MathML text integration points
16337
16068
  if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
16338
16069
  return false;
16339
16070
  }
16340
16071
  if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
16341
16072
  return false;
16342
16073
  }
16074
+ // We disallow tags that are specific for MathML
16075
+ // or SVG and should never appear in HTML namespace
16343
16076
  return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
16344
16077
  }
16078
+ // For XHTML and XML documents that support custom namespaces
16345
16079
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
16346
16080
  return true;
16347
16081
  }
16082
+ // The code should never reach this place (this means
16083
+ // that the element somehow got namespace that is not
16084
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
16085
+ // Return false just in case.
16348
16086
  return false;
16349
16087
  };
16088
+ /**
16089
+ * _forceRemove
16090
+ *
16091
+ * @param node a DOM node
16092
+ */
16350
16093
  const _forceRemove = function _forceRemove(node) {
16351
- arrayPush(DOMPurify.removed, { element: node });
16094
+ arrayPush(DOMPurify.removed, {
16095
+ element: node
16096
+ });
16352
16097
  try {
16353
- node.parentNode.removeChild(node);
16098
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
16099
+ getParentNode(node).removeChild(node);
16354
16100
  } catch (_) {
16355
- node.remove();
16101
+ remove(node);
16356
16102
  }
16357
16103
  };
16358
- const _removeAttribute = function _removeAttribute(name, node) {
16104
+ /**
16105
+ * _removeAttribute
16106
+ *
16107
+ * @param name an Attribute name
16108
+ * @param element a DOM node
16109
+ */
16110
+ const _removeAttribute = function _removeAttribute(name, element) {
16359
16111
  try {
16360
16112
  arrayPush(DOMPurify.removed, {
16361
- attribute: node.getAttributeNode(name),
16362
- from: node
16113
+ attribute: element.getAttributeNode(name),
16114
+ from: element
16363
16115
  });
16364
16116
  } catch (_) {
16365
16117
  arrayPush(DOMPurify.removed, {
16366
16118
  attribute: null,
16367
- from: node
16119
+ from: element
16368
16120
  });
16369
16121
  }
16370
- node.removeAttribute(name);
16371
- if (name === 'is' && !ALLOWED_ATTR[name]) {
16122
+ element.removeAttribute(name);
16123
+ // We void attribute values for unremovable "is" attributes
16124
+ if (name === 'is') {
16372
16125
  if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
16373
16126
  try {
16374
- _forceRemove(node);
16375
- } catch (_) {
16376
- }
16127
+ _forceRemove(element);
16128
+ } catch (_) {}
16377
16129
  } else {
16378
16130
  try {
16379
- node.setAttribute(name, '');
16380
- } catch (_) {
16381
- }
16131
+ element.setAttribute(name, '');
16132
+ } catch (_) {}
16382
16133
  }
16383
16134
  }
16384
16135
  };
16136
+ /**
16137
+ * _initDocument
16138
+ *
16139
+ * @param dirty - a string of dirty markup
16140
+ * @return a DOM, filled with the dirty markup
16141
+ */
16385
16142
  const _initDocument = function _initDocument(dirty) {
16386
- let doc;
16387
- let leadingWhitespace;
16143
+ /* Create a HTML document */
16144
+ let doc = null;
16145
+ let leadingWhitespace = null;
16388
16146
  if (FORCE_BODY) {
16389
16147
  dirty = '<remove></remove>' + dirty;
16390
16148
  } else {
16149
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
16391
16150
  const matches = stringMatch(dirty, /^[\r\n\t ]+/);
16392
16151
  leadingWhitespace = matches && matches[0];
16393
16152
  }
16394
16153
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
16154
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
16395
16155
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
16396
16156
  }
16397
16157
  const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
16158
+ /*
16159
+ * Use the DOMParser API by default, fallback later if needs be
16160
+ * DOMParser not work for svg when has multiple root element.
16161
+ */
16398
16162
  if (NAMESPACE === HTML_NAMESPACE) {
16399
16163
  try {
16400
16164
  doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
16401
- } catch (_) {
16402
- }
16165
+ } catch (_) {}
16403
16166
  }
16167
+ /* Use createHTMLDocument in case DOMParser is not available */
16404
16168
  if (!doc || !doc.documentElement) {
16405
16169
  doc = implementation.createDocument(NAMESPACE, 'template', null);
16406
16170
  try {
16407
16171
  doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
16408
16172
  } catch (_) {
16173
+ // Syntax error if dirtyPayload is invalid xml
16409
16174
  }
16410
16175
  }
16411
16176
  const body = doc.body || doc.documentElement;
16412
16177
  if (dirty && leadingWhitespace) {
16413
16178
  body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
16414
16179
  }
16180
+ /* Work on whole document or just its body */
16415
16181
  if (NAMESPACE === HTML_NAMESPACE) {
16416
16182
  return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
16417
16183
  }
16418
16184
  return WHOLE_DOCUMENT ? doc.documentElement : body;
16419
16185
  };
16420
- const _createIterator = function _createIterator(root) {
16421
- return createNodeIterator.call(root.ownerDocument || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
16422
- };
16423
- const _isClobbered = function _isClobbered(elm) {
16424
- return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
16425
- };
16426
- const _isNode = function _isNode(object) {
16427
- return typeof Node === 'object' ? object instanceof Node : object && typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
16428
- };
16429
- const _executeHook = function _executeHook(entryPoint, currentNode, data) {
16430
- if (!hooks[entryPoint]) {
16431
- return;
16186
+ /**
16187
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
16188
+ *
16189
+ * @param root The root element or node to start traversing on.
16190
+ * @return The created NodeIterator
16191
+ */
16192
+ const _createNodeIterator = function _createNodeIterator(root) {
16193
+ return createNodeIterator.call(root.ownerDocument || root, root,
16194
+ // eslint-disable-next-line no-bitwise
16195
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
16196
+ };
16197
+ /**
16198
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
16199
+ * character data of an element subtree. Used as the final safety net for
16200
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
16201
+ * which only form after text-node normalization (e.g. fragments split across
16202
+ * stripped elements) cannot survive into a template-evaluating framework.
16203
+ *
16204
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
16205
+ * in place rather than round-tripping through innerHTML. This preserves
16206
+ * descendant node references (important for IN_PLACE callers), avoids a
16207
+ * serialize/reparse cycle, and reads literal character data — which means
16208
+ * `<%...%>` in text content matches the ERB regex against its real bytes
16209
+ * instead of the HTML-entity-escaped form innerHTML would produce.
16210
+ *
16211
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
16212
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
16213
+ *
16214
+ * @param node The root element whose character data should be scrubbed.
16215
+ */
16216
+ const _scrubTemplateExpressions = function _scrubTemplateExpressions(node) {
16217
+ node.normalize();
16218
+ const walker = createNodeIterator.call(node.ownerDocument || node, node,
16219
+ // eslint-disable-next-line no-bitwise
16220
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
16221
+ let currentNode = walker.nextNode();
16222
+ while (currentNode) {
16223
+ let data = currentNode.data;
16224
+ arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
16225
+ data = stringReplace(data, expr, ' ');
16226
+ });
16227
+ currentNode.data = data;
16228
+ currentNode = walker.nextNode();
16229
+ }
16230
+ };
16231
+ /**
16232
+ * _isClobbered
16233
+ *
16234
+ * @param element element to check for clobbering attacks
16235
+ * @return true if clobbered, false if safe
16236
+ */
16237
+ const _isClobbered = function _isClobbered(element) {
16238
+ 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');
16239
+ };
16240
+ /**
16241
+ * Checks whether the given object is a DOM node, including nodes that
16242
+ * originate from a different window/realm (e.g. an iframe's
16243
+ * contentDocument). The previous `value instanceof Node` check was
16244
+ * realm-bound: nodes from a different window failed it, causing
16245
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
16246
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
16247
+ *
16248
+ * Implementation: call the cached `nodeType` getter from Node.prototype
16249
+ * directly on the value. This bypasses any clobbered instance property
16250
+ * (e.g. a child element named "nodeType") and works across realms
16251
+ * because the WebIDL `nodeType` getter reads an internal slot that
16252
+ * every real Node has, regardless of which window minted it.
16253
+ *
16254
+ * @param value object to check whether it's a DOM node
16255
+ * @return true if value is a DOM node from any realm
16256
+ */
16257
+ const _isNode = function _isNode(value) {
16258
+ if (!getNodeType || typeof value !== 'object' || value === null) {
16259
+ return false;
16432
16260
  }
16433
- arrayForEach(hooks[entryPoint], hook => {
16261
+ try {
16262
+ return typeof getNodeType(value) === 'number';
16263
+ } catch (_) {
16264
+ return false;
16265
+ }
16266
+ };
16267
+ function _executeHooks(hooks, currentNode, data) {
16268
+ arrayForEach(hooks, hook => {
16434
16269
  hook.call(DOMPurify, currentNode, data, CONFIG);
16435
16270
  });
16436
- };
16271
+ }
16272
+ /**
16273
+ * _sanitizeElements
16274
+ *
16275
+ * @protect nodeName
16276
+ * @protect textContent
16277
+ * @protect removeChild
16278
+ * @param currentNode to check for permission to exist
16279
+ * @return true if node was killed, false if left alive
16280
+ */
16437
16281
  const _sanitizeElements = function _sanitizeElements(currentNode) {
16438
- let content;
16439
- _executeHook('beforeSanitizeElements', currentNode, null);
16282
+ let content = null;
16283
+ /* Execute a hook if present */
16284
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
16285
+ /* Check if element is clobbered or can clobber */
16440
16286
  if (_isClobbered(currentNode)) {
16441
16287
  _forceRemove(currentNode);
16442
16288
  return true;
16443
16289
  }
16290
+ /* Now let's check the element's type and name */
16444
16291
  const tagName = transformCaseFunc(currentNode.nodeName);
16445
- _executeHook('uponSanitizeElement', currentNode, {
16292
+ /* Execute a hook if present */
16293
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
16446
16294
  tagName,
16447
16295
  allowedTags: ALLOWED_TAGS
16448
16296
  });
16449
- if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
16297
+ /* Detect mXSS attempts abusing namespace confusion */
16298
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
16299
+ _forceRemove(currentNode);
16300
+ return true;
16301
+ }
16302
+ /* Remove risky CSS construction leading to mXSS */
16303
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
16304
+ _forceRemove(currentNode);
16305
+ return true;
16306
+ }
16307
+ /* Remove any occurrence of processing instructions */
16308
+ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
16450
16309
  _forceRemove(currentNode);
16451
16310
  return true;
16452
16311
  }
16453
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
16454
- if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
16455
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName))
16312
+ /* Remove any kind of possibly harmful comments */
16313
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
16314
+ _forceRemove(currentNode);
16315
+ return true;
16316
+ }
16317
+ /* Remove element if anything forbids its presence */
16318
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
16319
+ /* Check if we have a custom element to handle */
16320
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
16321
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
16456
16322
  return false;
16457
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName))
16323
+ }
16324
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
16458
16325
  return false;
16326
+ }
16459
16327
  }
16328
+ /* Keep content except for bad-listed elements */
16460
16329
  if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
16461
16330
  const parentNode = getParentNode(currentNode) || currentNode.parentNode;
16462
16331
  const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
16463
16332
  if (childNodes && parentNode) {
16464
16333
  const childCount = childNodes.length;
16465
16334
  for (let i = childCount - 1; i >= 0; --i) {
16466
- parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
16335
+ const childClone = cloneNode(childNodes[i], true);
16336
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
16467
16337
  }
16468
16338
  }
16469
16339
  }
16470
16340
  _forceRemove(currentNode);
16471
16341
  return true;
16472
16342
  }
16343
+ /* Check whether element has a valid namespace */
16473
16344
  if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
16474
16345
  _forceRemove(currentNode);
16475
16346
  return true;
16476
16347
  }
16348
+ /* Make sure that older browsers don't get fallback-tag mXSS */
16477
16349
  if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
16478
16350
  _forceRemove(currentNode);
16479
16351
  return true;
16480
16352
  }
16481
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
16353
+ /* Sanitize element content to be template-safe */
16354
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
16355
+ /* Get the element's text content */
16482
16356
  content = currentNode.textContent;
16483
- content = stringReplace(content, MUSTACHE_EXPR, ' ');
16484
- content = stringReplace(content, ERB_EXPR, ' ');
16485
- content = stringReplace(content, TMPLIT_EXPR, ' ');
16357
+ arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
16358
+ content = stringReplace(content, expr, ' ');
16359
+ });
16486
16360
  if (currentNode.textContent !== content) {
16487
- arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
16361
+ arrayPush(DOMPurify.removed, {
16362
+ element: currentNode.cloneNode()
16363
+ });
16488
16364
  currentNode.textContent = content;
16489
16365
  }
16490
16366
  }
16491
- _executeHook('afterSanitizeElements', currentNode, null);
16367
+ /* Execute a hook if present */
16368
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
16492
16369
  return false;
16493
16370
  };
16371
+ /**
16372
+ * _isValidAttribute
16373
+ *
16374
+ * @param lcTag Lowercase tag name of containing element.
16375
+ * @param lcName Lowercase attribute name.
16376
+ * @param value Attribute value.
16377
+ * @return Returns true if `value` is valid, otherwise false.
16378
+ */
16379
+ // eslint-disable-next-line complexity
16494
16380
  const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
16381
+ /* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
16382
+ if (FORBID_ATTR[lcName]) {
16383
+ return false;
16384
+ }
16385
+ /* Make sure attribute cannot clobber */
16495
16386
  if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
16496
16387
  return false;
16497
16388
  }
16498
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName));
16499
- else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName));
16500
- else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
16501
- if (_basicCustomElementTest(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)) || 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)));
16502
- else {
16389
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
16390
+ /* Allow valid data-* attributes: At least one character after "-"
16391
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
16392
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
16393
+ We don't need to check the value; it's always URI safe. */
16394
+ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted || FORBID_ATTR[lcName]) {
16395
+ if (
16396
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
16397
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
16398
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
16399
+ _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)) ||
16400
+ // Alternative, second condition checks if it's an `is`-attribute, AND
16401
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
16402
+ 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 {
16503
16403
  return false;
16504
16404
  }
16505
- } else if (URI_SAFE_ATTRIBUTES[lcName]);
16506
- else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, '')));
16507
- else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]);
16508
- else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, '')));
16509
- else if (value) {
16405
+ /* Check value is safe. First, is attr inert? If so, is safe */
16406
+ } 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) {
16510
16407
  return false;
16511
16408
  } else ;
16512
16409
  return true;
16513
16410
  };
16514
- const _basicCustomElementTest = function _basicCustomElementTest(tagName) {
16515
- return tagName.indexOf('-') > 0;
16516
- };
16411
+ /* Names the HTML spec reserves from valid-custom-element-name; these must
16412
+ * never be treated as basic custom elements even when a permissive
16413
+ * CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
16414
+ 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']);
16415
+ /**
16416
+ * _isBasicCustomElement
16417
+ * checks if at least one dash is included in tagName, and it's not the first char
16418
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
16419
+ *
16420
+ * @param tagName name of the tag of the node to sanitize
16421
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
16422
+ */
16423
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
16424
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
16425
+ };
16426
+ /**
16427
+ * _sanitizeAttributes
16428
+ *
16429
+ * @protect attributes
16430
+ * @protect nodeName
16431
+ * @protect removeAttribute
16432
+ * @protect setAttribute
16433
+ *
16434
+ * @param currentNode to sanitize
16435
+ */
16517
16436
  const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
16518
- let attr;
16519
- let value;
16520
- let lcName;
16521
- let l;
16522
- _executeHook('beforeSanitizeAttributes', currentNode, null);
16523
- const {attributes} = currentNode;
16524
- if (!attributes) {
16437
+ /* Execute a hook if present */
16438
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
16439
+ const attributes = currentNode.attributes;
16440
+ /* Check if we have attributes; if not we might have a text node */
16441
+ if (!attributes || _isClobbered(currentNode)) {
16525
16442
  return;
16526
16443
  }
16527
16444
  const hookEvent = {
16528
16445
  attrName: '',
16529
16446
  attrValue: '',
16530
16447
  keepAttr: true,
16531
- allowedAttributes: ALLOWED_ATTR
16448
+ allowedAttributes: ALLOWED_ATTR,
16449
+ forceKeepAttr: undefined
16532
16450
  };
16533
- l = attributes.length;
16451
+ let l = attributes.length;
16452
+ /* Go backwards over all attributes; safely remove bad ones */
16534
16453
  while (l--) {
16535
- attr = attributes[l];
16536
- const {name, namespaceURI} = attr;
16537
- value = name === 'value' ? attr.value : stringTrim(attr.value);
16538
- const initValue = value;
16539
- lcName = transformCaseFunc(name);
16454
+ const attr = attributes[l];
16455
+ const name = attr.name,
16456
+ namespaceURI = attr.namespaceURI,
16457
+ attrValue = attr.value;
16458
+ const lcName = transformCaseFunc(name);
16459
+ const initValue = attrValue;
16460
+ let value = name === 'value' ? initValue : stringTrim(initValue);
16461
+ /* Execute a hook if present */
16540
16462
  hookEvent.attrName = lcName;
16541
16463
  hookEvent.attrValue = value;
16542
16464
  hookEvent.keepAttr = true;
16543
- hookEvent.forceKeepAttr = undefined;
16544
- _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
16465
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
16466
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
16545
16467
  value = hookEvent.attrValue;
16468
+ /* Full DOM Clobbering protection via namespace isolation,
16469
+ * Prefix id and name attributes with `user-content-`
16470
+ */
16471
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
16472
+ // Remove the attribute with this value
16473
+ _removeAttribute(name, currentNode);
16474
+ // Prefix the value and later re-create the attribute with the sanitized value
16475
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
16476
+ }
16477
+ // Else: already prefixed, leave the attribute alone — the prefix is
16478
+ // itself the clobbering protection, and re-applying it is incorrect.
16479
+ /* Work around a security issue with comments inside attributes */
16480
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
16481
+ _removeAttribute(name, currentNode);
16482
+ continue;
16483
+ }
16484
+ /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
16485
+ if (lcName === 'attributename' && stringMatch(value, 'href')) {
16486
+ _removeAttribute(name, currentNode);
16487
+ continue;
16488
+ }
16489
+ /* Did the hooks approve of the attribute? */
16546
16490
  if (hookEvent.forceKeepAttr) {
16547
16491
  continue;
16548
16492
  }
16493
+ /* Did the hooks approve of the attribute? */
16549
16494
  if (!hookEvent.keepAttr) {
16550
16495
  _removeAttribute(name, currentNode);
16551
16496
  continue;
16552
16497
  }
16498
+ /* Work around a security issue in jQuery 3.0 */
16553
16499
  if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
16554
16500
  _removeAttribute(name, currentNode);
16555
16501
  continue;
16556
16502
  }
16503
+ /* Sanitize attribute content to be template-safe */
16557
16504
  if (SAFE_FOR_TEMPLATES) {
16558
- value = stringReplace(value, MUSTACHE_EXPR, ' ');
16559
- value = stringReplace(value, ERB_EXPR, ' ');
16560
- value = stringReplace(value, TMPLIT_EXPR, ' ');
16505
+ arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
16506
+ value = stringReplace(value, expr, ' ');
16507
+ });
16561
16508
  }
16509
+ /* Is `value` valid for this attribute? */
16562
16510
  const lcTag = transformCaseFunc(currentNode.nodeName);
16563
16511
  if (!_isValidAttribute(lcTag, lcName, value)) {
16564
16512
  _removeAttribute(name, currentNode);
16565
16513
  continue;
16566
16514
  }
16567
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
16568
- _removeAttribute(name, currentNode);
16569
- value = SANITIZE_NAMED_PROPS_PREFIX + value;
16570
- }
16515
+ /* Handle attributes that require Trusted Types */
16571
16516
  if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
16572
- if (namespaceURI);
16573
- else {
16517
+ if (namespaceURI) ; else {
16574
16518
  switch (trustedTypes.getAttributeType(lcTag, lcName)) {
16575
- case 'TrustedHTML': {
16576
- value = trustedTypesPolicy.createHTML(value);
16577
- break;
16578
- }
16579
- case 'TrustedScriptURL': {
16580
- value = trustedTypesPolicy.createScriptURL(value);
16581
- break;
16582
- }
16519
+ case 'TrustedHTML':
16520
+ {
16521
+ value = trustedTypesPolicy.createHTML(value);
16522
+ break;
16523
+ }
16524
+ case 'TrustedScriptURL':
16525
+ {
16526
+ value = trustedTypesPolicy.createScriptURL(value);
16527
+ break;
16528
+ }
16583
16529
  }
16584
16530
  }
16585
16531
  }
16532
+ /* Handle invalid data-* attribute set by try-catching it */
16586
16533
  if (value !== initValue) {
16587
16534
  try {
16588
16535
  if (namespaceURI) {
16589
16536
  currentNode.setAttributeNS(namespaceURI, name, value);
16590
16537
  } else {
16538
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
16591
16539
  currentNode.setAttribute(name, value);
16592
16540
  }
16541
+ if (_isClobbered(currentNode)) {
16542
+ _forceRemove(currentNode);
16543
+ } else {
16544
+ arrayPop(DOMPurify.removed);
16545
+ }
16593
16546
  } catch (_) {
16594
16547
  _removeAttribute(name, currentNode);
16595
16548
  }
16596
16549
  }
16597
16550
  }
16598
- _executeHook('afterSanitizeAttributes', currentNode, null);
16551
+ /* Execute a hook if present */
16552
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
16599
16553
  };
16600
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
16601
- let shadowNode;
16602
- const shadowIterator = _createIterator(fragment);
16603
- _executeHook('beforeSanitizeShadowDOM', fragment, null);
16554
+ /**
16555
+ * _sanitizeShadowDOM
16556
+ *
16557
+ * @param fragment to iterate over recursively
16558
+ */
16559
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
16560
+ let shadowNode = null;
16561
+ const shadowIterator = _createNodeIterator(fragment);
16562
+ /* Execute a hook if present */
16563
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
16604
16564
  while (shadowNode = shadowIterator.nextNode()) {
16605
- _executeHook('uponSanitizeShadowNode', shadowNode, null);
16606
- if (_sanitizeElements(shadowNode)) {
16607
- continue;
16608
- }
16609
- if (shadowNode.content instanceof DocumentFragment) {
16610
- _sanitizeShadowDOM(shadowNode.content);
16611
- }
16565
+ /* Execute a hook if present */
16566
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
16567
+ /* Sanitize tags and elements */
16568
+ _sanitizeElements(shadowNode);
16569
+ /* Check attributes next */
16612
16570
  _sanitizeAttributes(shadowNode);
16571
+ /* Deep shadow DOM detected */
16572
+ if (shadowNode.content instanceof DocumentFragment) {
16573
+ _sanitizeShadowDOM2(shadowNode.content);
16574
+ }
16575
+ }
16576
+ /* Execute a hook if present */
16577
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
16578
+ };
16579
+ /**
16580
+ * _sanitizeAttachedShadowRoots
16581
+ *
16582
+ * Walks `root` and feeds every attached shadow root we encounter into
16583
+ * the existing _sanitizeShadowDOM pipeline. The default node iterator
16584
+ * does not descend into shadow trees, so nodes inside an attached
16585
+ * shadow root would otherwise be skipped entirely.
16586
+ *
16587
+ * Two real input paths put attached shadow roots in front of us:
16588
+ * 1. IN_PLACE on a DOM node that already has shadow roots attached.
16589
+ * 2. DOM-node input where importNode(dirty, true) deep-clones the
16590
+ * shadow root because it was created with `clonable: true`.
16591
+ *
16592
+ * This pass runs once, up front, so the main iteration loop (and the
16593
+ * existing _sanitizeShadowDOM template-content recursion) stay
16594
+ * untouched — string-input paths are not affected.
16595
+ *
16596
+ * @param root the subtree root to walk for attached shadow roots
16597
+ */
16598
+ const _sanitizeAttachedShadowRoots2 = function _sanitizeAttachedShadowRoots(root) {
16599
+ if (root.nodeType === NODE_TYPE.element && root.shadowRoot instanceof DocumentFragment) {
16600
+ const sr = root.shadowRoot;
16601
+ // Recurse first so that nested shadow roots are reached even if
16602
+ // _sanitizeShadowDOM removes hosts at this level.
16603
+ _sanitizeAttachedShadowRoots2(sr);
16604
+ _sanitizeShadowDOM2(sr);
16605
+ }
16606
+ // Snapshot children before recursing. Sanitization of one subtree
16607
+ // (e.g. via an uponSanitizeShadowNode hook) may detach siblings,
16608
+ // and naive nextSibling traversal would silently skip the rest of
16609
+ // the list once a node is detached.
16610
+ const childNodes = root.childNodes;
16611
+ if (!childNodes) {
16612
+ return;
16613
+ }
16614
+ const snapshot = [];
16615
+ arrayForEach(childNodes, child => {
16616
+ arrayPush(snapshot, child);
16617
+ });
16618
+ for (const child of snapshot) {
16619
+ _sanitizeAttachedShadowRoots2(child);
16613
16620
  }
16614
- _executeHook('afterSanitizeShadowDOM', fragment, null);
16615
16621
  };
16622
+ // eslint-disable-next-line complexity
16616
16623
  DOMPurify.sanitize = function (dirty) {
16617
16624
  let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16618
- let body;
16619
- let importedNode;
16620
- let currentNode;
16621
- let returnNode;
16625
+ let body = null;
16626
+ let importedNode = null;
16627
+ let currentNode = null;
16628
+ let returnNode = null;
16629
+ /* Make sure we have a string to sanitize.
16630
+ DO NOT return early, as this will return the wrong type if
16631
+ the user has requested a DOM object rather than a string */
16622
16632
  IS_EMPTY_INPUT = !dirty;
16623
16633
  if (IS_EMPTY_INPUT) {
16624
16634
  dirty = '<!-->';
16625
16635
  }
16636
+ /* Stringify, in case dirty is an object */
16626
16637
  if (typeof dirty !== 'string' && !_isNode(dirty)) {
16627
- if (typeof dirty.toString === 'function') {
16628
- dirty = dirty.toString();
16629
- if (typeof dirty !== 'string') {
16630
- throw typeErrorCreate('dirty is not a string, aborting');
16631
- }
16632
- } else {
16633
- throw typeErrorCreate('toString is not a function');
16638
+ dirty = stringifyValue(dirty);
16639
+ if (typeof dirty !== 'string') {
16640
+ throw typeErrorCreate('dirty is not a string, aborting');
16634
16641
  }
16635
16642
  }
16643
+ /* Return dirty HTML if DOMPurify cannot run */
16636
16644
  if (!DOMPurify.isSupported) {
16637
16645
  return dirty;
16638
16646
  }
16647
+ /* Assign config vars */
16639
16648
  if (!SET_CONFIG) {
16640
16649
  _parseConfig(cfg);
16641
16650
  }
16651
+ /* Clean up removed elements */
16642
16652
  DOMPurify.removed = [];
16653
+ /* Check if dirty is correctly typed for IN_PLACE */
16643
16654
  if (typeof dirty === 'string') {
16644
16655
  IN_PLACE = false;
16645
16656
  }
16646
16657
  if (IN_PLACE) {
16647
- if (dirty.nodeName) {
16648
- const tagName = transformCaseFunc(dirty.nodeName);
16658
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
16659
+ const nn = dirty.nodeName;
16660
+ if (typeof nn === 'string') {
16661
+ const tagName = transformCaseFunc(nn);
16649
16662
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
16650
16663
  throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
16651
16664
  }
16652
16665
  }
16653
- } else if (dirty instanceof Node) {
16666
+ /* Sanitize attached shadow roots before the main iterator runs.
16667
+ The iterator does not descend into shadow trees. */
16668
+ _sanitizeAttachedShadowRoots2(dirty);
16669
+ } else if (_isNode(dirty)) {
16670
+ /* If dirty is a DOM element, append to an empty document to avoid
16671
+ elements being stripped by the parser */
16654
16672
  body = _initDocument('<!---->');
16655
16673
  importedNode = body.ownerDocument.importNode(dirty, true);
16656
- if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
16674
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
16675
+ /* Node is already a body, use as is */
16657
16676
  body = importedNode;
16658
16677
  } else if (importedNode.nodeName === 'HTML') {
16659
16678
  body = importedNode;
16660
16679
  } else {
16680
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
16661
16681
  body.appendChild(importedNode);
16662
16682
  }
16683
+ /* Clonable shadow roots are deep-cloned by importNode(); sanitize
16684
+ them before the main iterator runs, since the iterator does not
16685
+ descend into shadow trees. */
16686
+ _sanitizeAttachedShadowRoots2(importedNode);
16663
16687
  } else {
16664
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf('<') === -1) {
16688
+ /* Exit directly if we have nothing to do */
16689
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
16690
+ // eslint-disable-next-line unicorn/prefer-includes
16691
+ dirty.indexOf('<') === -1) {
16665
16692
  return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
16666
16693
  }
16694
+ /* Initialize the document to work on */
16667
16695
  body = _initDocument(dirty);
16696
+ /* Check we have a DOM node from the data */
16668
16697
  if (!body) {
16669
16698
  return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
16670
16699
  }
16671
16700
  }
16701
+ /* Remove first element node (ours) if FORCE_BODY is set */
16672
16702
  if (body && FORCE_BODY) {
16673
16703
  _forceRemove(body.firstChild);
16674
16704
  }
16675
- const nodeIterator = _createIterator(IN_PLACE ? dirty : body);
16705
+ /* Get node iterator */
16706
+ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
16707
+ /* Now start iterating over the created document */
16676
16708
  while (currentNode = nodeIterator.nextNode()) {
16677
- if (_sanitizeElements(currentNode)) {
16678
- continue;
16679
- }
16709
+ /* Sanitize tags and elements */
16710
+ _sanitizeElements(currentNode);
16711
+ /* Check attributes next */
16712
+ _sanitizeAttributes(currentNode);
16713
+ /* Shadow DOM detected, sanitize it */
16680
16714
  if (currentNode.content instanceof DocumentFragment) {
16681
- _sanitizeShadowDOM(currentNode.content);
16715
+ _sanitizeShadowDOM2(currentNode.content);
16682
16716
  }
16683
- _sanitizeAttributes(currentNode);
16684
16717
  }
16718
+ /* If we sanitized `dirty` in-place, return it. */
16685
16719
  if (IN_PLACE) {
16720
+ if (SAFE_FOR_TEMPLATES) {
16721
+ _scrubTemplateExpressions(dirty);
16722
+ }
16686
16723
  return dirty;
16687
16724
  }
16725
+ /* Return sanitized string or DOM */
16688
16726
  if (RETURN_DOM) {
16727
+ if (SAFE_FOR_TEMPLATES) {
16728
+ _scrubTemplateExpressions(body);
16729
+ }
16689
16730
  if (RETURN_DOM_FRAGMENT) {
16690
16731
  returnNode = createDocumentFragment.call(body.ownerDocument);
16691
16732
  while (body.firstChild) {
16733
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
16692
16734
  returnNode.appendChild(body.firstChild);
16693
16735
  }
16694
16736
  } else {
16695
16737
  returnNode = body;
16696
16738
  }
16697
16739
  if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
16740
+ /*
16741
+ AdoptNode() is not used because internal state is not reset
16742
+ (e.g. the past names map of a HTMLFormElement), this is safe
16743
+ in theory but we would rather not risk another attack vector.
16744
+ The state that is cloned by importNode() is explicitly defined
16745
+ by the specs.
16746
+ */
16698
16747
  returnNode = importNode.call(originalDocument, returnNode, true);
16699
16748
  }
16700
16749
  return returnNode;
16701
16750
  }
16702
16751
  let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
16752
+ /* Serialize doctype if allowed */
16703
16753
  if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
16704
16754
  serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
16705
16755
  }
16756
+ /* Sanitize final string template-safe */
16706
16757
  if (SAFE_FOR_TEMPLATES) {
16707
- serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR, ' ');
16708
- serializedHTML = stringReplace(serializedHTML, ERB_EXPR, ' ');
16709
- serializedHTML = stringReplace(serializedHTML, TMPLIT_EXPR, ' ');
16758
+ arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
16759
+ serializedHTML = stringReplace(serializedHTML, expr, ' ');
16760
+ });
16710
16761
  }
16711
16762
  return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
16712
16763
  };
16713
- DOMPurify.setConfig = function (cfg) {
16764
+ DOMPurify.setConfig = function () {
16765
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16714
16766
  _parseConfig(cfg);
16715
16767
  SET_CONFIG = true;
16716
16768
  };
@@ -16719,6 +16771,7 @@
16719
16771
  SET_CONFIG = false;
16720
16772
  };
16721
16773
  DOMPurify.isValidAttribute = function (tag, attr, value) {
16774
+ /* Initialize shared config vars if necessary. */
16722
16775
  if (!CONFIG) {
16723
16776
  _parseConfig({});
16724
16777
  }
@@ -16730,21 +16783,20 @@
16730
16783
  if (typeof hookFunction !== 'function') {
16731
16784
  return;
16732
16785
  }
16733
- hooks[entryPoint] = hooks[entryPoint] || [];
16734
16786
  arrayPush(hooks[entryPoint], hookFunction);
16735
16787
  };
16736
- DOMPurify.removeHook = function (entryPoint) {
16737
- if (hooks[entryPoint]) {
16738
- return arrayPop(hooks[entryPoint]);
16788
+ DOMPurify.removeHook = function (entryPoint, hookFunction) {
16789
+ if (hookFunction !== undefined) {
16790
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
16791
+ return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
16739
16792
  }
16793
+ return arrayPop(hooks[entryPoint]);
16740
16794
  };
16741
16795
  DOMPurify.removeHooks = function (entryPoint) {
16742
- if (hooks[entryPoint]) {
16743
- hooks[entryPoint] = [];
16744
- }
16796
+ hooks[entryPoint] = [];
16745
16797
  };
16746
16798
  DOMPurify.removeAllHooks = function () {
16747
- hooks = {};
16799
+ hooks = _createHooksMap();
16748
16800
  };
16749
16801
  return DOMPurify;
16750
16802
  }