1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).DOMPurify=t()}(this,function(){"use strict";var r,o=Object.hasOwnProperty,i=Object.setPrototypeOf,a=Object.isFrozen,l=Object.getPrototypeOf,c=Object.getOwnPropertyDescriptor,_e=Object.freeze,e=Object.seal,s=Object.create,t="undefined"!=typeof Reflect&&Reflect,u=(u=t.apply)||function(e,t,n){return e.apply(t,n)},_e=_e||function(e){return e},e=e||function(e){return e},m=(m=t.construct)||function(e,t){return new(Function.prototype.bind.apply(e,[null].concat(function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(t))))},Ne=f(Array.prototype.forEach),Oe=f(Array.prototype.pop),Me=f(Array.prototype.push),Le=f(String.prototype.toLowerCase),Fe=f(String.prototype.match),Ie=f(String.prototype.replace),Ce=f(String.prototype.indexOf),ze=f(String.prototype.trim),Ue=f(RegExp.prototype.test),He=(r=TypeError,function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return m(r,t)});function f(o){return function(e){for(var t=arguments.length,n=Array(1<t?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return u(o,e,n)}}function je(e,t){i&&i(e,null);for(var n=t.length;n--;){var r,o=t[n];"string"!=typeof o||(r=Le(o))!==o&&(a(t)||(t[n]=r),o=r),e[o]=!0}return e}function Pe(e){var t=s(null),n=void 0;for(n in e)u(o,e,[n])&&(t[n]=e[n]);return t}function Be(e,t){for(;null!==e;){var n=c(e,t);if(n){if(n.get)return f(n.get);if("function"==typeof n.value)return f(n.value)}e=l(e)}return function(e){return console.warn("fallback value for",e),null}}var We=_e(["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"]),Ge=_e(["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"]),qe=_e(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Ke=_e(["animate","color-profile","cursor","discard","fedropshadow","feimage","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"]),Ve=_e(["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"]),Ye=_e(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Xe=_e(["#text"]),$e=_e(["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","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"]),Ze=_e(["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","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"]),Je=_e(["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"]),Qe=_e(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),et=e(/\{\{[\s\S]*|[\s\S]*\}\}/gm),tt=e(/<%[\s\S]*|[\s\S]*%>/gm),nt=e(/^data-[\-\w.\u00B7-\uFFFF]/),rt=e(/^aria-[\-\w]+$/),ot=e(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),it=e(/^(?:\w+script|data):/i),at=e(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),lt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function ct(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}var st=function(){return"undefined"==typeof window?null:window},ut=function(e,t){if("object"!==(void 0===e?"undefined":lt(e))||"function"!=typeof e.createPolicy)return null;var n=null,r="data-tt-policy-suffix";t.currentScript&&t.currentScript.hasAttribute(r)&&(n=t.currentScript.getAttribute(r));var o="dompurify"+(n?"#"+n:"");try{return e.createPolicy(o,{createHTML:function(e){return e}})}catch(e){return console.warn("TrustedTypes policy "+o+" could not be created."),null}};return function t(e){function s(e){return t(e)}var l=0<arguments.length&&void 0!==e?e:st();if(s.version="2.2.9",s.removed=[],!l||!l.document||9!==l.document.nodeType)return s.isSupported=!1,s;var c=l.document,i=l.document,u=l.DocumentFragment,n=l.HTMLTemplateElement,m=l.Node,a=l.Element,r=l.NodeFilter,o=l.NamedNodeMap,f=void 0===o?l.NamedNodeMap||l.MozNamedAttrMap:o,p=l.Text,d=l.Comment,g=l.DOMParser,e=l.trustedTypes,o=a.prototype,h=Be(o,"cloneNode"),y=Be(o,"nextSibling"),v=Be(o,"childNodes"),b=Be(o,"parentNode");"function"!=typeof n||(n=i.createElement("template")).content&&n.content.ownerDocument&&(i=n.content.ownerDocument);var A=ut(e,c),T=A&&Q?A.createHTML(""):"",x=i.implementation,w=i.createNodeIterator,S=i.createDocumentFragment,k=c.importNode,D={};try{D=Pe(i).documentMode?i.documentMode:{}}catch(e){}var E={};s.isSupported="function"==typeof b&&x&&void 0!==x.createHTMLDocument&&9!==D;function R(e){pe&&pe===e||(e&&"object"===(void 0===e?"undefined":lt(e))||(e={}),e=Pe(e),z="ALLOWED_TAGS"in e?je({},e.ALLOWED_TAGS):U,H="ALLOWED_ATTR"in e?je({},e.ALLOWED_ATTR):j,ae="ADD_URI_SAFE_ATTR"in e?je(Pe(le),e.ADD_URI_SAFE_ATTR):le,oe="ADD_DATA_URI_TAGS"in e?je(Pe(ie),e.ADD_DATA_URI_TAGS):ie,P="FORBID_TAGS"in e?je({},e.FORBID_TAGS):{},B="FORBID_ATTR"in e?je({},e.FORBID_ATTR):{},_="USE_PROFILES"in e&&e.USE_PROFILES,W=!1!==e.ALLOW_ARIA_ATTR,G=!1!==e.ALLOW_DATA_ATTR,q=e.ALLOW_UNKNOWN_PROTOCOLS||!1,K=e.SAFE_FOR_TEMPLATES||!1,V=e.WHOLE_DOCUMENT||!1,$=e.RETURN_DOM||!1,Z=e.RETURN_DOM_FRAGMENT||!1,J=!1!==e.RETURN_DOM_IMPORT,Q=e.RETURN_TRUSTED_TYPE||!1,X=e.FORCE_BODY||!1,ee=!1!==e.SANITIZE_DOM,te=!1!==e.KEEP_CONTENT,ne=e.IN_PLACE||!1,C=e.ALLOWED_URI_REGEXP||C,me=e.NAMESPACE||ue,K&&(G=!1),Z&&($=!0),_&&(z=je({},[].concat(ct(Xe))),H=[],!0===_.html&&(je(z,We),je(H,$e)),!0===_.svg&&(je(z,Ge),je(H,Ze),je(H,Qe)),!0===_.svgFilters&&(je(z,qe),je(H,Ze),je(H,Qe)),!0===_.mathMl&&(je(z,Ve),je(H,Je),je(H,Qe))),e.ADD_TAGS&&(z===U&&(z=Pe(z)),je(z,e.ADD_TAGS)),e.ADD_ATTR&&(H===j&&(H=Pe(H)),je(H,e.ADD_ATTR)),e.ADD_URI_SAFE_ATTR&&je(ae,e.ADD_URI_SAFE_ATTR),te&&(z["#text"]=!0),V&&je(z,["html","head","body"]),z.table&&(je(z,["tbody"]),delete P.tbody),_e&&_e(e),pe=e)}var _,N=et,O=tt,M=nt,L=rt,F=it,I=at,C=ot,z=null,U=je({},[].concat(ct(We),ct(Ge),ct(qe),ct(Ve),ct(Xe))),H=null,j=je({},[].concat(ct($e),ct(Ze),ct(Je),ct(Qe))),P=null,B=null,W=!0,G=!0,q=!1,K=!1,V=!1,Y=!1,X=!1,$=!1,Z=!1,J=!0,Q=!1,ee=!0,te=!0,ne=!1,re=je({},["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"]),oe=null,ie=je({},["audio","video","img","source","image","track"]),ae=null,le=je({},["alt","class","for","id","label","name","pattern","placeholder","summary","title","value","style","xmlns"]),ce="http://www.w3.org/1998/Math/MathML",se="http://www.w3.org/2000/svg",ue="http://www.w3.org/1999/xhtml",me=ue,fe=!1,pe=null,de=i.createElement("form"),ge=je({},["mi","mo","mn","ms","mtext"]),he=je({},["foreignobject","desc","title","annotation-xml"]),ye=je({},Ge);je(ye,qe),je(ye,Ke);var ve=je({},Ve);je(ve,Ye);function be(t){Me(s.removed,{element:t});try{t.parentNode.removeChild(t)}catch(e){try{t.outerHTML=T}catch(e){t.remove()}}}function Ae(e,t){try{Me(s.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){Me(s.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!H[e])if($||Z)try{be(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}}function Te(e){var t=void 0,n=void 0;X?e="<remove></remove>"+e:n=(o=Fe(e,/^[\r\n\t ]+/))&&o[0];var r=A?A.createHTML(e):e;if(me===ue)try{t=(new g).parseFromString(r,"text/html")}catch(e){}if(!t||!t.documentElement){t=x.createDocument(me,"template",null);try{t.documentElement.innerHTML=fe?"":r}catch(e){}}var o=t.body||t.documentElement;return e&&n&&o.insertBefore(i.createTextNode(n),o.childNodes[0]||null),V?t.documentElement:o}function xe(e){return w.call(e.ownerDocument||e,e,r.SHOW_ELEMENT|r.SHOW_COMMENT|r.SHOW_TEXT,null,!1)}function we(e){return"object"===(void 0===m?"undefined":lt(m))?e instanceof m:e&&"object"===(void 0===e?"undefined":lt(e))&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName}function Se(e,t,n){E[e]&&Ne(E[e],function(e){e.call(s,t,n,pe)})}function ke(e){var t;if(Se("beforeSanitizeElements",e,null),!((n=e)instanceof p||n instanceof d||"string"==typeof n.nodeName&&"string"==typeof n.textContent&&"function"==typeof n.removeChild&&n.attributes instanceof f&&"function"==typeof n.removeAttribute&&"function"==typeof n.setAttribute&&"string"==typeof n.namespaceURI&&"function"==typeof n.insertBefore))return be(e),1;if(Fe(e.nodeName,/[\u0080-\uFFFF]/))return be(e),1;var n=Le(e.nodeName);if(Se("uponSanitizeElement",e,{tagName:n,allowedTags:z}),!we(e.firstElementChild)&&(!we(e.content)||!we(e.content.firstElementChild))&&Ue(/<[/\w]/g,e.innerHTML)&&Ue(/<[/\w]/g,e.textContent))return be(e),1;if(z[n]&&!P[n])return e instanceof a&&!function(e){var t=b(e);t&&t.tagName||(t={namespaceURI:ue,tagName:"template"});var n=Le(e.tagName),r=Le(t.tagName);return e.namespaceURI===se?t.namespaceURI===ue?"svg"===n:t.namespaceURI===ce?"svg"===n&&("annotation-xml"===r||ge[r]):Boolean(ye[n]):e.namespaceURI===ce?t.namespaceURI===ue?"math"===n:t.namespaceURI===se?"math"===n&&he[r]:Boolean(ve[n]):e.namespaceURI===ue&&((t.namespaceURI!==se||he[r])&&((t.namespaceURI!==ce||ge[r])&&(r=je({},["title","style","font","a","script"]),!ve[n]&&(r[n]||!ye[n]))))}(e)||("noscript"===n||"noembed"===n)&&Ue(/<\/no(script|embed)/i,e.innerHTML)?(be(e),1):(K&&3===e.nodeType&&(t=e.textContent,t=Ie(t,N," "),t=Ie(t,O," "),e.textContent!==t&&(Me(s.removed,{element:e.cloneNode()}),e.textContent=t)),Se("afterSanitizeElements",e,null),0);if(te&&!re[n]){var r=b(e)||e.parentNode,o=v(e)||e.childNodes;if(o&&r)for(var i=o.length-1;0<=i;--i)r.insertBefore(h(o[i],!0),y(e))}return be(e),1}function De(e,t,n){if(ee&&("id"===t||"name"===t)&&(n in i||n in de))return!1;if(!(G&&Ue(M,t)||W&&Ue(L,t))){if(!H[t]||B[t])return!1;if(!ae[t]&&!Ue(C,Ie(n,I,""))&&("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==Ce(n,"data:")||!oe[e])&&(!q||Ue(F,Ie(n,I,"")))&&n)return!1}return!0}function Ee(e){var t=void 0,n=void 0;Se("beforeSanitizeAttributes",e,null);var r=e.attributes;if(r){for(var o={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:H},n=r.length;n--;){var i=(c=r[n]).name,a=c.namespaceURI,t=ze(c.value),l=Le(i);if(o.attrName=l,o.attrValue=t,o.keepAttr=!0,o.forceKeepAttr=void 0,Se("uponSanitizeAttribute",e,o),t=o.attrValue,!o.forceKeepAttr&&(Ae(i,e),o.keepAttr))if(Ue(/\/>/i,t))Ae(i,e);else{K&&(t=Ie(t,N," "),t=Ie(t,O," "));var c=e.nodeName.toLowerCase();if(De(c,l,t))try{a?e.setAttributeNS(a,i,t):e.setAttribute(i,t),Oe(s.removed)}catch(e){}}}Se("afterSanitizeAttributes",e,null)}}function Re(e){var t,n=xe(e);for(Se("beforeSanitizeShadowDOM",e,null);t=n.nextNode();)Se("uponSanitizeShadowNode",t,null),ke(t)||(t.content instanceof u&&Re(t.content),Ee(t));Se("afterSanitizeShadowDOM",e,null)}return s.sanitize=function(e,t){var n,r=void 0,o=void 0,i=void 0;if((fe=!e)&&(e="\x3c!--\x3e"),"string"!=typeof e&&!we(e)){if("function"!=typeof e.toString)throw He("toString is not a function");if("string"!=typeof(e=e.toString()))throw He("dirty is not a string, aborting")}if(!s.isSupported){if("object"===lt(l.toStaticHTML)||"function"==typeof l.toStaticHTML){if("string"==typeof e)return l.toStaticHTML(e);if(we(e))return l.toStaticHTML(e.outerHTML)}return e}if(Y||R(t),s.removed=[],"string"==typeof e&&(ne=!1),!ne)if(e instanceof m)1===(t=(r=Te("\x3c!----\x3e")).ownerDocument.importNode(e,!0)).nodeType&&"BODY"===t.nodeName||"HTML"===t.nodeName?r=t:r.appendChild(t);else{if(!$&&!K&&!V&&-1===e.indexOf("<"))return A&&Q?A.createHTML(e):e;if(!(r=Te(e)))return $?null:T}r&&X&&be(r.firstChild);for(var a=xe(ne?e:r);n=a.nextNode();)3===n.nodeType&&n===o||ke(n)||(n.content instanceof u&&Re(n.content),Ee(n),o=n);if(o=null,ne)return e;if($){if(Z)for(i=S.call(r.ownerDocument);r.firstChild;)i.appendChild(r.firstChild);else i=r;return J&&(i=k.call(c,i,!0)),i}return e=V?r.outerHTML:r.innerHTML,K&&(e=Ie(e,N," "),e=Ie(e,O," ")),A&&Q?A.createHTML(e):e},s.setConfig=function(e){R(e),Y=!0},s.clearConfig=function(){pe=null,Y=!1},s.isValidAttribute=function(e,t,n){return pe||R({}),e=Le(e),t=Le(t),De(e,t,n)},s.addHook=function(e,t){"function"==typeof t&&(E[e]=E[e]||[],Me(E[e],t))},s.removeHook=function(e){E[e]&&Oe(E[e])},s.removeHooks=function(e){E[e]&&(E[e]=[])},s.removeAllHooks=function(){E={}},s}()}); |