UNPKG

61.6 kBJavaScriptView Raw
1/*! @license DOMPurify 2.4.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.4.0/LICENSE */
2
3function _typeof(obj) {
4 "@babel/helpers - typeof";
5
6 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
7 return typeof obj;
8 } : function (obj) {
9 return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
10 }, _typeof(obj);
11}
12
13function _setPrototypeOf(o, p) {
14 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
15 o.__proto__ = p;
16 return o;
17 };
18
19 return _setPrototypeOf(o, p);
20}
21
22function _isNativeReflectConstruct() {
23 if (typeof Reflect === "undefined" || !Reflect.construct) return false;
24 if (Reflect.construct.sham) return false;
25 if (typeof Proxy === "function") return true;
26
27 try {
28 Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
29 return true;
30 } catch (e) {
31 return false;
32 }
33}
34
35function _construct(Parent, args, Class) {
36 if (_isNativeReflectConstruct()) {
37 _construct = Reflect.construct;
38 } else {
39 _construct = function _construct(Parent, args, Class) {
40 var a = [null];
41 a.push.apply(a, args);
42 var Constructor = Function.bind.apply(Parent, a);
43 var instance = new Constructor();
44 if (Class) _setPrototypeOf(instance, Class.prototype);
45 return instance;
46 };
47 }
48
49 return _construct.apply(null, arguments);
50}
51
52function _toConsumableArray(arr) {
53 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
54}
55
56function _arrayWithoutHoles(arr) {
57 if (Array.isArray(arr)) return _arrayLikeToArray(arr);
58}
59
60function _iterableToArray(iter) {
61 if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
62}
63
64function _unsupportedIterableToArray(o, minLen) {
65 if (!o) return;
66 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
67 var n = Object.prototype.toString.call(o).slice(8, -1);
68 if (n === "Object" && o.constructor) n = o.constructor.name;
69 if (n === "Map" || n === "Set") return Array.from(o);
70 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
71}
72
73function _arrayLikeToArray(arr, len) {
74 if (len == null || len > arr.length) len = arr.length;
75
76 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
77
78 return arr2;
79}
80
81function _nonIterableSpread() {
82 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
83}
84
85var hasOwnProperty = Object.hasOwnProperty,
86 setPrototypeOf = Object.setPrototypeOf,
87 isFrozen = Object.isFrozen,
88 getPrototypeOf = Object.getPrototypeOf,
89 getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
90var freeze = Object.freeze,
91 seal = Object.seal,
92 create = Object.create; // eslint-disable-line import/no-mutable-exports
93
94var _ref = typeof Reflect !== 'undefined' && Reflect,
95 apply = _ref.apply,
96 construct = _ref.construct;
97
98if (!apply) {
99 apply = function apply(fun, thisValue, args) {
100 return fun.apply(thisValue, args);
101 };
102}
103
104if (!freeze) {
105 freeze = function freeze(x) {
106 return x;
107 };
108}
109
110if (!seal) {
111 seal = function seal(x) {
112 return x;
113 };
114}
115
116if (!construct) {
117 construct = function construct(Func, args) {
118 return _construct(Func, _toConsumableArray(args));
119 };
120}
121
122var arrayForEach = unapply(Array.prototype.forEach);
123var arrayPop = unapply(Array.prototype.pop);
124var arrayPush = unapply(Array.prototype.push);
125var stringToLowerCase = unapply(String.prototype.toLowerCase);
126var stringMatch = unapply(String.prototype.match);
127var stringReplace = unapply(String.prototype.replace);
128var stringIndexOf = unapply(String.prototype.indexOf);
129var stringTrim = unapply(String.prototype.trim);
130var regExpTest = unapply(RegExp.prototype.test);
131var typeErrorCreate = unconstruct(TypeError);
132function unapply(func) {
133 return function (thisArg) {
134 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
135 args[_key - 1] = arguments[_key];
136 }
137
138 return apply(func, thisArg, args);
139 };
140}
141function unconstruct(func) {
142 return function () {
143 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
144 args[_key2] = arguments[_key2];
145 }
146
147 return construct(func, args);
148 };
149}
150/* Add properties to a lookup table */
151
152function addToSet(set, array, transformCaseFunc) {
153 transformCaseFunc = transformCaseFunc ? transformCaseFunc : stringToLowerCase;
154
155 if (setPrototypeOf) {
156 // Make 'in' and truthy checks like Boolean(set.constructor)
157 // independent of any properties defined on Object.prototype.
158 // Prevent prototype setters from intercepting set as a this value.
159 setPrototypeOf(set, null);
160 }
161
162 var l = array.length;
163
164 while (l--) {
165 var element = array[l];
166
167 if (typeof element === 'string') {
168 var lcElement = transformCaseFunc(element);
169
170 if (lcElement !== element) {
171 // Config presets (e.g. tags.js, attrs.js) are immutable.
172 if (!isFrozen(array)) {
173 array[l] = lcElement;
174 }
175
176 element = lcElement;
177 }
178 }
179
180 set[element] = true;
181 }
182
183 return set;
184}
185/* Shallow clone an object */
186
187function clone(object) {
188 var newObject = create(null);
189 var property;
190
191 for (property in object) {
192 if (apply(hasOwnProperty, object, [property])) {
193 newObject[property] = object[property];
194 }
195 }
196
197 return newObject;
198}
199/* IE10 doesn't support __lookupGetter__ so lets'
200 * simulate it. It also automatically checks
201 * if the prop is function or getter and behaves
202 * accordingly. */
203
204function lookupGetter(object, prop) {
205 while (object !== null) {
206 var desc = getOwnPropertyDescriptor(object, prop);
207
208 if (desc) {
209 if (desc.get) {
210 return unapply(desc.get);
211 }
212
213 if (typeof desc.value === 'function') {
214 return unapply(desc.value);
215 }
216 }
217
218 object = getPrototypeOf(object);
219 }
220
221 function fallbackValue(element) {
222 console.warn('fallback value for', element);
223 return null;
224 }
225
226 return fallbackValue;
227}
228
229var html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']); // SVG
230
231var svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
232var 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']); // List of SVG elements that are disallowed by default.
233// We still need to know them so that we can do namespace
234// checks properly in case one wants to add them to
235// allow-list.
236
237var 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']);
238var 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']); // Similarly to SVG, we want to know all MathML elements,
239// even those that we disallow by default.
240
241var mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
242var text = freeze(['#text']);
243
244var html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', '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']);
245var svg = 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']);
246var mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
247var xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
248
249var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
250
251var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
252var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
253
254var ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
255
256var 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
257);
258var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
259var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
260);
261var DOCTYPE_NAME = seal(/^html$/i);
262
263var getGlobal = function getGlobal() {
264 return typeof window === 'undefined' ? null : window;
265};
266/**
267 * Creates a no-op policy for internal use only.
268 * Don't export this function outside this module!
269 * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
270 * @param {Document} document The document object (to determine policy name suffix)
271 * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
272 * are not supported).
273 */
274
275
276var _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {
277 if (_typeof(trustedTypes) !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
278 return null;
279 } // Allow the callers to control the unique policy name
280 // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
281 // Policy creation with duplicate names throws in Trusted Types.
282
283
284 var suffix = null;
285 var ATTR_NAME = 'data-tt-policy-suffix';
286
287 if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {
288 suffix = document.currentScript.getAttribute(ATTR_NAME);
289 }
290
291 var policyName = 'dompurify' + (suffix ? '#' + suffix : '');
292
293 try {
294 return trustedTypes.createPolicy(policyName, {
295 createHTML: function createHTML(html) {
296 return html;
297 },
298 createScriptURL: function createScriptURL(scriptUrl) {
299 return scriptUrl;
300 }
301 });
302 } catch (_) {
303 // Policy creation failed (most likely another DOMPurify script has
304 // already run). Skip creating the policy, as this will only cause errors
305 // if TT are enforced.
306 console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
307 return null;
308 }
309};
310
311function createDOMPurify() {
312 var window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
313
314 var DOMPurify = function DOMPurify(root) {
315 return createDOMPurify(root);
316 };
317 /**
318 * Version label, exposed for easier checks
319 * if DOMPurify is up to date or not
320 */
321
322
323 DOMPurify.version = '2.4.0';
324 /**
325 * Array of elements that DOMPurify removed during sanitation.
326 * Empty if nothing was removed.
327 */
328
329 DOMPurify.removed = [];
330
331 if (!window || !window.document || window.document.nodeType !== 9) {
332 // Not running in a browser, provide a factory function
333 // so that you can pass your own Window
334 DOMPurify.isSupported = false;
335 return DOMPurify;
336 }
337
338 var originalDocument = window.document;
339 var document = window.document;
340 var DocumentFragment = window.DocumentFragment,
341 HTMLTemplateElement = window.HTMLTemplateElement,
342 Node = window.Node,
343 Element = window.Element,
344 NodeFilter = window.NodeFilter,
345 _window$NamedNodeMap = window.NamedNodeMap,
346 NamedNodeMap = _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap,
347 HTMLFormElement = window.HTMLFormElement,
348 DOMParser = window.DOMParser,
349 trustedTypes = window.trustedTypes;
350 var ElementPrototype = Element.prototype;
351 var cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
352 var getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
353 var getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
354 var getParentNode = lookupGetter(ElementPrototype, 'parentNode'); // As per issue #47, the web-components registry is inherited by a
355 // new document created via createHTMLDocument. As per the spec
356 // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
357 // a new empty registry is used when creating a template contents owner
358 // document, so we use that as our parent document to ensure nothing
359 // is inherited.
360
361 if (typeof HTMLTemplateElement === 'function') {
362 var template = document.createElement('template');
363
364 if (template.content && template.content.ownerDocument) {
365 document = template.content.ownerDocument;
366 }
367 }
368
369 var trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
370
371 var emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML('') : '';
372 var _document = document,
373 implementation = _document.implementation,
374 createNodeIterator = _document.createNodeIterator,
375 createDocumentFragment = _document.createDocumentFragment,
376 getElementsByTagName = _document.getElementsByTagName;
377 var importNode = originalDocument.importNode;
378 var documentMode = {};
379
380 try {
381 documentMode = clone(document).documentMode ? document.documentMode : {};
382 } catch (_) {}
383
384 var hooks = {};
385 /**
386 * Expose whether this browser supports running the full DOMPurify.
387 */
388
389 DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;
390 var MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
391 ERB_EXPR$1 = ERB_EXPR,
392 DATA_ATTR$1 = DATA_ATTR,
393 ARIA_ATTR$1 = ARIA_ATTR,
394 IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
395 ATTR_WHITESPACE$1 = ATTR_WHITESPACE;
396 var IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
397 /**
398 * We consider the elements and attributes below to be safe. Ideally
399 * don't add any new ones but feel free to remove unwanted ones.
400 */
401
402 /* allowed element names */
403
404 var ALLOWED_TAGS = null;
405 var DEFAULT_ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray(html$1), _toConsumableArray(svg$1), _toConsumableArray(svgFilters), _toConsumableArray(mathMl$1), _toConsumableArray(text)));
406 /* Allowed attribute names */
407
408 var ALLOWED_ATTR = null;
409 var DEFAULT_ALLOWED_ATTR = addToSet({}, [].concat(_toConsumableArray(html), _toConsumableArray(svg), _toConsumableArray(mathMl), _toConsumableArray(xml)));
410 /*
411 * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
412 * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
413 * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
414 * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
415 */
416
417 var CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
418 tagNameCheck: {
419 writable: true,
420 configurable: false,
421 enumerable: true,
422 value: null
423 },
424 attributeNameCheck: {
425 writable: true,
426 configurable: false,
427 enumerable: true,
428 value: null
429 },
430 allowCustomizedBuiltInElements: {
431 writable: true,
432 configurable: false,
433 enumerable: true,
434 value: false
435 }
436 }));
437 /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
438
439 var FORBID_TAGS = null;
440 /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
441
442 var FORBID_ATTR = null;
443 /* Decide if ARIA attributes are okay */
444
445 var ALLOW_ARIA_ATTR = true;
446 /* Decide if custom data attributes are okay */
447
448 var ALLOW_DATA_ATTR = true;
449 /* Decide if unknown protocols are okay */
450
451 var ALLOW_UNKNOWN_PROTOCOLS = false;
452 /* Output should be safe for common template engines.
453 * This means, DOMPurify removes data attributes, mustaches and ERB
454 */
455
456 var SAFE_FOR_TEMPLATES = false;
457 /* Decide if document with <html>... should be returned */
458
459 var WHOLE_DOCUMENT = false;
460 /* Track whether config is already set on this instance of DOMPurify. */
461
462 var SET_CONFIG = false;
463 /* Decide if all elements (e.g. style, script) must be children of
464 * document.body. By default, browsers might move them to document.head */
465
466 var FORCE_BODY = false;
467 /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
468 * string (or a TrustedHTML object if Trusted Types are supported).
469 * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
470 */
471
472 var RETURN_DOM = false;
473 /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
474 * string (or a TrustedHTML object if Trusted Types are supported) */
475
476 var RETURN_DOM_FRAGMENT = false;
477 /* Try to return a Trusted Type object instead of a string, return a string in
478 * case Trusted Types are not supported */
479
480 var RETURN_TRUSTED_TYPE = false;
481 /* Output should be free from DOM clobbering attacks?
482 * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
483 */
484
485 var SANITIZE_DOM = true;
486 /* Achieve full DOM Clobbering protection by isolating the namespace of named
487 * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
488 *
489 * HTML/DOM spec rules that enable DOM Clobbering:
490 * - Named Access on Window (§7.3.3)
491 * - DOM Tree Accessors (§3.1.5)
492 * - Form Element Parent-Child Relations (§4.10.3)
493 * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
494 * - HTMLCollection (§4.2.10.2)
495 *
496 * Namespace isolation is implemented by prefixing `id` and `name` attributes
497 * with a constant string, i.e., `user-content-`
498 */
499
500 var SANITIZE_NAMED_PROPS = false;
501 var SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
502 /* Keep element content when removing element? */
503
504 var KEEP_CONTENT = true;
505 /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
506 * of importing it into a new Document and returning a sanitized copy */
507
508 var IN_PLACE = false;
509 /* Allow usage of profiles like html, svg and mathMl */
510
511 var USE_PROFILES = {};
512 /* Tags to ignore content of when KEEP_CONTENT is true */
513
514 var FORBID_CONTENTS = null;
515 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']);
516 /* Tags that are safe for data: URIs */
517
518 var DATA_URI_TAGS = null;
519 var DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
520 /* Attributes safe for values like "javascript:" */
521
522 var URI_SAFE_ATTRIBUTES = null;
523 var DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
524 var MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
525 var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
526 var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
527 /* Document namespace */
528
529 var NAMESPACE = HTML_NAMESPACE;
530 var IS_EMPTY_INPUT = false;
531 /* Parsing of strict XHTML documents */
532
533 var PARSER_MEDIA_TYPE;
534 var SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
535 var DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
536 var transformCaseFunc;
537 /* Keep a reference to config to pass to hooks */
538
539 var CONFIG = null;
540 /* Ideally, do not touch anything below this line */
541
542 /* ______________________________________________ */
543
544 var formElement = document.createElement('form');
545
546 var isRegexOrFunction = function isRegexOrFunction(testValue) {
547 return testValue instanceof RegExp || testValue instanceof Function;
548 };
549 /**
550 * _parseConfig
551 *
552 * @param {Object} cfg optional config literal
553 */
554 // eslint-disable-next-line complexity
555
556
557 var _parseConfig = function _parseConfig(cfg) {
558 if (CONFIG && CONFIG === cfg) {
559 return;
560 }
561 /* Shield configuration object from tampering */
562
563
564 if (!cfg || _typeof(cfg) !== 'object') {
565 cfg = {};
566 }
567 /* Shield configuration object from prototype pollution */
568
569
570 cfg = clone(cfg);
571 PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
572 SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE; // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
573
574 transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? function (x) {
575 return x;
576 } : stringToLowerCase;
577 /* Set configuration parameters */
578
579 ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
580 ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
581 URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent
582 cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent
583 transformCaseFunc // eslint-disable-line indent
584 ) // eslint-disable-line indent
585 : DEFAULT_URI_SAFE_ATTRIBUTES;
586 DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), // eslint-disable-line indent
587 cfg.ADD_DATA_URI_TAGS, // eslint-disable-line indent
588 transformCaseFunc // eslint-disable-line indent
589 ) // eslint-disable-line indent
590 : DEFAULT_DATA_URI_TAGS;
591 FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
592 FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
593 FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
594 USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
595 ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
596
597 ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
598
599 ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
600
601 SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
602
603 WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
604
605 RETURN_DOM = cfg.RETURN_DOM || false; // Default false
606
607 RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
608
609 RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
610
611 FORCE_BODY = cfg.FORCE_BODY || false; // Default false
612
613 SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
614
615 SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
616
617 KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
618
619 IN_PLACE = cfg.IN_PLACE || false; // Default false
620
621 IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$1;
622 NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
623
624 if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
625 CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
626 }
627
628 if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
629 CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
630 }
631
632 if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
633 CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
634 }
635
636 if (SAFE_FOR_TEMPLATES) {
637 ALLOW_DATA_ATTR = false;
638 }
639
640 if (RETURN_DOM_FRAGMENT) {
641 RETURN_DOM = true;
642 }
643 /* Parse profile info */
644
645
646 if (USE_PROFILES) {
647 ALLOWED_TAGS = addToSet({}, _toConsumableArray(text));
648 ALLOWED_ATTR = [];
649
650 if (USE_PROFILES.html === true) {
651 addToSet(ALLOWED_TAGS, html$1);
652 addToSet(ALLOWED_ATTR, html);
653 }
654
655 if (USE_PROFILES.svg === true) {
656 addToSet(ALLOWED_TAGS, svg$1);
657 addToSet(ALLOWED_ATTR, svg);
658 addToSet(ALLOWED_ATTR, xml);
659 }
660
661 if (USE_PROFILES.svgFilters === true) {
662 addToSet(ALLOWED_TAGS, svgFilters);
663 addToSet(ALLOWED_ATTR, svg);
664 addToSet(ALLOWED_ATTR, xml);
665 }
666
667 if (USE_PROFILES.mathMl === true) {
668 addToSet(ALLOWED_TAGS, mathMl$1);
669 addToSet(ALLOWED_ATTR, mathMl);
670 addToSet(ALLOWED_ATTR, xml);
671 }
672 }
673 /* Merge configuration parameters */
674
675
676 if (cfg.ADD_TAGS) {
677 if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
678 ALLOWED_TAGS = clone(ALLOWED_TAGS);
679 }
680
681 addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
682 }
683
684 if (cfg.ADD_ATTR) {
685 if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
686 ALLOWED_ATTR = clone(ALLOWED_ATTR);
687 }
688
689 addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
690 }
691
692 if (cfg.ADD_URI_SAFE_ATTR) {
693 addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
694 }
695
696 if (cfg.FORBID_CONTENTS) {
697 if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
698 FORBID_CONTENTS = clone(FORBID_CONTENTS);
699 }
700
701 addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
702 }
703 /* Add #text in case KEEP_CONTENT is set to true */
704
705
706 if (KEEP_CONTENT) {
707 ALLOWED_TAGS['#text'] = true;
708 }
709 /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
710
711
712 if (WHOLE_DOCUMENT) {
713 addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
714 }
715 /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
716
717
718 if (ALLOWED_TAGS.table) {
719 addToSet(ALLOWED_TAGS, ['tbody']);
720 delete FORBID_TAGS.tbody;
721 } // Prevent further manipulation of configuration.
722 // Not available in IE8, Safari 5, etc.
723
724
725 if (freeze) {
726 freeze(cfg);
727 }
728
729 CONFIG = cfg;
730 };
731
732 var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
733 var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']); // Certain elements are allowed in both SVG and HTML
734 // namespace. We need to specify them explicitly
735 // so that they don't get erroneously deleted from
736 // HTML namespace.
737
738 var COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
739 /* Keep track of all possible SVG and MathML tags
740 * so that we can perform the namespace checks
741 * correctly. */
742
743 var ALL_SVG_TAGS = addToSet({}, svg$1);
744 addToSet(ALL_SVG_TAGS, svgFilters);
745 addToSet(ALL_SVG_TAGS, svgDisallowed);
746 var ALL_MATHML_TAGS = addToSet({}, mathMl$1);
747 addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
748 /**
749 *
750 *
751 * @param {Element} element a DOM element whose namespace is being checked
752 * @returns {boolean} Return false if the element has a
753 * namespace that a spec-compliant parser would never
754 * return. Return true otherwise.
755 */
756
757 var _checkValidNamespace = function _checkValidNamespace(element) {
758 var parent = getParentNode(element); // In JSDOM, if we're inside shadow DOM, then parentNode
759 // can be null. We just simulate parent in this case.
760
761 if (!parent || !parent.tagName) {
762 parent = {
763 namespaceURI: HTML_NAMESPACE,
764 tagName: 'template'
765 };
766 }
767
768 var tagName = stringToLowerCase(element.tagName);
769 var parentTagName = stringToLowerCase(parent.tagName);
770
771 if (element.namespaceURI === SVG_NAMESPACE) {
772 // The only way to switch from HTML namespace to SVG
773 // is via <svg>. If it happens via any other tag, then
774 // it should be killed.
775 if (parent.namespaceURI === HTML_NAMESPACE) {
776 return tagName === 'svg';
777 } // The only way to switch from MathML to SVG is via
778 // svg if parent is either <annotation-xml> or MathML
779 // text integration points.
780
781
782 if (parent.namespaceURI === MATHML_NAMESPACE) {
783 return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
784 } // We only allow elements that are defined in SVG
785 // spec. All others are disallowed in SVG namespace.
786
787
788 return Boolean(ALL_SVG_TAGS[tagName]);
789 }
790
791 if (element.namespaceURI === MATHML_NAMESPACE) {
792 // The only way to switch from HTML namespace to MathML
793 // is via <math>. If it happens via any other tag, then
794 // it should be killed.
795 if (parent.namespaceURI === HTML_NAMESPACE) {
796 return tagName === 'math';
797 } // The only way to switch from SVG to MathML is via
798 // <math> and HTML integration points
799
800
801 if (parent.namespaceURI === SVG_NAMESPACE) {
802 return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
803 } // We only allow elements that are defined in MathML
804 // spec. All others are disallowed in MathML namespace.
805
806
807 return Boolean(ALL_MATHML_TAGS[tagName]);
808 }
809
810 if (element.namespaceURI === HTML_NAMESPACE) {
811 // The only way to switch from SVG to HTML is via
812 // HTML integration points, and from MathML to HTML
813 // is via MathML text integration points
814 if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
815 return false;
816 }
817
818 if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
819 return false;
820 } // We disallow tags that are specific for MathML
821 // or SVG and should never appear in HTML namespace
822
823
824 return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
825 } // The code should never reach this place (this means
826 // that the element somehow got namespace that is not
827 // HTML, SVG or MathML). Return false just in case.
828
829
830 return false;
831 };
832 /**
833 * _forceRemove
834 *
835 * @param {Node} node a DOM node
836 */
837
838
839 var _forceRemove = function _forceRemove(node) {
840 arrayPush(DOMPurify.removed, {
841 element: node
842 });
843
844 try {
845 // eslint-disable-next-line unicorn/prefer-dom-node-remove
846 node.parentNode.removeChild(node);
847 } catch (_) {
848 try {
849 node.outerHTML = emptyHTML;
850 } catch (_) {
851 node.remove();
852 }
853 }
854 };
855 /**
856 * _removeAttribute
857 *
858 * @param {String} name an Attribute name
859 * @param {Node} node a DOM node
860 */
861
862
863 var _removeAttribute = function _removeAttribute(name, node) {
864 try {
865 arrayPush(DOMPurify.removed, {
866 attribute: node.getAttributeNode(name),
867 from: node
868 });
869 } catch (_) {
870 arrayPush(DOMPurify.removed, {
871 attribute: null,
872 from: node
873 });
874 }
875
876 node.removeAttribute(name); // We void attribute values for unremovable "is"" attributes
877
878 if (name === 'is' && !ALLOWED_ATTR[name]) {
879 if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
880 try {
881 _forceRemove(node);
882 } catch (_) {}
883 } else {
884 try {
885 node.setAttribute(name, '');
886 } catch (_) {}
887 }
888 }
889 };
890 /**
891 * _initDocument
892 *
893 * @param {String} dirty a string of dirty markup
894 * @return {Document} a DOM, filled with the dirty markup
895 */
896
897
898 var _initDocument = function _initDocument(dirty) {
899 /* Create a HTML document */
900 var doc;
901 var leadingWhitespace;
902
903 if (FORCE_BODY) {
904 dirty = '<remove></remove>' + dirty;
905 } else {
906 /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
907 var matches = stringMatch(dirty, /^[\r\n\t ]+/);
908 leadingWhitespace = matches && matches[0];
909 }
910
911 if (PARSER_MEDIA_TYPE === 'application/xhtml+xml') {
912 // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
913 dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
914 }
915
916 var dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
917 /*
918 * Use the DOMParser API by default, fallback later if needs be
919 * DOMParser not work for svg when has multiple root element.
920 */
921
922 if (NAMESPACE === HTML_NAMESPACE) {
923 try {
924 doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
925 } catch (_) {}
926 }
927 /* Use createHTMLDocument in case DOMParser is not available */
928
929
930 if (!doc || !doc.documentElement) {
931 doc = implementation.createDocument(NAMESPACE, 'template', null);
932
933 try {
934 doc.documentElement.innerHTML = IS_EMPTY_INPUT ? '' : dirtyPayload;
935 } catch (_) {// Syntax error if dirtyPayload is invalid xml
936 }
937 }
938
939 var body = doc.body || doc.documentElement;
940
941 if (dirty && leadingWhitespace) {
942 body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
943 }
944 /* Work on whole document or just its body */
945
946
947 if (NAMESPACE === HTML_NAMESPACE) {
948 return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
949 }
950
951 return WHOLE_DOCUMENT ? doc.documentElement : body;
952 };
953 /**
954 * _createIterator
955 *
956 * @param {Document} root document/fragment to create iterator for
957 * @return {Iterator} iterator instance
958 */
959
960
961 var _createIterator = function _createIterator(root) {
962 return createNodeIterator.call(root.ownerDocument || root, root, // eslint-disable-next-line no-bitwise
963 NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
964 };
965 /**
966 * _isClobbered
967 *
968 * @param {Node} elm element to check for clobbering attacks
969 * @return {Boolean} true if clobbered, false if safe
970 */
971
972
973 var _isClobbered = function _isClobbered(elm) {
974 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');
975 };
976 /**
977 * _isNode
978 *
979 * @param {Node} obj object to check whether it's a DOM node
980 * @return {Boolean} true is object is a DOM node
981 */
982
983
984 var _isNode = function _isNode(object) {
985 return _typeof(Node) === 'object' ? object instanceof Node : object && _typeof(object) === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
986 };
987 /**
988 * _executeHook
989 * Execute user configurable hooks
990 *
991 * @param {String} entryPoint Name of the hook's entry point
992 * @param {Node} currentNode node to work on with the hook
993 * @param {Object} data additional hook parameters
994 */
995
996
997 var _executeHook = function _executeHook(entryPoint, currentNode, data) {
998 if (!hooks[entryPoint]) {
999 return;
1000 }
1001
1002 arrayForEach(hooks[entryPoint], function (hook) {
1003 hook.call(DOMPurify, currentNode, data, CONFIG);
1004 });
1005 };
1006 /**
1007 * _sanitizeElements
1008 *
1009 * @protect nodeName
1010 * @protect textContent
1011 * @protect removeChild
1012 *
1013 * @param {Node} currentNode to check for permission to exist
1014 * @return {Boolean} true if node was killed, false if left alive
1015 */
1016
1017
1018 var _sanitizeElements = function _sanitizeElements(currentNode) {
1019 var content;
1020 /* Execute a hook if present */
1021
1022 _executeHook('beforeSanitizeElements', currentNode, null);
1023 /* Check if element is clobbered or can clobber */
1024
1025
1026 if (_isClobbered(currentNode)) {
1027 _forceRemove(currentNode);
1028
1029 return true;
1030 }
1031 /* Check if tagname contains Unicode */
1032
1033
1034 if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
1035 _forceRemove(currentNode);
1036
1037 return true;
1038 }
1039 /* Now let's check the element's type and name */
1040
1041
1042 var tagName = transformCaseFunc(currentNode.nodeName);
1043 /* Execute a hook if present */
1044
1045 _executeHook('uponSanitizeElement', currentNode, {
1046 tagName: tagName,
1047 allowedTags: ALLOWED_TAGS
1048 });
1049 /* Detect mXSS attempts abusing namespace confusion */
1050
1051
1052 if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
1053 _forceRemove(currentNode);
1054
1055 return true;
1056 }
1057 /* Mitigate a problem with templates inside select */
1058
1059
1060 if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
1061 _forceRemove(currentNode);
1062
1063 return true;
1064 }
1065 /* Remove element if anything forbids its presence */
1066
1067
1068 if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1069 /* Check if we have a custom element to handle */
1070 if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
1071 if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
1072 if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
1073 }
1074 /* Keep content except for bad-listed elements */
1075
1076
1077 if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1078 var parentNode = getParentNode(currentNode) || currentNode.parentNode;
1079 var childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1080
1081 if (childNodes && parentNode) {
1082 var childCount = childNodes.length;
1083
1084 for (var i = childCount - 1; i >= 0; --i) {
1085 parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1086 }
1087 }
1088 }
1089
1090 _forceRemove(currentNode);
1091
1092 return true;
1093 }
1094 /* Check whether element has a valid namespace */
1095
1096
1097 if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1098 _forceRemove(currentNode);
1099
1100 return true;
1101 }
1102
1103 if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1104 _forceRemove(currentNode);
1105
1106 return true;
1107 }
1108 /* Sanitize element content to be template-safe */
1109
1110
1111 if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
1112 /* Get the element's text content */
1113 content = currentNode.textContent;
1114 content = stringReplace(content, MUSTACHE_EXPR$1, ' ');
1115 content = stringReplace(content, ERB_EXPR$1, ' ');
1116
1117 if (currentNode.textContent !== content) {
1118 arrayPush(DOMPurify.removed, {
1119 element: currentNode.cloneNode()
1120 });
1121 currentNode.textContent = content;
1122 }
1123 }
1124 /* Execute a hook if present */
1125
1126
1127 _executeHook('afterSanitizeElements', currentNode, null);
1128
1129 return false;
1130 };
1131 /**
1132 * _isValidAttribute
1133 *
1134 * @param {string} lcTag Lowercase tag name of containing element.
1135 * @param {string} lcName Lowercase attribute name.
1136 * @param {string} value Attribute value.
1137 * @return {Boolean} Returns true if `value` is valid, otherwise false.
1138 */
1139 // eslint-disable-next-line complexity
1140
1141
1142 var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1143 /* Make sure attribute cannot clobber */
1144 if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1145 return false;
1146 }
1147 /* Allow valid data-* attributes: At least one character after "-"
1148 (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1149 XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1150 We don't need to check the value; it's always URI safe. */
1151
1152
1153 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]) {
1154 if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1155 // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1156 // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1157 _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)) || // Alternative, second condition checks if it's an `is`-attribute, AND
1158 // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1159 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 {
1160 return false;
1161 }
1162 /* Check value is safe. First, is attr inert? If so, is safe */
1163
1164 } 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 {
1165 return false;
1166 }
1167
1168 return true;
1169 };
1170 /**
1171 * _basicCustomElementCheck
1172 * checks if at least one dash is included in tagName, and it's not the first char
1173 * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1174 * @param {string} tagName name of the tag of the node to sanitize
1175 */
1176
1177
1178 var _basicCustomElementTest = function _basicCustomElementTest(tagName) {
1179 return tagName.indexOf('-') > 0;
1180 };
1181 /**
1182 * _sanitizeAttributes
1183 *
1184 * @protect attributes
1185 * @protect nodeName
1186 * @protect removeAttribute
1187 * @protect setAttribute
1188 *
1189 * @param {Node} currentNode to sanitize
1190 */
1191
1192
1193 var _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1194 var attr;
1195 var value;
1196 var lcName;
1197 var l;
1198 /* Execute a hook if present */
1199
1200 _executeHook('beforeSanitizeAttributes', currentNode, null);
1201
1202 var attributes = currentNode.attributes;
1203 /* Check if we have attributes; if not we might have a text node */
1204
1205 if (!attributes) {
1206 return;
1207 }
1208
1209 var hookEvent = {
1210 attrName: '',
1211 attrValue: '',
1212 keepAttr: true,
1213 allowedAttributes: ALLOWED_ATTR
1214 };
1215 l = attributes.length;
1216 /* Go backwards over all attributes; safely remove bad ones */
1217
1218 while (l--) {
1219 attr = attributes[l];
1220 var _attr = attr,
1221 name = _attr.name,
1222 namespaceURI = _attr.namespaceURI;
1223 value = name === 'value' ? attr.value : stringTrim(attr.value);
1224 lcName = transformCaseFunc(name);
1225 /* Execute a hook if present */
1226
1227 hookEvent.attrName = lcName;
1228 hookEvent.attrValue = value;
1229 hookEvent.keepAttr = true;
1230 hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1231
1232 _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
1233
1234 value = hookEvent.attrValue;
1235 /* Did the hooks approve of the attribute? */
1236
1237 if (hookEvent.forceKeepAttr) {
1238 continue;
1239 }
1240 /* Remove attribute */
1241
1242
1243 _removeAttribute(name, currentNode);
1244 /* Did the hooks approve of the attribute? */
1245
1246
1247 if (!hookEvent.keepAttr) {
1248 continue;
1249 }
1250 /* Work around a security issue in jQuery 3.0 */
1251
1252
1253 if (regExpTest(/\/>/i, value)) {
1254 _removeAttribute(name, currentNode);
1255
1256 continue;
1257 }
1258 /* Sanitize attribute content to be template-safe */
1259
1260
1261 if (SAFE_FOR_TEMPLATES) {
1262 value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
1263 value = stringReplace(value, ERB_EXPR$1, ' ');
1264 }
1265 /* Is `value` valid for this attribute? */
1266
1267
1268 var lcTag = transformCaseFunc(currentNode.nodeName);
1269
1270 if (!_isValidAttribute(lcTag, lcName, value)) {
1271 continue;
1272 }
1273 /* Full DOM Clobbering protection via namespace isolation,
1274 * Prefix id and name attributes with `user-content-`
1275 */
1276
1277
1278 if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1279 // Remove the attribute with this value
1280 _removeAttribute(name, currentNode); // Prefix the value and later re-create the attribute with the sanitized value
1281
1282
1283 value = SANITIZE_NAMED_PROPS_PREFIX + value;
1284 }
1285 /* Handle attributes that require Trusted Types */
1286
1287
1288 if (trustedTypesPolicy && _typeof(trustedTypes) === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1289 if (namespaceURI) ; else {
1290 switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1291 case 'TrustedHTML':
1292 value = trustedTypesPolicy.createHTML(value);
1293 break;
1294
1295 case 'TrustedScriptURL':
1296 value = trustedTypesPolicy.createScriptURL(value);
1297 break;
1298 }
1299 }
1300 }
1301 /* Handle invalid data-* attribute set by try-catching it */
1302
1303
1304 try {
1305 if (namespaceURI) {
1306 currentNode.setAttributeNS(namespaceURI, name, value);
1307 } else {
1308 /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1309 currentNode.setAttribute(name, value);
1310 }
1311
1312 arrayPop(DOMPurify.removed);
1313 } catch (_) {}
1314 }
1315 /* Execute a hook if present */
1316
1317
1318 _executeHook('afterSanitizeAttributes', currentNode, null);
1319 };
1320 /**
1321 * _sanitizeShadowDOM
1322 *
1323 * @param {DocumentFragment} fragment to iterate over recursively
1324 */
1325
1326
1327 var _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1328 var shadowNode;
1329
1330 var shadowIterator = _createIterator(fragment);
1331 /* Execute a hook if present */
1332
1333
1334 _executeHook('beforeSanitizeShadowDOM', fragment, null);
1335
1336 while (shadowNode = shadowIterator.nextNode()) {
1337 /* Execute a hook if present */
1338 _executeHook('uponSanitizeShadowNode', shadowNode, null);
1339 /* Sanitize tags and elements */
1340
1341
1342 if (_sanitizeElements(shadowNode)) {
1343 continue;
1344 }
1345 /* Deep shadow DOM detected */
1346
1347
1348 if (shadowNode.content instanceof DocumentFragment) {
1349 _sanitizeShadowDOM(shadowNode.content);
1350 }
1351 /* Check attributes, sanitize if necessary */
1352
1353
1354 _sanitizeAttributes(shadowNode);
1355 }
1356 /* Execute a hook if present */
1357
1358
1359 _executeHook('afterSanitizeShadowDOM', fragment, null);
1360 };
1361 /**
1362 * Sanitize
1363 * Public method providing core sanitation functionality
1364 *
1365 * @param {String|Node} dirty string or DOM node
1366 * @param {Object} configuration object
1367 */
1368 // eslint-disable-next-line complexity
1369
1370
1371 DOMPurify.sanitize = function (dirty) {
1372 var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1373 var body;
1374 var importedNode;
1375 var currentNode;
1376 var oldNode;
1377 var returnNode;
1378 /* Make sure we have a string to sanitize.
1379 DO NOT return early, as this will return the wrong type if
1380 the user has requested a DOM object rather than a string */
1381
1382 IS_EMPTY_INPUT = !dirty;
1383
1384 if (IS_EMPTY_INPUT) {
1385 dirty = '<!-->';
1386 }
1387 /* Stringify, in case dirty is an object */
1388
1389
1390 if (typeof dirty !== 'string' && !_isNode(dirty)) {
1391 // eslint-disable-next-line no-negated-condition
1392 if (typeof dirty.toString !== 'function') {
1393 throw typeErrorCreate('toString is not a function');
1394 } else {
1395 dirty = dirty.toString();
1396
1397 if (typeof dirty !== 'string') {
1398 throw typeErrorCreate('dirty is not a string, aborting');
1399 }
1400 }
1401 }
1402 /* Check we can run. Otherwise fall back or ignore */
1403
1404
1405 if (!DOMPurify.isSupported) {
1406 if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
1407 if (typeof dirty === 'string') {
1408 return window.toStaticHTML(dirty);
1409 }
1410
1411 if (_isNode(dirty)) {
1412 return window.toStaticHTML(dirty.outerHTML);
1413 }
1414 }
1415
1416 return dirty;
1417 }
1418 /* Assign config vars */
1419
1420
1421 if (!SET_CONFIG) {
1422 _parseConfig(cfg);
1423 }
1424 /* Clean up removed elements */
1425
1426
1427 DOMPurify.removed = [];
1428 /* Check if dirty is correctly typed for IN_PLACE */
1429
1430 if (typeof dirty === 'string') {
1431 IN_PLACE = false;
1432 }
1433
1434 if (IN_PLACE) {
1435 /* Do some early pre-sanitization to avoid unsafe root nodes */
1436 if (dirty.nodeName) {
1437 var tagName = transformCaseFunc(dirty.nodeName);
1438
1439 if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1440 throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1441 }
1442 }
1443 } else if (dirty instanceof Node) {
1444 /* If dirty is a DOM element, append to an empty document to avoid
1445 elements being stripped by the parser */
1446 body = _initDocument('<!---->');
1447 importedNode = body.ownerDocument.importNode(dirty, true);
1448
1449 if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
1450 /* Node is already a body, use as is */
1451 body = importedNode;
1452 } else if (importedNode.nodeName === 'HTML') {
1453 body = importedNode;
1454 } else {
1455 // eslint-disable-next-line unicorn/prefer-dom-node-append
1456 body.appendChild(importedNode);
1457 }
1458 } else {
1459 /* Exit directly if we have nothing to do */
1460 if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
1461 dirty.indexOf('<') === -1) {
1462 return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1463 }
1464 /* Initialize the document to work on */
1465
1466
1467 body = _initDocument(dirty);
1468 /* Check we have a DOM node from the data */
1469
1470 if (!body) {
1471 return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1472 }
1473 }
1474 /* Remove first element node (ours) if FORCE_BODY is set */
1475
1476
1477 if (body && FORCE_BODY) {
1478 _forceRemove(body.firstChild);
1479 }
1480 /* Get node iterator */
1481
1482
1483 var nodeIterator = _createIterator(IN_PLACE ? dirty : body);
1484 /* Now start iterating over the created document */
1485
1486
1487 while (currentNode = nodeIterator.nextNode()) {
1488 /* Fix IE's strange behavior with manipulated textNodes #89 */
1489 if (currentNode.nodeType === 3 && currentNode === oldNode) {
1490 continue;
1491 }
1492 /* Sanitize tags and elements */
1493
1494
1495 if (_sanitizeElements(currentNode)) {
1496 continue;
1497 }
1498 /* Shadow DOM detected, sanitize it */
1499
1500
1501 if (currentNode.content instanceof DocumentFragment) {
1502 _sanitizeShadowDOM(currentNode.content);
1503 }
1504 /* Check attributes, sanitize if necessary */
1505
1506
1507 _sanitizeAttributes(currentNode);
1508
1509 oldNode = currentNode;
1510 }
1511
1512 oldNode = null;
1513 /* If we sanitized `dirty` in-place, return it. */
1514
1515 if (IN_PLACE) {
1516 return dirty;
1517 }
1518 /* Return sanitized string or DOM */
1519
1520
1521 if (RETURN_DOM) {
1522 if (RETURN_DOM_FRAGMENT) {
1523 returnNode = createDocumentFragment.call(body.ownerDocument);
1524
1525 while (body.firstChild) {
1526 // eslint-disable-next-line unicorn/prefer-dom-node-append
1527 returnNode.appendChild(body.firstChild);
1528 }
1529 } else {
1530 returnNode = body;
1531 }
1532
1533 if (ALLOWED_ATTR.shadowroot) {
1534 /*
1535 AdoptNode() is not used because internal state is not reset
1536 (e.g. the past names map of a HTMLFormElement), this is safe
1537 in theory but we would rather not risk another attack vector.
1538 The state that is cloned by importNode() is explicitly defined
1539 by the specs.
1540 */
1541 returnNode = importNode.call(originalDocument, returnNode, true);
1542 }
1543
1544 return returnNode;
1545 }
1546
1547 var serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1548 /* Serialize doctype if allowed */
1549
1550 if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1551 serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1552 }
1553 /* Sanitize final string template-safe */
1554
1555
1556 if (SAFE_FOR_TEMPLATES) {
1557 serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$1, ' ');
1558 serializedHTML = stringReplace(serializedHTML, ERB_EXPR$1, ' ');
1559 }
1560
1561 return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1562 };
1563 /**
1564 * Public method to set the configuration once
1565 * setConfig
1566 *
1567 * @param {Object} cfg configuration object
1568 */
1569
1570
1571 DOMPurify.setConfig = function (cfg) {
1572 _parseConfig(cfg);
1573
1574 SET_CONFIG = true;
1575 };
1576 /**
1577 * Public method to remove the configuration
1578 * clearConfig
1579 *
1580 */
1581
1582
1583 DOMPurify.clearConfig = function () {
1584 CONFIG = null;
1585 SET_CONFIG = false;
1586 };
1587 /**
1588 * Public method to check if an attribute value is valid.
1589 * Uses last set config, if any. Otherwise, uses config defaults.
1590 * isValidAttribute
1591 *
1592 * @param {string} tag Tag name of containing element.
1593 * @param {string} attr Attribute name.
1594 * @param {string} value Attribute value.
1595 * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
1596 */
1597
1598
1599 DOMPurify.isValidAttribute = function (tag, attr, value) {
1600 /* Initialize shared config vars if necessary. */
1601 if (!CONFIG) {
1602 _parseConfig({});
1603 }
1604
1605 var lcTag = transformCaseFunc(tag);
1606 var lcName = transformCaseFunc(attr);
1607 return _isValidAttribute(lcTag, lcName, value);
1608 };
1609 /**
1610 * AddHook
1611 * Public method to add DOMPurify hooks
1612 *
1613 * @param {String} entryPoint entry point for the hook to add
1614 * @param {Function} hookFunction function to execute
1615 */
1616
1617
1618 DOMPurify.addHook = function (entryPoint, hookFunction) {
1619 if (typeof hookFunction !== 'function') {
1620 return;
1621 }
1622
1623 hooks[entryPoint] = hooks[entryPoint] || [];
1624 arrayPush(hooks[entryPoint], hookFunction);
1625 };
1626 /**
1627 * RemoveHook
1628 * Public method to remove a DOMPurify hook at a given entryPoint
1629 * (pops it from the stack of hooks if more are present)
1630 *
1631 * @param {String} entryPoint entry point for the hook to remove
1632 * @return {Function} removed(popped) hook
1633 */
1634
1635
1636 DOMPurify.removeHook = function (entryPoint) {
1637 if (hooks[entryPoint]) {
1638 return arrayPop(hooks[entryPoint]);
1639 }
1640 };
1641 /**
1642 * RemoveHooks
1643 * Public method to remove all DOMPurify hooks at a given entryPoint
1644 *
1645 * @param {String} entryPoint entry point for the hooks to remove
1646 */
1647
1648
1649 DOMPurify.removeHooks = function (entryPoint) {
1650 if (hooks[entryPoint]) {
1651 hooks[entryPoint] = [];
1652 }
1653 };
1654 /**
1655 * RemoveAllHooks
1656 * Public method to remove all DOMPurify hooks
1657 *
1658 */
1659
1660
1661 DOMPurify.removeAllHooks = function () {
1662 hooks = {};
1663 };
1664
1665 return DOMPurify;
1666}
1667
1668var purify = createDOMPurify();
1669
1670export { purify as default };
1671//# sourceMappingURL=purify.es.js.map