purify.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  1. /*! @license DOMPurify 2.3.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.6/LICENSE */
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  4. typeof define === 'function' && define.amd ? define(factory) :
  5. (global = global || self, global.DOMPurify = factory());
  6. }(this, function () { 'use strict';
  7. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  8. var hasOwnProperty = Object.hasOwnProperty,
  9. setPrototypeOf = Object.setPrototypeOf,
  10. isFrozen = Object.isFrozen,
  11. getPrototypeOf = Object.getPrototypeOf,
  12. getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  13. var freeze = Object.freeze,
  14. seal = Object.seal,
  15. create = Object.create; // eslint-disable-line import/no-mutable-exports
  16. var _ref = typeof Reflect !== 'undefined' && Reflect,
  17. apply = _ref.apply,
  18. construct = _ref.construct;
  19. if (!apply) {
  20. apply = function apply(fun, thisValue, args) {
  21. return fun.apply(thisValue, args);
  22. };
  23. }
  24. if (!freeze) {
  25. freeze = function freeze(x) {
  26. return x;
  27. };
  28. }
  29. if (!seal) {
  30. seal = function seal(x) {
  31. return x;
  32. };
  33. }
  34. if (!construct) {
  35. construct = function construct(Func, args) {
  36. return new (Function.prototype.bind.apply(Func, [null].concat(_toConsumableArray(args))))();
  37. };
  38. }
  39. var arrayForEach = unapply(Array.prototype.forEach);
  40. var arrayPop = unapply(Array.prototype.pop);
  41. var arrayPush = unapply(Array.prototype.push);
  42. var stringToLowerCase = unapply(String.prototype.toLowerCase);
  43. var stringMatch = unapply(String.prototype.match);
  44. var stringReplace = unapply(String.prototype.replace);
  45. var stringIndexOf = unapply(String.prototype.indexOf);
  46. var stringTrim = unapply(String.prototype.trim);
  47. var regExpTest = unapply(RegExp.prototype.test);
  48. var typeErrorCreate = unconstruct(TypeError);
  49. function unapply(func) {
  50. return function (thisArg) {
  51. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  52. args[_key - 1] = arguments[_key];
  53. }
  54. return apply(func, thisArg, args);
  55. };
  56. }
  57. function unconstruct(func) {
  58. return function () {
  59. for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  60. args[_key2] = arguments[_key2];
  61. }
  62. return construct(func, args);
  63. };
  64. }
  65. /* Add properties to a lookup table */
  66. function addToSet(set, array) {
  67. if (setPrototypeOf) {
  68. // Make 'in' and truthy checks like Boolean(set.constructor)
  69. // independent of any properties defined on Object.prototype.
  70. // Prevent prototype setters from intercepting set as a this value.
  71. setPrototypeOf(set, null);
  72. }
  73. var l = array.length;
  74. while (l--) {
  75. var element = array[l];
  76. if (typeof element === 'string') {
  77. var lcElement = stringToLowerCase(element);
  78. if (lcElement !== element) {
  79. // Config presets (e.g. tags.js, attrs.js) are immutable.
  80. if (!isFrozen(array)) {
  81. array[l] = lcElement;
  82. }
  83. element = lcElement;
  84. }
  85. }
  86. set[element] = true;
  87. }
  88. return set;
  89. }
  90. /* Shallow clone an object */
  91. function clone(object) {
  92. var newObject = create(null);
  93. var property = void 0;
  94. for (property in object) {
  95. if (apply(hasOwnProperty, object, [property])) {
  96. newObject[property] = object[property];
  97. }
  98. }
  99. return newObject;
  100. }
  101. /* IE10 doesn't support __lookupGetter__ so lets'
  102. * simulate it. It also automatically checks
  103. * if the prop is function or getter and behaves
  104. * accordingly. */
  105. function lookupGetter(object, prop) {
  106. while (object !== null) {
  107. var desc = getOwnPropertyDescriptor(object, prop);
  108. if (desc) {
  109. if (desc.get) {
  110. return unapply(desc.get);
  111. }
  112. if (typeof desc.value === 'function') {
  113. return unapply(desc.value);
  114. }
  115. }
  116. object = getPrototypeOf(object);
  117. }
  118. function fallbackValue(element) {
  119. console.warn('fallback value for', element);
  120. return null;
  121. }
  122. return fallbackValue;
  123. }
  124. var html = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
  125. // SVG
  126. var svg = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
  127. var svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
  128. // List of SVG elements that are disallowed by default.
  129. // We still need to know them so that we can do namespace
  130. // checks properly in case one wants to add them to
  131. // allow-list.
  132. var svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'fedropshadow', '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']);
  133. var mathMl = 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']);
  134. // Similarly to SVG, we want to know all MathML elements,
  135. // even those that we disallow by default.
  136. var mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
  137. var text = freeze(['#text']);
  138. var html$1 = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns', 'slot']);
  139. var svg$1 = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', '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', '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', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', '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', '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']);
  140. var mathMl$1 = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
  141. var xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
  142. // eslint-disable-next-line unicorn/better-regex
  143. var MUSTACHE_EXPR = seal(/\{\{[\s\S]*|[\s\S]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
  144. var ERB_EXPR = seal(/<%[\s\S]*|[\s\S]*%>/gm);
  145. var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
  146. var ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
  147. var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
  148. );
  149. var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
  150. var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
  151. );
  152. var DOCTYPE_NAME = seal(/^html$/i);
  153. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  154. function _toConsumableArray$1(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  155. var getGlobal = function getGlobal() {
  156. return typeof window === 'undefined' ? null : window;
  157. };
  158. /**
  159. * Creates a no-op policy for internal use only.
  160. * Don't export this function outside this module!
  161. * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
  162. * @param {Document} document The document object (to determine policy name suffix)
  163. * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
  164. * are not supported).
  165. */
  166. var _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {
  167. if ((typeof trustedTypes === 'undefined' ? 'undefined' : _typeof(trustedTypes)) !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
  168. return null;
  169. }
  170. // Allow the callers to control the unique policy name
  171. // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
  172. // Policy creation with duplicate names throws in Trusted Types.
  173. var suffix = null;
  174. var ATTR_NAME = 'data-tt-policy-suffix';
  175. if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {
  176. suffix = document.currentScript.getAttribute(ATTR_NAME);
  177. }
  178. var policyName = 'dompurify' + (suffix ? '#' + suffix : '');
  179. try {
  180. return trustedTypes.createPolicy(policyName, {
  181. createHTML: function createHTML(html$$1) {
  182. return html$$1;
  183. }
  184. });
  185. } catch (_) {
  186. // Policy creation failed (most likely another DOMPurify script has
  187. // already run). Skip creating the policy, as this will only cause errors
  188. // if TT are enforced.
  189. console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
  190. return null;
  191. }
  192. };
  193. function createDOMPurify() {
  194. var window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
  195. var DOMPurify = function DOMPurify(root) {
  196. return createDOMPurify(root);
  197. };
  198. /**
  199. * Version label, exposed for easier checks
  200. * if DOMPurify is up to date or not
  201. */
  202. DOMPurify.version = '2.3.6';
  203. /**
  204. * Array of elements that DOMPurify removed during sanitation.
  205. * Empty if nothing was removed.
  206. */
  207. DOMPurify.removed = [];
  208. if (!window || !window.document || window.document.nodeType !== 9) {
  209. // Not running in a browser, provide a factory function
  210. // so that you can pass your own Window
  211. DOMPurify.isSupported = false;
  212. return DOMPurify;
  213. }
  214. var originalDocument = window.document;
  215. var document = window.document;
  216. var DocumentFragment = window.DocumentFragment,
  217. HTMLTemplateElement = window.HTMLTemplateElement,
  218. Node = window.Node,
  219. Element = window.Element,
  220. NodeFilter = window.NodeFilter,
  221. _window$NamedNodeMap = window.NamedNodeMap,
  222. NamedNodeMap = _window$NamedNodeMap === undefined ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap,
  223. HTMLFormElement = window.HTMLFormElement,
  224. DOMParser = window.DOMParser,
  225. trustedTypes = window.trustedTypes;
  226. var ElementPrototype = Element.prototype;
  227. var cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
  228. var getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
  229. var getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
  230. var getParentNode = lookupGetter(ElementPrototype, 'parentNode');
  231. // As per issue #47, the web-components registry is inherited by a
  232. // new document created via createHTMLDocument. As per the spec
  233. // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
  234. // a new empty registry is used when creating a template contents owner
  235. // document, so we use that as our parent document to ensure nothing
  236. // is inherited.
  237. if (typeof HTMLTemplateElement === 'function') {
  238. var template = document.createElement('template');
  239. if (template.content && template.content.ownerDocument) {
  240. document = template.content.ownerDocument;
  241. }
  242. }
  243. var trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
  244. var emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML('') : '';
  245. var _document = document,
  246. implementation = _document.implementation,
  247. createNodeIterator = _document.createNodeIterator,
  248. createDocumentFragment = _document.createDocumentFragment,
  249. getElementsByTagName = _document.getElementsByTagName;
  250. var importNode = originalDocument.importNode;
  251. var documentMode = {};
  252. try {
  253. documentMode = clone(document).documentMode ? document.documentMode : {};
  254. } catch (_) {}
  255. var hooks = {};
  256. /**
  257. * Expose whether this browser supports running the full DOMPurify.
  258. */
  259. DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;
  260. var MUSTACHE_EXPR$$1 = MUSTACHE_EXPR,
  261. ERB_EXPR$$1 = ERB_EXPR,
  262. DATA_ATTR$$1 = DATA_ATTR,
  263. ARIA_ATTR$$1 = ARIA_ATTR,
  264. IS_SCRIPT_OR_DATA$$1 = IS_SCRIPT_OR_DATA,
  265. ATTR_WHITESPACE$$1 = ATTR_WHITESPACE;
  266. var IS_ALLOWED_URI$$1 = IS_ALLOWED_URI;
  267. /**
  268. * We consider the elements and attributes below to be safe. Ideally
  269. * don't add any new ones but feel free to remove unwanted ones.
  270. */
  271. /* allowed element names */
  272. var ALLOWED_TAGS = null;
  273. var DEFAULT_ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray$1(html), _toConsumableArray$1(svg), _toConsumableArray$1(svgFilters), _toConsumableArray$1(mathMl), _toConsumableArray$1(text)));
  274. /* Allowed attribute names */
  275. var ALLOWED_ATTR = null;
  276. var DEFAULT_ALLOWED_ATTR = addToSet({}, [].concat(_toConsumableArray$1(html$1), _toConsumableArray$1(svg$1), _toConsumableArray$1(mathMl$1), _toConsumableArray$1(xml)));
  277. /*
  278. * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
  279. * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
  280. * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
  281. * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
  282. */
  283. var CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
  284. tagNameCheck: {
  285. writable: true,
  286. configurable: false,
  287. enumerable: true,
  288. value: null
  289. },
  290. attributeNameCheck: {
  291. writable: true,
  292. configurable: false,
  293. enumerable: true,
  294. value: null
  295. },
  296. allowCustomizedBuiltInElements: {
  297. writable: true,
  298. configurable: false,
  299. enumerable: true,
  300. value: false
  301. }
  302. }));
  303. /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
  304. var FORBID_TAGS = null;
  305. /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
  306. var FORBID_ATTR = null;
  307. /* Decide if ARIA attributes are okay */
  308. var ALLOW_ARIA_ATTR = true;
  309. /* Decide if custom data attributes are okay */
  310. var ALLOW_DATA_ATTR = true;
  311. /* Decide if unknown protocols are okay */
  312. var ALLOW_UNKNOWN_PROTOCOLS = false;
  313. /* Output should be safe for common template engines.
  314. * This means, DOMPurify removes data attributes, mustaches and ERB
  315. */
  316. var SAFE_FOR_TEMPLATES = false;
  317. /* Decide if document with <html>... should be returned */
  318. var WHOLE_DOCUMENT = false;
  319. /* Track whether config is already set on this instance of DOMPurify. */
  320. var SET_CONFIG = false;
  321. /* Decide if all elements (e.g. style, script) must be children of
  322. * document.body. By default, browsers might move them to document.head */
  323. var FORCE_BODY = false;
  324. /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
  325. * string (or a TrustedHTML object if Trusted Types are supported).
  326. * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
  327. */
  328. var RETURN_DOM = false;
  329. /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
  330. * string (or a TrustedHTML object if Trusted Types are supported) */
  331. var RETURN_DOM_FRAGMENT = false;
  332. /* Try to return a Trusted Type object instead of a string, return a string in
  333. * case Trusted Types are not supported */
  334. var RETURN_TRUSTED_TYPE = false;
  335. /* Output should be free from DOM clobbering attacks? */
  336. var SANITIZE_DOM = true;
  337. /* Keep element content when removing element? */
  338. var KEEP_CONTENT = true;
  339. /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
  340. * of importing it into a new Document and returning a sanitized copy */
  341. var IN_PLACE = false;
  342. /* Allow usage of profiles like html, svg and mathMl */
  343. var USE_PROFILES = {};
  344. /* Tags to ignore content of when KEEP_CONTENT is true */
  345. var FORBID_CONTENTS = null;
  346. var 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']);
  347. /* Tags that are safe for data: URIs */
  348. var DATA_URI_TAGS = null;
  349. var DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
  350. /* Attributes safe for values like "javascript:" */
  351. var URI_SAFE_ATTRIBUTES = null;
  352. var DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
  353. var MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
  354. var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
  355. var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
  356. /* Document namespace */
  357. var NAMESPACE = HTML_NAMESPACE;
  358. var IS_EMPTY_INPUT = false;
  359. /* Parsing of strict XHTML documents */
  360. var PARSER_MEDIA_TYPE = void 0;
  361. var SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
  362. var DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
  363. var transformCaseFunc = void 0;
  364. /* Keep a reference to config to pass to hooks */
  365. var CONFIG = null;
  366. /* Ideally, do not touch anything below this line */
  367. /* ______________________________________________ */
  368. var formElement = document.createElement('form');
  369. var isRegexOrFunction = function isRegexOrFunction(testValue) {
  370. return testValue instanceof RegExp || testValue instanceof Function;
  371. };
  372. /**
  373. * _parseConfig
  374. *
  375. * @param {Object} cfg optional config literal
  376. */
  377. // eslint-disable-next-line complexity
  378. var _parseConfig = function _parseConfig(cfg) {
  379. if (CONFIG && CONFIG === cfg) {
  380. return;
  381. }
  382. /* Shield configuration object from tampering */
  383. if (!cfg || (typeof cfg === 'undefined' ? 'undefined' : _typeof(cfg)) !== 'object') {
  384. cfg = {};
  385. }
  386. /* Shield configuration object from prototype pollution */
  387. cfg = clone(cfg);
  388. /* Set configuration parameters */
  389. ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS) : DEFAULT_ALLOWED_TAGS;
  390. ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR) : DEFAULT_ALLOWED_ATTR;
  391. URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR) : DEFAULT_URI_SAFE_ATTRIBUTES;
  392. DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS) : DEFAULT_DATA_URI_TAGS;
  393. FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS) : DEFAULT_FORBID_CONTENTS;
  394. FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS) : {};
  395. FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR) : {};
  396. USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
  397. ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
  398. ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
  399. ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
  400. SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
  401. WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
  402. RETURN_DOM = cfg.RETURN_DOM || false; // Default false
  403. RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
  404. RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
  405. FORCE_BODY = cfg.FORCE_BODY || false; // Default false
  406. SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
  407. KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
  408. IN_PLACE = cfg.IN_PLACE || false; // Default false
  409. IS_ALLOWED_URI$$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$$1;
  410. NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
  411. if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
  412. CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
  413. }
  414. if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
  415. CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
  416. }
  417. if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
  418. CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
  419. }
  420. PARSER_MEDIA_TYPE =
  421. // eslint-disable-next-line unicorn/prefer-includes
  422. SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE;
  423. // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
  424. transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? function (x) {
  425. return x;
  426. } : stringToLowerCase;
  427. if (SAFE_FOR_TEMPLATES) {
  428. ALLOW_DATA_ATTR = false;
  429. }
  430. if (RETURN_DOM_FRAGMENT) {
  431. RETURN_DOM = true;
  432. }
  433. /* Parse profile info */
  434. if (USE_PROFILES) {
  435. ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray$1(text)));
  436. ALLOWED_ATTR = [];
  437. if (USE_PROFILES.html === true) {
  438. addToSet(ALLOWED_TAGS, html);
  439. addToSet(ALLOWED_ATTR, html$1);
  440. }
  441. if (USE_PROFILES.svg === true) {
  442. addToSet(ALLOWED_TAGS, svg);
  443. addToSet(ALLOWED_ATTR, svg$1);
  444. addToSet(ALLOWED_ATTR, xml);
  445. }
  446. if (USE_PROFILES.svgFilters === true) {
  447. addToSet(ALLOWED_TAGS, svgFilters);
  448. addToSet(ALLOWED_ATTR, svg$1);
  449. addToSet(ALLOWED_ATTR, xml);
  450. }
  451. if (USE_PROFILES.mathMl === true) {
  452. addToSet(ALLOWED_TAGS, mathMl);
  453. addToSet(ALLOWED_ATTR, mathMl$1);
  454. addToSet(ALLOWED_ATTR, xml);
  455. }
  456. }
  457. /* Merge configuration parameters */
  458. if (cfg.ADD_TAGS) {
  459. if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
  460. ALLOWED_TAGS = clone(ALLOWED_TAGS);
  461. }
  462. addToSet(ALLOWED_TAGS, cfg.ADD_TAGS);
  463. }
  464. if (cfg.ADD_ATTR) {
  465. if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
  466. ALLOWED_ATTR = clone(ALLOWED_ATTR);
  467. }
  468. addToSet(ALLOWED_ATTR, cfg.ADD_ATTR);
  469. }
  470. if (cfg.ADD_URI_SAFE_ATTR) {
  471. addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR);
  472. }
  473. if (cfg.FORBID_CONTENTS) {
  474. if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
  475. FORBID_CONTENTS = clone(FORBID_CONTENTS);
  476. }
  477. addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS);
  478. }
  479. /* Add #text in case KEEP_CONTENT is set to true */
  480. if (KEEP_CONTENT) {
  481. ALLOWED_TAGS['#text'] = true;
  482. }
  483. /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
  484. if (WHOLE_DOCUMENT) {
  485. addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
  486. }
  487. /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
  488. if (ALLOWED_TAGS.table) {
  489. addToSet(ALLOWED_TAGS, ['tbody']);
  490. delete FORBID_TAGS.tbody;
  491. }
  492. // Prevent further manipulation of configuration.
  493. // Not available in IE8, Safari 5, etc.
  494. if (freeze) {
  495. freeze(cfg);
  496. }
  497. CONFIG = cfg;
  498. };
  499. var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
  500. var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']);
  501. /* Keep track of all possible SVG and MathML tags
  502. * so that we can perform the namespace checks
  503. * correctly. */
  504. var ALL_SVG_TAGS = addToSet({}, svg);
  505. addToSet(ALL_SVG_TAGS, svgFilters);
  506. addToSet(ALL_SVG_TAGS, svgDisallowed);
  507. var ALL_MATHML_TAGS = addToSet({}, mathMl);
  508. addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
  509. /**
  510. *
  511. *
  512. * @param {Element} element a DOM element whose namespace is being checked
  513. * @returns {boolean} Return false if the element has a
  514. * namespace that a spec-compliant parser would never
  515. * return. Return true otherwise.
  516. */
  517. var _checkValidNamespace = function _checkValidNamespace(element) {
  518. var parent = getParentNode(element);
  519. // In JSDOM, if we're inside shadow DOM, then parentNode
  520. // can be null. We just simulate parent in this case.
  521. if (!parent || !parent.tagName) {
  522. parent = {
  523. namespaceURI: HTML_NAMESPACE,
  524. tagName: 'template'
  525. };
  526. }
  527. var tagName = stringToLowerCase(element.tagName);
  528. var parentTagName = stringToLowerCase(parent.tagName);
  529. if (element.namespaceURI === SVG_NAMESPACE) {
  530. // The only way to switch from HTML namespace to SVG
  531. // is via <svg>. If it happens via any other tag, then
  532. // it should be killed.
  533. if (parent.namespaceURI === HTML_NAMESPACE) {
  534. return tagName === 'svg';
  535. }
  536. // The only way to switch from MathML to SVG is via
  537. // svg if parent is either <annotation-xml> or MathML
  538. // text integration points.
  539. if (parent.namespaceURI === MATHML_NAMESPACE) {
  540. return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
  541. }
  542. // We only allow elements that are defined in SVG
  543. // spec. All others are disallowed in SVG namespace.
  544. return Boolean(ALL_SVG_TAGS[tagName]);
  545. }
  546. if (element.namespaceURI === MATHML_NAMESPACE) {
  547. // The only way to switch from HTML namespace to MathML
  548. // is via <math>. If it happens via any other tag, then
  549. // it should be killed.
  550. if (parent.namespaceURI === HTML_NAMESPACE) {
  551. return tagName === 'math';
  552. }
  553. // The only way to switch from SVG to MathML is via
  554. // <math> and HTML integration points
  555. if (parent.namespaceURI === SVG_NAMESPACE) {
  556. return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
  557. }
  558. // We only allow elements that are defined in MathML
  559. // spec. All others are disallowed in MathML namespace.
  560. return Boolean(ALL_MATHML_TAGS[tagName]);
  561. }
  562. if (element.namespaceURI === HTML_NAMESPACE) {
  563. // The only way to switch from SVG to HTML is via
  564. // HTML integration points, and from MathML to HTML
  565. // is via MathML text integration points
  566. if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
  567. return false;
  568. }
  569. if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
  570. return false;
  571. }
  572. // Certain elements are allowed in both SVG and HTML
  573. // namespace. We need to specify them explicitly
  574. // so that they don't get erronously deleted from
  575. // HTML namespace.
  576. var commonSvgAndHTMLElements = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
  577. // We disallow tags that are specific for MathML
  578. // or SVG and should never appear in HTML namespace
  579. return !ALL_MATHML_TAGS[tagName] && (commonSvgAndHTMLElements[tagName] || !ALL_SVG_TAGS[tagName]);
  580. }
  581. // The code should never reach this place (this means
  582. // that the element somehow got namespace that is not
  583. // HTML, SVG or MathML). Return false just in case.
  584. return false;
  585. };
  586. /**
  587. * _forceRemove
  588. *
  589. * @param {Node} node a DOM node
  590. */
  591. var _forceRemove = function _forceRemove(node) {
  592. arrayPush(DOMPurify.removed, { element: node });
  593. try {
  594. // eslint-disable-next-line unicorn/prefer-dom-node-remove
  595. node.parentNode.removeChild(node);
  596. } catch (_) {
  597. try {
  598. node.outerHTML = emptyHTML;
  599. } catch (_) {
  600. node.remove();
  601. }
  602. }
  603. };
  604. /**
  605. * _removeAttribute
  606. *
  607. * @param {String} name an Attribute name
  608. * @param {Node} node a DOM node
  609. */
  610. var _removeAttribute = function _removeAttribute(name, node) {
  611. try {
  612. arrayPush(DOMPurify.removed, {
  613. attribute: node.getAttributeNode(name),
  614. from: node
  615. });
  616. } catch (_) {
  617. arrayPush(DOMPurify.removed, {
  618. attribute: null,
  619. from: node
  620. });
  621. }
  622. node.removeAttribute(name);
  623. // We void attribute values for unremovable "is"" attributes
  624. if (name === 'is' && !ALLOWED_ATTR[name]) {
  625. if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
  626. try {
  627. _forceRemove(node);
  628. } catch (_) {}
  629. } else {
  630. try {
  631. node.setAttribute(name, '');
  632. } catch (_) {}
  633. }
  634. }
  635. };
  636. /**
  637. * _initDocument
  638. *
  639. * @param {String} dirty a string of dirty markup
  640. * @return {Document} a DOM, filled with the dirty markup
  641. */
  642. var _initDocument = function _initDocument(dirty) {
  643. /* Create a HTML document */
  644. var doc = void 0;
  645. var leadingWhitespace = void 0;
  646. if (FORCE_BODY) {
  647. dirty = '<remove></remove>' + dirty;
  648. } else {
  649. /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
  650. var matches = stringMatch(dirty, /^[\r\n\t ]+/);
  651. leadingWhitespace = matches && matches[0];
  652. }
  653. if (PARSER_MEDIA_TYPE === 'application/xhtml+xml') {
  654. // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
  655. dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
  656. }
  657. var dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
  658. /*
  659. * Use the DOMParser API by default, fallback later if needs be
  660. * DOMParser not work for svg when has multiple root element.
  661. */
  662. if (NAMESPACE === HTML_NAMESPACE) {
  663. try {
  664. doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
  665. } catch (_) {}
  666. }
  667. /* Use createHTMLDocument in case DOMParser is not available */
  668. if (!doc || !doc.documentElement) {
  669. doc = implementation.createDocument(NAMESPACE, 'template', null);
  670. try {
  671. doc.documentElement.innerHTML = IS_EMPTY_INPUT ? '' : dirtyPayload;
  672. } catch (_) {
  673. // Syntax error if dirtyPayload is invalid xml
  674. }
  675. }
  676. var body = doc.body || doc.documentElement;
  677. if (dirty && leadingWhitespace) {
  678. body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
  679. }
  680. /* Work on whole document or just its body */
  681. if (NAMESPACE === HTML_NAMESPACE) {
  682. return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
  683. }
  684. return WHOLE_DOCUMENT ? doc.documentElement : body;
  685. };
  686. /**
  687. * _createIterator
  688. *
  689. * @param {Document} root document/fragment to create iterator for
  690. * @return {Iterator} iterator instance
  691. */
  692. var _createIterator = function _createIterator(root) {
  693. return createNodeIterator.call(root.ownerDocument || root, root,
  694. // eslint-disable-next-line no-bitwise
  695. NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
  696. };
  697. /**
  698. * _isClobbered
  699. *
  700. * @param {Node} elm element to check for clobbering attacks
  701. * @return {Boolean} true if clobbered, false if safe
  702. */
  703. var _isClobbered = function _isClobbered(elm) {
  704. 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');
  705. };
  706. /**
  707. * _isNode
  708. *
  709. * @param {Node} obj object to check whether it's a DOM node
  710. * @return {Boolean} true is object is a DOM node
  711. */
  712. var _isNode = function _isNode(object) {
  713. return (typeof Node === 'undefined' ? 'undefined' : _typeof(Node)) === 'object' ? object instanceof Node : object && (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
  714. };
  715. /**
  716. * _executeHook
  717. * Execute user configurable hooks
  718. *
  719. * @param {String} entryPoint Name of the hook's entry point
  720. * @param {Node} currentNode node to work on with the hook
  721. * @param {Object} data additional hook parameters
  722. */
  723. var _executeHook = function _executeHook(entryPoint, currentNode, data) {
  724. if (!hooks[entryPoint]) {
  725. return;
  726. }
  727. arrayForEach(hooks[entryPoint], function (hook) {
  728. hook.call(DOMPurify, currentNode, data, CONFIG);
  729. });
  730. };
  731. /**
  732. * _sanitizeElements
  733. *
  734. * @protect nodeName
  735. * @protect textContent
  736. * @protect removeChild
  737. *
  738. * @param {Node} currentNode to check for permission to exist
  739. * @return {Boolean} true if node was killed, false if left alive
  740. */
  741. var _sanitizeElements = function _sanitizeElements(currentNode) {
  742. var content = void 0;
  743. /* Execute a hook if present */
  744. _executeHook('beforeSanitizeElements', currentNode, null);
  745. /* Check if element is clobbered or can clobber */
  746. if (_isClobbered(currentNode)) {
  747. _forceRemove(currentNode);
  748. return true;
  749. }
  750. /* Check if tagname contains Unicode */
  751. if (stringMatch(currentNode.nodeName, /[\u0080-\uFFFF]/)) {
  752. _forceRemove(currentNode);
  753. return true;
  754. }
  755. /* Now let's check the element's type and name */
  756. var tagName = transformCaseFunc(currentNode.nodeName);
  757. /* Execute a hook if present */
  758. _executeHook('uponSanitizeElement', currentNode, {
  759. tagName: tagName,
  760. allowedTags: ALLOWED_TAGS
  761. });
  762. /* Detect mXSS attempts abusing namespace confusion */
  763. if (!_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
  764. _forceRemove(currentNode);
  765. return true;
  766. }
  767. /* Mitigate a problem with templates inside select */
  768. if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
  769. _forceRemove(currentNode);
  770. return true;
  771. }
  772. /* Remove element if anything forbids its presence */
  773. if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
  774. /* Check if we have a custom element to handle */
  775. if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
  776. if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
  777. if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
  778. }
  779. /* Keep content except for bad-listed elements */
  780. if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
  781. var parentNode = getParentNode(currentNode) || currentNode.parentNode;
  782. var childNodes = getChildNodes(currentNode) || currentNode.childNodes;
  783. if (childNodes && parentNode) {
  784. var childCount = childNodes.length;
  785. for (var i = childCount - 1; i >= 0; --i) {
  786. parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
  787. }
  788. }
  789. }
  790. _forceRemove(currentNode);
  791. return true;
  792. }
  793. /* Check whether element has a valid namespace */
  794. if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
  795. _forceRemove(currentNode);
  796. return true;
  797. }
  798. if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
  799. _forceRemove(currentNode);
  800. return true;
  801. }
  802. /* Sanitize element content to be template-safe */
  803. if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
  804. /* Get the element's text content */
  805. content = currentNode.textContent;
  806. content = stringReplace(content, MUSTACHE_EXPR$$1, ' ');
  807. content = stringReplace(content, ERB_EXPR$$1, ' ');
  808. if (currentNode.textContent !== content) {
  809. arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
  810. currentNode.textContent = content;
  811. }
  812. }
  813. /* Execute a hook if present */
  814. _executeHook('afterSanitizeElements', currentNode, null);
  815. return false;
  816. };
  817. /**
  818. * _isValidAttribute
  819. *
  820. * @param {string} lcTag Lowercase tag name of containing element.
  821. * @param {string} lcName Lowercase attribute name.
  822. * @param {string} value Attribute value.
  823. * @return {Boolean} Returns true if `value` is valid, otherwise false.
  824. */
  825. // eslint-disable-next-line complexity
  826. var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
  827. /* Make sure attribute cannot clobber */
  828. if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
  829. return false;
  830. }
  831. /* Allow valid data-* attributes: At least one character after "-"
  832. (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
  833. XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
  834. We don't need to check the value; it's always URI safe. */
  835. if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR$$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$$1, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
  836. if (
  837. // First condition does a very basic check if a) it's basically a valid custom element tagname AND
  838. // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
  839. // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
  840. _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)) ||
  841. // Alternative, second condition checks if it's an `is`-attribute, AND
  842. // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
  843. 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 {
  844. return false;
  845. }
  846. /* Check value is safe. First, is attr inert? If so, is safe */
  847. } 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) ; else {
  848. return false;
  849. }
  850. return true;
  851. };
  852. /**
  853. * _basicCustomElementCheck
  854. * checks if at least one dash is included in tagName, and it's not the first char
  855. * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
  856. * @param {string} tagName name of the tag of the node to sanitize
  857. */
  858. var _basicCustomElementTest = function _basicCustomElementTest(tagName) {
  859. return tagName.indexOf('-') > 0;
  860. };
  861. /**
  862. * _sanitizeAttributes
  863. *
  864. * @protect attributes
  865. * @protect nodeName
  866. * @protect removeAttribute
  867. * @protect setAttribute
  868. *
  869. * @param {Node} currentNode to sanitize
  870. */
  871. var _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
  872. var attr = void 0;
  873. var value = void 0;
  874. var lcName = void 0;
  875. var l = void 0;
  876. /* Execute a hook if present */
  877. _executeHook('beforeSanitizeAttributes', currentNode, null);
  878. var attributes = currentNode.attributes;
  879. /* Check if we have attributes; if not we might have a text node */
  880. if (!attributes) {
  881. return;
  882. }
  883. var hookEvent = {
  884. attrName: '',
  885. attrValue: '',
  886. keepAttr: true,
  887. allowedAttributes: ALLOWED_ATTR
  888. };
  889. l = attributes.length;
  890. /* Go backwards over all attributes; safely remove bad ones */
  891. while (l--) {
  892. attr = attributes[l];
  893. var _attr = attr,
  894. name = _attr.name,
  895. namespaceURI = _attr.namespaceURI;
  896. value = stringTrim(attr.value);
  897. lcName = transformCaseFunc(name);
  898. /* Execute a hook if present */
  899. hookEvent.attrName = lcName;
  900. hookEvent.attrValue = value;
  901. hookEvent.keepAttr = true;
  902. hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
  903. _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
  904. value = hookEvent.attrValue;
  905. /* Did the hooks approve of the attribute? */
  906. if (hookEvent.forceKeepAttr) {
  907. continue;
  908. }
  909. /* Remove attribute */
  910. _removeAttribute(name, currentNode);
  911. /* Did the hooks approve of the attribute? */
  912. if (!hookEvent.keepAttr) {
  913. continue;
  914. }
  915. /* Work around a security issue in jQuery 3.0 */
  916. if (regExpTest(/\/>/i, value)) {
  917. _removeAttribute(name, currentNode);
  918. continue;
  919. }
  920. /* Sanitize attribute content to be template-safe */
  921. if (SAFE_FOR_TEMPLATES) {
  922. value = stringReplace(value, MUSTACHE_EXPR$$1, ' ');
  923. value = stringReplace(value, ERB_EXPR$$1, ' ');
  924. }
  925. /* Is `value` valid for this attribute? */
  926. var lcTag = transformCaseFunc(currentNode.nodeName);
  927. if (!_isValidAttribute(lcTag, lcName, value)) {
  928. continue;
  929. }
  930. /* Handle invalid data-* attribute set by try-catching it */
  931. try {
  932. if (namespaceURI) {
  933. currentNode.setAttributeNS(namespaceURI, name, value);
  934. } else {
  935. /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
  936. currentNode.setAttribute(name, value);
  937. }
  938. arrayPop(DOMPurify.removed);
  939. } catch (_) {}
  940. }
  941. /* Execute a hook if present */
  942. _executeHook('afterSanitizeAttributes', currentNode, null);
  943. };
  944. /**
  945. * _sanitizeShadowDOM
  946. *
  947. * @param {DocumentFragment} fragment to iterate over recursively
  948. */
  949. var _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
  950. var shadowNode = void 0;
  951. var shadowIterator = _createIterator(fragment);
  952. /* Execute a hook if present */
  953. _executeHook('beforeSanitizeShadowDOM', fragment, null);
  954. while (shadowNode = shadowIterator.nextNode()) {
  955. /* Execute a hook if present */
  956. _executeHook('uponSanitizeShadowNode', shadowNode, null);
  957. /* Sanitize tags and elements */
  958. if (_sanitizeElements(shadowNode)) {
  959. continue;
  960. }
  961. /* Deep shadow DOM detected */
  962. if (shadowNode.content instanceof DocumentFragment) {
  963. _sanitizeShadowDOM(shadowNode.content);
  964. }
  965. /* Check attributes, sanitize if necessary */
  966. _sanitizeAttributes(shadowNode);
  967. }
  968. /* Execute a hook if present */
  969. _executeHook('afterSanitizeShadowDOM', fragment, null);
  970. };
  971. /**
  972. * Sanitize
  973. * Public method providing core sanitation functionality
  974. *
  975. * @param {String|Node} dirty string or DOM node
  976. * @param {Object} configuration object
  977. */
  978. // eslint-disable-next-line complexity
  979. DOMPurify.sanitize = function (dirty, cfg) {
  980. var body = void 0;
  981. var importedNode = void 0;
  982. var currentNode = void 0;
  983. var oldNode = void 0;
  984. var returnNode = void 0;
  985. /* Make sure we have a string to sanitize.
  986. DO NOT return early, as this will return the wrong type if
  987. the user has requested a DOM object rather than a string */
  988. IS_EMPTY_INPUT = !dirty;
  989. if (IS_EMPTY_INPUT) {
  990. dirty = '<!-->';
  991. }
  992. /* Stringify, in case dirty is an object */
  993. if (typeof dirty !== 'string' && !_isNode(dirty)) {
  994. // eslint-disable-next-line no-negated-condition
  995. if (typeof dirty.toString !== 'function') {
  996. throw typeErrorCreate('toString is not a function');
  997. } else {
  998. dirty = dirty.toString();
  999. if (typeof dirty !== 'string') {
  1000. throw typeErrorCreate('dirty is not a string, aborting');
  1001. }
  1002. }
  1003. }
  1004. /* Check we can run. Otherwise fall back or ignore */
  1005. if (!DOMPurify.isSupported) {
  1006. if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
  1007. if (typeof dirty === 'string') {
  1008. return window.toStaticHTML(dirty);
  1009. }
  1010. if (_isNode(dirty)) {
  1011. return window.toStaticHTML(dirty.outerHTML);
  1012. }
  1013. }
  1014. return dirty;
  1015. }
  1016. /* Assign config vars */
  1017. if (!SET_CONFIG) {
  1018. _parseConfig(cfg);
  1019. }
  1020. /* Clean up removed elements */
  1021. DOMPurify.removed = [];
  1022. /* Check if dirty is correctly typed for IN_PLACE */
  1023. if (typeof dirty === 'string') {
  1024. IN_PLACE = false;
  1025. }
  1026. if (IN_PLACE) {
  1027. /* Do some early pre-sanitization to avoid unsafe root nodes */
  1028. if (dirty.nodeName) {
  1029. var tagName = transformCaseFunc(dirty.nodeName);
  1030. if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
  1031. throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
  1032. }
  1033. }
  1034. } else if (dirty instanceof Node) {
  1035. /* If dirty is a DOM element, append to an empty document to avoid
  1036. elements being stripped by the parser */
  1037. body = _initDocument('<!---->');
  1038. importedNode = body.ownerDocument.importNode(dirty, true);
  1039. if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
  1040. /* Node is already a body, use as is */
  1041. body = importedNode;
  1042. } else if (importedNode.nodeName === 'HTML') {
  1043. body = importedNode;
  1044. } else {
  1045. // eslint-disable-next-line unicorn/prefer-dom-node-append
  1046. body.appendChild(importedNode);
  1047. }
  1048. } else {
  1049. /* Exit directly if we have nothing to do */
  1050. if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
  1051. // eslint-disable-next-line unicorn/prefer-includes
  1052. dirty.indexOf('<') === -1) {
  1053. return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
  1054. }
  1055. /* Initialize the document to work on */
  1056. body = _initDocument(dirty);
  1057. /* Check we have a DOM node from the data */
  1058. if (!body) {
  1059. return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
  1060. }
  1061. }
  1062. /* Remove first element node (ours) if FORCE_BODY is set */
  1063. if (body && FORCE_BODY) {
  1064. _forceRemove(body.firstChild);
  1065. }
  1066. /* Get node iterator */
  1067. var nodeIterator = _createIterator(IN_PLACE ? dirty : body);
  1068. /* Now start iterating over the created document */
  1069. while (currentNode = nodeIterator.nextNode()) {
  1070. /* Fix IE's strange behavior with manipulated textNodes #89 */
  1071. if (currentNode.nodeType === 3 && currentNode === oldNode) {
  1072. continue;
  1073. }
  1074. /* Sanitize tags and elements */
  1075. if (_sanitizeElements(currentNode)) {
  1076. continue;
  1077. }
  1078. /* Shadow DOM detected, sanitize it */
  1079. if (currentNode.content instanceof DocumentFragment) {
  1080. _sanitizeShadowDOM(currentNode.content);
  1081. }
  1082. /* Check attributes, sanitize if necessary */
  1083. _sanitizeAttributes(currentNode);
  1084. oldNode = currentNode;
  1085. }
  1086. oldNode = null;
  1087. /* If we sanitized `dirty` in-place, return it. */
  1088. if (IN_PLACE) {
  1089. return dirty;
  1090. }
  1091. /* Return sanitized string or DOM */
  1092. if (RETURN_DOM) {
  1093. if (RETURN_DOM_FRAGMENT) {
  1094. returnNode = createDocumentFragment.call(body.ownerDocument);
  1095. while (body.firstChild) {
  1096. // eslint-disable-next-line unicorn/prefer-dom-node-append
  1097. returnNode.appendChild(body.firstChild);
  1098. }
  1099. } else {
  1100. returnNode = body;
  1101. }
  1102. if (ALLOWED_ATTR.shadowroot) {
  1103. /*
  1104. AdoptNode() is not used because internal state is not reset
  1105. (e.g. the past names map of a HTMLFormElement), this is safe
  1106. in theory but we would rather not risk another attack vector.
  1107. The state that is cloned by importNode() is explicitly defined
  1108. by the specs.
  1109. */
  1110. returnNode = importNode.call(originalDocument, returnNode, true);
  1111. }
  1112. return returnNode;
  1113. }
  1114. var serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
  1115. /* Serialize doctype if allowed */
  1116. if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
  1117. serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
  1118. }
  1119. /* Sanitize final string template-safe */
  1120. if (SAFE_FOR_TEMPLATES) {
  1121. serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$$1, ' ');
  1122. serializedHTML = stringReplace(serializedHTML, ERB_EXPR$$1, ' ');
  1123. }
  1124. return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
  1125. };
  1126. /**
  1127. * Public method to set the configuration once
  1128. * setConfig
  1129. *
  1130. * @param {Object} cfg configuration object
  1131. */
  1132. DOMPurify.setConfig = function (cfg) {
  1133. _parseConfig(cfg);
  1134. SET_CONFIG = true;
  1135. };
  1136. /**
  1137. * Public method to remove the configuration
  1138. * clearConfig
  1139. *
  1140. */
  1141. DOMPurify.clearConfig = function () {
  1142. CONFIG = null;
  1143. SET_CONFIG = false;
  1144. };
  1145. /**
  1146. * Public method to check if an attribute value is valid.
  1147. * Uses last set config, if any. Otherwise, uses config defaults.
  1148. * isValidAttribute
  1149. *
  1150. * @param {string} tag Tag name of containing element.
  1151. * @param {string} attr Attribute name.
  1152. * @param {string} value Attribute value.
  1153. * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
  1154. */
  1155. DOMPurify.isValidAttribute = function (tag, attr, value) {
  1156. /* Initialize shared config vars if necessary. */
  1157. if (!CONFIG) {
  1158. _parseConfig({});
  1159. }
  1160. var lcTag = transformCaseFunc(tag);
  1161. var lcName = transformCaseFunc(attr);
  1162. return _isValidAttribute(lcTag, lcName, value);
  1163. };
  1164. /**
  1165. * AddHook
  1166. * Public method to add DOMPurify hooks
  1167. *
  1168. * @param {String} entryPoint entry point for the hook to add
  1169. * @param {Function} hookFunction function to execute
  1170. */
  1171. DOMPurify.addHook = function (entryPoint, hookFunction) {
  1172. if (typeof hookFunction !== 'function') {
  1173. return;
  1174. }
  1175. hooks[entryPoint] = hooks[entryPoint] || [];
  1176. arrayPush(hooks[entryPoint], hookFunction);
  1177. };
  1178. /**
  1179. * RemoveHook
  1180. * Public method to remove a DOMPurify hook at a given entryPoint
  1181. * (pops it from the stack of hooks if more are present)
  1182. *
  1183. * @param {String} entryPoint entry point for the hook to remove
  1184. */
  1185. DOMPurify.removeHook = function (entryPoint) {
  1186. if (hooks[entryPoint]) {
  1187. arrayPop(hooks[entryPoint]);
  1188. }
  1189. };
  1190. /**
  1191. * RemoveHooks
  1192. * Public method to remove all DOMPurify hooks at a given entryPoint
  1193. *
  1194. * @param {String} entryPoint entry point for the hooks to remove
  1195. */
  1196. DOMPurify.removeHooks = function (entryPoint) {
  1197. if (hooks[entryPoint]) {
  1198. hooks[entryPoint] = [];
  1199. }
  1200. };
  1201. /**
  1202. * RemoveAllHooks
  1203. * Public method to remove all DOMPurify hooks
  1204. *
  1205. */
  1206. DOMPurify.removeAllHooks = function () {
  1207. hooks = {};
  1208. };
  1209. return DOMPurify;
  1210. }
  1211. var purify = createDOMPurify();
  1212. return purify;
  1213. }));
  1214. //# sourceMappingURL=purify.js.map