Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/*! @license DOMPurify 3.4.8 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.8/LICENSE */function_arrayLikeToArray(r, a){(null== a || a > r.length)&&(a = r.length);for(var e =0, n =Array(a); e < a; e++) n[e]= r[e];return n;}function_arrayWithHoles(r){if r r
t r r r
t
e
n
i
u
a
f
o
i t tr l f e it ae a l f
r
o n r
f t u t u u
o n
a
r r e r e
r
r r a
t r
t r t r t t r t t r a
entries
setPrototypeOf
isFrozen
getPrototypeOf
getOwnPropertyDescriptor
freeze
seal
create
_ref
apply _ref
construct _ref
freeze
x
seal
x
apply
_len arguments args _len _len _key _key _len _key
args_key arguments_key
functhisArg args
construct
_len2 arguments args _len2 _len2 _key2 _key2 _len2 _key2
args_key2 arguments_key2
args
arrayForEach
arrayLastIndexOf
arrayPop
arrayPush
arraySplice
arrayIsArray
stringToLowerCase
stringToString
stringMatch
stringReplace
stringIndexOf
stringTrim
numberToString
booleanToString
bigintToString
symbolToString
objectHasOwnProperty
objectToString
regExpTest
typeErrorCreate
thisArg
thisArg
_len3 arguments args _len3 _len3 _key3 _key3 _len3 _key3
args_key3 arguments_key3
func thisArg args
_len4 arguments args _len4 _key4 _key4 _len4 _key4
args_key4 arguments_key4
args
transformCaseFunc arguments arguments arguments stringToLowerCase
setPrototypeOf
set
array
set
l array
l
element arrayl
element
lcElement element
lcElement element
array
arrayl lcElement
element lcElement
element
set
index index array index
isPropertyExist array index
isPropertyExist
arrayindex
array
newObject
_ref2 object
_ref3 _ref2
property _ref3
value _ref3
isPropertyExist object property
isPropertyExist
value
newObjectproperty value
value value value
newObjectproperty value
newObjectproperty value
newObject
value
value
value
value
bigintToString value
symbolToString value
value
value
value
valueAsRecord value
valueToString valueAsRecord
valueToString
stringified valueAsRecord
stringified stringified stringified
value
value
object
desc object prop
desc
desc
desc
desc
desc
object object
fallbackValue
value
_unused
html$1
svg$1
svgFilters
svgDisallowed
mathMl$1
mathMlDisallowed
text
html
svg
mathMl
xml
trustedTypes trustedTypes
suffix
purifyHostElement purifyHostElement
suffix purifyHostElement
policyName suffix suffix
trustedTypespolicyName
html
scriptUrl
_
policyName
arguments arguments arguments
root
originalDocument
currentScript originalDocument
_window$NamedNodeMap
_window$NamedNodeMap _window$NamedNodeMap
trustedTypes
cloneNode
remove
getNextSibling
getChildNodes
getParentNode
getShadowRoot
getAttributes
getNodeType
getNodeName
template
template template
template
trustedTypesPolicy
emptyHTML
trustedTypesPolicyhtml
_document
implementation _document
createNodeIterator _document
createDocumentFragment _document
getElementsByTagName _document
importNode originalDocument
hooks
entries getParentNode implementation implementation
$1
$1
$1
$1
$1
$1
$1
$1
$1
html$1 svg$1 svgFilters mathMl$1 text
html svg mathMl xml
stringToString
transformCaseFunc
formElement
testValue testValue
cfg arguments arguments arguments
cfg
cfg cfg
cfg
cfg cfg
cfg cfg
transformCaseFunc stringToString stringToLowerCase
cfg cfg cfg transformCaseFunc
cfg cfg cfg transformCaseFunc
cfg cfg cfg stringToString
cfg cfg cfg transformCaseFunc
cfg cfg cfg transformCaseFunc
cfg cfg cfg transformCaseFunc
cfg cfg cfg transformCaseFunc
cfg cfg cfg transformCaseFunc
cfg cfg cfg cfg cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
cfg
$1 cfg cfg
cfg cfg
cfg cfg cfg cfg
cfg cfg cfg cfg
customElementHandling cfg cfg cfg cfg
customElementHandling customElementHandling
customElementHandling
customElementHandling customElementHandling
customElementHandling
customElementHandling customElementHandling
customElementHandling
text
html$1
html
svg$1
svg
xml
svgFilters
svg
xml
mathMl$1
mathMl
xml
cfg
cfg
cfg
cfg
cfg transformCaseFunc
cfg
cfg
cfg
cfg
cfg transformCaseFunc
cfg cfg
cfg transformCaseFunc
cfg cfg
cfg transformCaseFunc
cfg cfg
cfg transformCaseFunc
cfg
cfg
cfg
previousTrustedTypesPolicy trustedTypesPolicy
trustedTypesPolicy cfg
emptyHTML
error
trustedTypesPolicy previousTrustedTypesPolicy
error
trustedTypesPolicy cfg
trustedTypesPolicy trustedTypes currentScript
trustedTypesPolicy emptyHTML
emptyHTML
hooks hooks
hooks
freeze
cfg
cfg
svg$1 svgFilters svgDisallowed
mathMl$1 mathMlDisallowed
parent element
parent parent
parent
tagName element
parentTagName parent
element
element
parent
tagName
parent
tagName parentTagName parentTagName
tagName
element
parent
tagName
parent
tagName parentTagName
tagName
element
parent parentTagName
parent parentTagName
tagName tagName tagName
element
node
nodenode
_
node
elementname
element
_
element
elementname
name
element
_
elementname
_
doc
leadingWhitespace
dirty dirty
matches dirty
leadingWhitespace matches matches
dirty dirty
dirtyPayload trustedTypesPolicy dirty dirty
doc dirtyPayload
_
doc doc
doc implementation
doc emptyHTML dirtyPayload
_
body doc doc
dirty leadingWhitespace
bodyleadingWhitespace body
getElementsByTagNamedoc
doc body
createNodeIteratorroot root root
_node$querySelectorAl _node$querySelectorAl2
node
walker createNodeIteratornode node node
currentNode walker
currentNode
data currentNode
$1 $1 $1
data data expr
currentNode data
currentNode walker
templates _node$querySelectorAl _node$querySelectorAl2 node _node$querySelectorAl2 _node$querySelectorAl2node _node$querySelectorAl _node$querySelectorAl
templates
tmpl
tmpl
realTagName getNodeName element
realTagName
realTagName
element element element
element element element element element element element
element element
element element
getNodeType value value
value
_
getNodeType value value
value
_
hooks
hook currentNode data
content
hooks currentNode
currentNode
currentNode
tagName getNodeName currentNode currentNode
hooks currentNode
tagName
currentNode currentNode currentNode currentNode
currentNode
currentNode tagName currentNode
currentNode
currentNode
currentNode
currentNode currentNode
currentNode
tagName tagName tagName
tagName tagName
tagName
tagName
tagName
parentNode currentNode
childNodes currentNode
childNodes parentNode
childCount childNodes
i childCount i i
childClone childNodesi
parentNodechildClone currentNode
currentNode
nt getNodeType currentNode currentNode
nt currentNode
currentNode
tagName tagName tagName currentNode
currentNode
currentNode
content currentNode
$1 $1 $1
content content expr
currentNode content
currentNode
currentNode content
hooks currentNode
lcName
lcName lcName value value formElement
nameIsPermitted lcName lcName lcTag
lcName $1 lcName $1 lcName nameIsPermitted lcName
lcTag lcTag lcTag lcName lcName lcTag
lcName value value
lcName $1 value $1 lcName lcName lcName lcTag value lcTag $1 value $1 value
tagName $1 tagName
hooks currentNode
attributes currentNode
attributes currentNode
hookEvent
l attributes
l
attr attributesl
name attr
namespaceURI attr
attrValue attr
lcName name
initValue attrValue
value name initValue initValue
hookEvent lcName
hookEvent value
hookEvent
hookEvent
hooks currentNode hookEvent
value hookEvent
lcName lcName value
name currentNode
value value
value
name currentNode
lcName value
name currentNode
hookEvent
hookEvent
name currentNode
value
name currentNode
$1 $1 $1
value value expr
lcTag currentNode
lcTag lcName value
name currentNode
trustedTypesPolicy trustedTypes trustedTypes
namespaceURI
trustedTypeslcTag lcName
value value
value trustedTypesPolicyvalue
value initValue
namespaceURI
currentNodenamespaceURI name value
currentNodename value
currentNode
currentNode
_
name currentNode
hooks currentNode
shadowNode
shadowIterator fragment
hooks fragment
shadowNode shadowIterator
hooks shadowNode
shadowNode
shadowNode
shadowNode
shadowNode
shadowNodeType getNodeType shadowNode shadowNode
shadowNodeType
innerSr getShadowRoot shadowNode shadowNode
innerSr
innerSr
innerSr
hooks fragment
nodeType getNodeType root root
nodeType
sr getShadowRoot root root
sr
sr
sr
childNodes getChildNodes root root
childNodes
snapshot
childNodes
snapshot child
child snapshot
child
nodeType
rootName getNodeName root
rootName rootName
content root
content
content
cfg arguments arguments arguments
body
importedNode
currentNode
returnNode
dirty
dirty
dirty dirty
dirty dirty
dirty
dirty
cfg
dirty
nn getNodeName dirty dirty
nn
tagName nn
tagName tagName
dirty
dirty
dirty
body
importedNode bodydirty
importedNode importedNode
body importedNode
importedNode
body importedNode
bodyimportedNode
importedNode
dirty
trustedTypesPolicy dirty dirty
body dirty
body
emptyHTML
body
body
nodeIterator dirty body
currentNode nodeIterator
currentNode
currentNode
currentNode
currentNode
dirty
dirty
body
returnNode createDocumentFragmentbody
body
returnNodebody
returnNode body
returnNode importNodeoriginalDocument returnNode
returnNode
serializedHTML body body
body body body body
serializedHTML body serializedHTML
$1 $1 $1
serializedHTML serializedHTML expr
trustedTypesPolicy serializedHTML serializedHTML
cfg arguments arguments arguments
cfg
lcTag tag
lcName attr
lcTag lcName value
hookFunction
hooksentryPoint hookFunction
hookFunction
index hooksentryPoint hookFunction
index hooksentryPoint index
hooksentryPoint
hooksentryPoint
hooks
purify
"Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
)
;
}
function
_slicedToArray
(
r, e
)
{
return
_arrayWithHoles
(
)
||
_iterableToArrayLimit
(
,
)
||
_unsupportedIterableToArray
(
,
)
||
_nonIterableRest
(
)
;
}
function
_unsupportedIterableToArray
(
r, a
)
{
if
(
)
{
if
(
"string"
==
typeof
)
return
_arrayLikeToArray
(
,
)
;
var
=
{
}
.
toString
.
call
(
)
.
slice
(
8
,
-
1
)
;
return
"Object"
===
&&
.
constructor
&&
(
=
.
constructor
.
name
)
,
"Map"
===
||
"Set"
===
?
Array
.
from
(
)
:
"Arguments"
===
||
/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/
.
test
(
)
?
_arrayLikeToArray
(
,
)
:
void
0
;
}
}
const
=
Object
.
entries
,
=
Object
.
setPrototypeOf
,
=
Object
.
isFrozen
,
=
Object
.
getPrototypeOf
,
=
Object
.
getOwnPropertyDescriptor
;
let
=
Object
.
freeze
,
=
Object
.
seal
,
=
Object
.
create
;
// eslint-disable-line import/no-mutable-exports
let
=
typeof
Reflect
!==
'undefined'
&&
Reflect
,
=
.
apply
,
=
.
construct
;
if
(
!
)
{
freeze
=
function
freeze
(
x
)
{
return
;
}
;
}
if
(
!
)
{
seal
=
function
seal
(
x
)
{
return
;
}
;
}
if
(
!
)
{
apply
=
function
apply
(
func, thisArg
)
{
for
(
var
=
.
length
,
=
new
Array
(
>
2
?
-
2
:
0
)
,
=
2
;
<
;
++
)
{
[
-
2
]
=
[
]
;
}
return
.
apply
(
,
)
;
}
;
}
if
(
!
)
{
construct
=
function
construct
(
Func
)
{
for
(
var
=
.
length
,
=
new
Array
(
>
1
?
-
1
:
0
)
,
=
1
;
<
;
++
)
{
[
-
1
]
=
[
]
;
}
return
new
Func
(
...
)
;
}
;
}
const
=
unapply
(
Array
.
prototype
.
forEach
)
;
const
=
unapply
(
Array
.
prototype
.
lastIndexOf
)
;
const
=
unapply
(
Array
.
prototype
.
pop
)
;
const
=
unapply
(
Array
.
prototype
.
push
)
;
const
=
unapply
(
Array
.
prototype
.
splice
)
;
const
=
Array
.
isArray
;
const
=
unapply
(
String
.
prototype
.
toLowerCase
)
;
const
=
unapply
(
String
.
prototype
.
toString
)
;
const
=
unapply
(
String
.
prototype
.
match
)
;
const
=
unapply
(
String
.
prototype
.
replace
)
;
const
=
unapply
(
String
.
prototype
.
indexOf
)
;
const
=
unapply
(
String
.
prototype
.
trim
)
;
const
=
unapply
(
Number
.
prototype
.
toString
)
;
const
=
unapply
(
Boolean
.
prototype
.
toString
)
;
const
=
typeof
BigInt
===
'undefined'
?
null
:
unapply
(
BigInt
.
prototype
.
toString
)
;
const
=
typeof
Symbol
===
'undefined'
?
null
:
unapply
(
Symbol
.
prototype
.
toString
)
;
const
=
unapply
(
Object
.
prototype
.
hasOwnProperty
)
;
const
=
unapply
(
Object
.
prototype
.
toString
)
;
const
=
unapply
(
RegExp
.
prototype
.
test
)
;
const
=
unconstruct
(
TypeError
)
;
/**
* Creates a new function that calls the given function with a specified thisArg and arguments.
*
* @paramfunc - The function to be wrapped and called.
* @returns A new function that calls the given function with a specified thisArg and arguments.
*/
function
unapply
(
func
)
{
return
function
(
thisArg
)
{
if
(
instanceof
RegExp
)
{
.
lastIndex
=
0
;
}
for
(
var
=
.
length
,
=
new
Array
(
>
1
?
-
1
:
0
)
,
=
1
;
<
;
++
)
{
[
-
1
]
=
[
]
;
}
return
apply
(
,
,
)
;
}
;
}
/**
* Creates a new function that constructs an instance of the given constructor function with the provided arguments.
*
* @paramfunc - The constructor function to be wrapped and called.
* @returns A new function that constructs an instance of the given constructor function with the provided arguments.
*/
function
unconstruct
(
Func
)
{
return
function
(
)
{
for
(
var
=
.
length
,
=
new
Array
(
)
,
=
0
;
<
;
++
)
{
[
]
=
[
]
;
}
return
construct
(
Func
,
)
;
}
;
}
/**
* Add properties to a lookup table
*
* @paramset - The set to which elements will be added.
* @paramarray - The array containing elements to be added to the set.
* @paramtransformCaseFunc - An optional function to transform the case of each element before adding to the set.
* @returns The modified set with added elements.
*/
function
addToSet
(
set, array
)
{
let
=
.
length
>
2
&&
[
2
]
!==
undefined
?
[
2
]
:
;
if
(
)
{
// Make 'in' and truthy checks like Boolean(set.constructor)
// independent of any properties defined on Object.prototype.
// Prevent prototype setters from intercepting set as a this value.
setPrototypeOf
(
,
null
)
;
}
if
(
!
arrayIsArray
(
)
)
{
return
;
}
let
=
.
length
;
while
(
--
)
{
let
=
[
]
;
if
(
typeof
===
'string'
)
{
const
=
transformCaseFunc
(
)
;
if
(
!==
)
{
// Config presets (e.g. tags.js, attrs.js) are immutable.
if
(
!
isFrozen
(
)
)
{
[
]
=
;
}
=
;
}
}
set
[
]
=
true
;
}
return
;
}
/**
* Clean up an array to harden against CSPP
*
* @paramarray - The array to be cleaned.
* @returns The cleaned version of the array
*/
function
cleanArray
(
array
)
{
for
(
let
=
0
;
<
.
length
;
++
)
{
const
=
objectHasOwnProperty
(
,
)
;
if
(
!
)
{
[
]
=
null
;
}
}
return
;
}
/**
* Shallow clone an object
*
* @paramobject - The object to be cloned.
* @returns A new object that copies the original.
*/
function
clone
(
object
)
{
const
=
create
(
null
)
;
for
(
const
of
entries
(
)
)
{
var
=
_slicedToArray
(
,
2
)
;
const
=
[
0
]
;
const
=
[
1
]
;
const
=
objectHasOwnProperty
(
,
)
;
if
(
)
{
if
(
arrayIsArray
(
)
)
{
[
]
=
cleanArray
(
)
;
}
else
if
(
&&
typeof
===
'object'
&&
.
constructor
===
Object
)
{
[
]
=
clone
(
)
;
}
else
{
[
]
=
;
}
}
}
return
;
}
/**
* Convert non-node values into strings without depending on direct property access.
*
* @paramvalue - The value to stringify.
* @returns A string representation of the provided value.
*/
function
stringifyValue
(
value
)
{
switch
(
typeof
)
{
case
'string'
:
{
return
;
}
case
'number'
:
{
return
numberToString
(
)
;
}
case
'boolean'
:
{
return
booleanToString
(
)
;
}
case
'bigint'
:
{
return
?
bigintToString
(
)
:
'0'
;
}
case
'symbol'
:
{
return
?
symbolToString
(
)
:
'Symbol()'
;
}
case
'undefined'
:
{
return
objectToString
(
)
;
}
case
'function'
:
case
'object'
:
{
if
(
===
null
)
{
return
objectToString
(
)
;
}
const
=
;
const
=
lookupGetter
(
,
'toString'
)
;
if
(
typeof
===
'function'
)
{
const
=
valueToString
(
)
;
return
typeof
===
'string'
?
:
objectToString
(
)
;
}
return
objectToString
(
)
;
}
default
:
{
return
objectToString
(
)
;
}
}
}
/**
* This method automatically checks if the prop is function or getter and behaves accordingly.
*
* @paramobject - The object to look up the getter function in its prototype chain.
* @paramprop - The property name for which to find the getter function.
* @returns The getter function found in the prototype chain or a fallback function.
*/
function
lookupGetter
(
object, prop
)
{
while
(
!==
null
)
{
const
=
getOwnPropertyDescriptor
(
,
)
;
if
(
)
{
if
(
.
get
)
{
return
unapply
(
.
get
)
;
}
if
(
typeof
.
value
===
'function'
)
{
return
unapply
(
.
value
)
;
}
}
=
getPrototypeOf
(
)
;
}
function
fallbackValue
(
)
{
return
null
;
}
return
;
}
function
isRegex
(
value
)
{
try
{
regExpTest
(
,
''
)
;
return
true
;
}
catch
(
)
{
return
false
;
}
}
const
=
freeze
(
[
'a'
,
'abbr'
,
'acronym'
,
'address'
,
'area'
,
'article'
,
'aside'
,
'audio'
,
'b'
,
'bdi'
,
'bdo'
,
'big'
,
'blink'
,
'blockquote'
,
'body'
,
'br'
,
'button'
,
'canvas'
,
'caption'
,
'center'
,
'cite'
,
'code'
,
'col'
,
'colgroup'
,
'content'
,
'data'
,
'datalist'
,
'dd'
,
'decorator'
,
'del'
,
'details'
,
'dfn'
,
'dialog'
,
'dir'
,
'div'
,
'dl'
,
'dt'
,
'element'
,
'em'
,
'fieldset'
,
'figcaption'
,
'figure'
,
'font'
,
'footer'
,
'form'
,
'h1'
,
'h2'
,
'h3'
,
'h4'
,
'h5'
,
'h6'
,
'head'
,
'header'
,
'hgroup'
,
'hr'
,
'html'
,
'i'
,
'img'
,
'input'
,
'ins'
,
'kbd'
,
'label'
,
'legend'
,
'li'
,
'main'
,
'map'
,
'mark'
,
'marquee'
,
'menu'
,
'menuitem'
,
'meter'
,
'nav'
,
'nobr'
,
'ol'
,
'optgroup'
,
'option'
,
'output'
,
'p'
,
'picture'
,
'pre'
,
'progress'
,
'q'
,
'rp'
,
'rt'
,
'ruby'
,
's'
,
'samp'
,
'search'
,
'section'
,
'select'
,
'shadow'
,
'slot'
,
'small'
,
'source'
,
'spacer'
,
'span'
,
'strike'
,
'strong'
,
'style'
,
'sub'
,
'summary'
,
'sup'
,
'table'
,
'tbody'
,
'td'
,
'template'
,
'textarea'
,
'tfoot'
,
'th'
,
'thead'
,
'time'
,
'tr'
,
'track'
,
'tt'
,
'u'
,
'ul'
,
'var'
,
'video'
,
'wbr'
]
)
;
const
=
freeze
(
[
'svg'
,
'a'
,
'altglyph'
,
'altglyphdef'
,
'altglyphitem'
,
'animatecolor'
,
'animatemotion'
,
'animatetransform'
,
'circle'
,
'clippath'
,
'defs'
,
'desc'
,
'ellipse'
,
'enterkeyhint'
,
'exportparts'
,
'filter'
,
'font'
,
'g'
,
'glyph'
,
'glyphref'
,
'hkern'
,
'image'
,
'inputmode'
,
'line'
,
'lineargradient'
,
'marker'
,
'mask'
,
'metadata'
,
'mpath'
,
'part'
,
'path'
,
'pattern'
,
'polygon'
,
'polyline'
,
'radialgradient'
,
'rect'
,
'stop'
,
'style'
,
'switch'
,
'symbol'
,
'text'
,
'textpath'
,
'title'
,
'tref'
,
'tspan'
,
'view'
,
'vkern'
]
)
;
const
=
freeze
(
[
'feBlend'
,
'feColorMatrix'
,
'feComponentTransfer'
,
'feComposite'
,
'feConvolveMatrix'
,
'feDiffuseLighting'
,
'feDisplacementMap'
,
'feDistantLight'
,
'feDropShadow'
,
'feFlood'
,
'feFuncA'
,
'feFuncB'
,
'feFuncG'
,
'feFuncR'
,
'feGaussianBlur'
,
'feImage'
,
'feMerge'
,
'feMergeNode'
,
'feMorphology'
,
'feOffset'
,
'fePointLight'
,
'feSpecularLighting'
,
'feSpotLight'
,
'feTile'
,
'feTurbulence'
]
)
;
// List of SVG elements that are disallowed by default.
// We still need to know them so that we can do namespace
// checks properly in case one wants to add them to
// allow-list.
const
=
freeze
(
[
'animate'
,
'color-profile'
,
'cursor'
,
'discard'
,
'font-face'
,
'font-face-format'
,
'font-face-name'
,
'font-face-src'
,
'font-face-uri'
,
'foreignobject'
,
'hatch'
,
'hatchpath'
,
'mesh'
,
'meshgradient'
,
'meshpatch'
,
'meshrow'
,
'missing-glyph'
,
'script'
,
'set'
,
'solidcolor'
,
'unknown'
,
'use'
]
)
;
const
=
freeze
(
[
'math'
,
'menclose'
,
'merror'
,
'mfenced'
,
'mfrac'
,
'mglyph'
,
'mi'
,
'mlabeledtr'
,
'mmultiscripts'
,
'mn'
,
'mo'
,
'mover'
,
'mpadded'
,
'mphantom'
,
'mroot'
,
'mrow'
,
'ms'
,
'mspace'
,
'msqrt'
,
'mstyle'
,
'msub'
,
'msup'
,
'msubsup'
,
'mtable'
,
'mtd'
,
'mtext'
,
'mtr'
,
'munder'
,
'munderover'
,
'mprescripts'
]
)
;
// Similarly to SVG, we want to know all MathML elements,
/**
* Creates a no-op policy for internal use only.
* Don't export this function outside this module!
* @paramtrustedTypes The policy factory.
* @parampurifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
* @return The policy created (or null, if Trusted Types
* are not supported or creating the policy failed).
*/
const
_createTrustedTypesPolicy
=
function
_createTrustedTypesPolicy
(
trustedTypes, purifyHostElement
)
{
if
(
typeof
!==
'object'
||
typeof
.
createPolicy
!==
'function'
)
{
return
null
;
}
// Allow the callers to control the unique policy name
// by adding a data-tt-policy-suffix to the script element with the DOMPurify.
// Policy creation with duplicate names throws in Trusted Types.
let
=
null
;
const
ATTR_NAME
=
'data-tt-policy-suffix'
;
if
(
&&
.
hasAttribute
(
ATTR_NAME
)
)
{
=
.
getAttribute
(
ATTR_NAME
)
;
}
const
=
'dompurify'
+
(
?
'#'
+
:
''
)
;
try
{
return
.
createPolicy
(
,
{
createHTML
(
html
)
{
return
;
}
,
createScriptURL
(
scriptUrl
)
{
return
;
}
}
)
;
}
catch
(
)
{
// Policy creation failed (most likely another DOMPurify script has
// already run). Skip creating the policy, as this will only cause errors
// if TT are enforced.
console
.
warn
(
'TrustedTypes policy '
+
+
' could not be created.'
)
;
return
null
;
}
}
;
const
_createHooksMap
=
function
_createHooksMap
(
)
{
return
{
afterSanitizeAttributes
:
[
]
,
afterSanitizeElements
:
[
]
,
afterSanitizeShadowDOM
:
[
]
,
beforeSanitizeAttributes
:
[
]
,
beforeSanitizeElements
:
[
]
,
beforeSanitizeShadowDOM
:
[
]
,
uponSanitizeAttribute
:
[
]
,
uponSanitizeElement
:
[
]
,
uponSanitizeShadowNode
:
[
]
}
;
}
;
function
createDOMPurify
(
)
{
let
window
=
.
length
>
0
&&
[
0
]
!==
undefined
?
[
0
]
:
getGlobal
(
)
;
const
DOMPurify
=
root
=>
createDOMPurify
(
)
;
DOMPurify
.
version
=
'3.4.8'
;
DOMPurify
.
removed
=
[
]
;
if
(
!
window
||
!
window
.
document
||
window
.
document
.
nodeType
!==
NODE_TYPE
.
document
||
!
window
.
Element
)
{
// Not running in a browser, provide a factory function
// so that you can pass your own Window
DOMPurify
.
isSupported
=
false
;
return
DOMPurify
;
}
let
document
=
window
.
document
;
const
=
document
;
const
=
.
currentScript
;
window
.
DocumentFragment
;
const
HTMLTemplateElement
=
window
.
HTMLTemplateElement
,
Node
=
window
.
Node
,
Element
=
window
.
Element
,
NodeFilter
=
window
.
NodeFilter
,
=
window
.
NamedNodeMap
;
===
void
0
?
window
.
NamedNodeMap
||
window
.
MozNamedAttrMap
:
;
window
.
HTMLFormElement
;
const
DOMParser
=
window
.
DOMParser
,
=
window
.
trustedTypes
;
const
ElementPrototype
=
Element
.
prototype
;
const
=
lookupGetter
(
ElementPrototype
,
'cloneNode'
)
;
const
=
lookupGetter
(
ElementPrototype
,
'remove'
)
;
const
=
lookupGetter
(
ElementPrototype
,
'nextSibling'
)
;
const
=
lookupGetter
(
ElementPrototype
,
'childNodes'
)
;
const
=
lookupGetter
(
ElementPrototype
,
'parentNode'
)
;
const
=
lookupGetter
(
ElementPrototype
,
'shadowRoot'
)
;
const
=
lookupGetter
(
ElementPrototype
,
'attributes'
)
;
const
=
Node
&&
Node
.
prototype
?
lookupGetter
(
Node
.
prototype
,
'nodeType'
)
:
null
;
const
=
Node
&&
Node
.
prototype
?
lookupGetter
(
Node
.
prototype
,
'nodeName'
)
:
null
;
// As per issue #47, the web-components registry is inherited by a
// new document created via createHTMLDocument. As per the spec
// a new empty registry is used when creating a template contents owner
// document, so we use that as our parent document to ensure nothing
// is inherited.
if
(
typeof
HTMLTemplateElement
===
'function'
)
{
const
=
document
.
createElement
(
'template'
)
;
if
(
.
content
&&
.
content
.
ownerDocument
)
{
document
=
.
content
.
ownerDocument
;
}
}
let
;
let
=
''
;
// Tracks whether we are already inside a call to the configured Trusted Types
// policy's `createHTML`. If the supplied `TRUSTED_TYPES_POLICY.createHTML`
// itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
// re-enter the policy and recurse until the stack overflows. We detect that
// re-entry and throw a clear, actionable error instead.
let
IN_POLICY_CREATE_HTML
=
0
;
const
_createTrustedHTML
=
function
_createTrustedHTML
(
html
)
{
if
(
IN_POLICY_CREATE_HTML
>
0
)
{
throw
typeErrorCreate
(
'The configured TRUSTED_TYPES_POLICY.createHTML must not call '
+
'DOMPurify.sanitize, as that causes infinite recursion. Do not pass '
+
'a policy whose createHTML wraps DOMPurify as TRUSTED_TYPES_POLICY; '
+
'see the "DOMPurify and Trusted Types" section of the README.'
)
;
}
IN_POLICY_CREATE_HTML
++
;
try
{
return
.
createHTML
(
)
;
}
finally
{
IN_POLICY_CREATE_HTML
--
;
}
}
;
const
=
document
,
=
.
implementation
,
=
.
createNodeIterator
,
=
.
createDocumentFragment
,
=
.
getElementsByTagName
;
const
=
.
importNode
;
let
=
_createHooksMap
(
)
;
/**
* Expose whether this browser supports running the full DOMPurify.
*/
DOMPurify
.
isSupported
=
typeof
===
'function'
&&
typeof
===
'function'
&&
&&
.
createHTMLDocument
!==
undefined
;
const
MUSTACHE_EXPR
=
MUSTACHE_EXPR
,
ERB_EXPR
=
ERB_EXPR
,
TMPLIT_EXPR
=
TMPLIT_EXPR
,
DATA_ATTR
=
DATA_ATTR
,
ARIA_ATTR
=
ARIA_ATTR
,
IS_SCRIPT_OR_DATA
=
IS_SCRIPT_OR_DATA
,
ATTR_WHITESPACE
=
ATTR_WHITESPACE
,
CUSTOM_ELEMENT
=
CUSTOM_ELEMENT
;
let
IS_ALLOWED_URI
=
IS_ALLOWED_URI
;
/**
* We consider the elements and attributes below to be safe. Ideally
* don't add any new ones but feel free to remove unwanted ones.
*/
/* allowed element names */
let
ALLOWED_TAGS
=
null
;
const
DEFAULT_ALLOWED_TAGS
=
addToSet
(
{
}
,
[
...
,
...
,
...
,
...
,
...
]
)
;
/* Allowed attribute names */
let
ALLOWED_ATTR
=
null
;
const
DEFAULT_ALLOWED_ATTR
=
addToSet
(
{
}
,
[
...
,
...
,
...
,
...
]
)
;
/*
* Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
* @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
* @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
* @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
*/
/* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
const
EXTRA_ELEMENT_HANDLING
=
Object
.
seal
(
create
(
null
,
{
tagCheck
:
{
writable
:
true
,
configurable
:
false
,
enumerable
:
true
,
value
:
null
}
,
attributeCheck
:
{
writable
:
true
,
configurable
:
false
,
enumerable
:
true
,
value
:
null
}
}
)
)
;
/* Decide if ARIA attributes are okay */
let
ALLOW_ARIA_ATTR
=
true
;
/* Decide if custom data attributes are okay */
let
ALLOW_DATA_ATTR
=
true
;
/* Decide if unknown protocols are okay */
let
ALLOW_UNKNOWN_PROTOCOLS
=
false
;
/* Decide if self-closing tags in attributes are allowed.
* Usually removed due to a mXSS issue in jQuery 3.0 */
let
ALLOW_SELF_CLOSE_IN_ATTR
=
true
;
/* Output should be safe for common template engines.
* This means, DOMPurify removes data attributes, mustaches and ERB
*/
let
SAFE_FOR_TEMPLATES
=
false
;
/* Output should be safe even for XML used within HTML and alike.
* This means, DOMPurify removes comments when containing risky content.
*/
let
SAFE_FOR_XML
=
true
;
/* Decide if document with <html>... should be returned */
let
WHOLE_DOCUMENT
=
false
;
/* Track whether config is already set on this instance of DOMPurify. */
let
SET_CONFIG
=
false
;
/* Decide if all elements (e.g. style, script) must be children of
* document.body. By default, browsers might move them to document.head */
let
FORCE_BODY
=
false
;
/* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
* string (or a TrustedHTML object if Trusted Types are supported).
* If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
*/
let
RETURN_DOM
=
false
;
/* Decide if a DOM `DocumentFragment` should be returned, instead of a html
* string (or a TrustedHTML object if Trusted Types are supported) */
let
RETURN_DOM_FRAGMENT
=
false
;
/* Try to return a Trusted Type object instead of a string, return a string in
* case Trusted Types are not supported */
let
RETURN_TRUSTED_TYPE
=
false
;
/* Output should be free from DOM clobbering attacks?
* This sanitizes markups named with colliding, clobberable built-in DOM APIs.
*/
let
SANITIZE_DOM
=
true
;
/* Achieve full DOM Clobbering protection by isolating the namespace of named
* properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
*
* HTML/DOM spec rules that enable DOM Clobbering:
* - Named Access on Window (§7.3.3)
* - DOM Tree Accessors (§3.1.5)
* - Form Element Parent-Child Relations (§4.10.3)
* - Iframe srcdoc / Nested WindowProxies (§4.8.5)
* - HTMLCollection (§4.2.10.2)
*
* Namespace isolation is implemented by prefixing `id` and `name` attributes
* with a constant string, i.e., `user-content-`
*/
let
SANITIZE_NAMED_PROPS
=
false
;
const
SANITIZE_NAMED_PROPS_PREFIX
=
'user-content-'
;
/* Keep element content when removing element? */
let
KEEP_CONTENT
=
true
;
/* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
* of importing it into a new Document and returning a sanitized copy */
let
IN_PLACE
=
false
;
/* Allow usage of profiles like html, svg and mathMl */
let
USE_PROFILES
=
{
}
;
/* Tags to ignore content of when KEEP_CONTENT is true */
let
FORBID_CONTENTS
=
null
;
const
DEFAULT_FORBID_CONTENTS
=
addToSet
(
{
}
,
[
'annotation-xml'
,
'audio'
,
'colgroup'
,
'desc'
,
'foreignobject'
,
'head'
,
'iframe'
,
'math'
,
'mi'
,
'mn'
,
'mo'
,
'ms'
,
'mtext'
,
'noembed'
,
'noframes'
,
'noscript'
,
'plaintext'
,
'script'
,
'style'
,
'svg'
,
'template'
,
'thead'
,
'title'
,
'video'
,
'xmp'
]
)
;
/* Tags that are safe for data: URIs */
let
DATA_URI_TAGS
=
null
;
const
DEFAULT_DATA_URI_TAGS
=
addToSet
(
{
}
,
[
'audio'
,
'video'
,
'img'
,
'source'
,
'image'
,
'track'
]
)
;
/* Attributes safe for values like "javascript:" */
let
URI_SAFE_ATTRIBUTES
=
null
;
const
DEFAULT_URI_SAFE_ATTRIBUTES
=
addToSet
(
{
}
,
[
'alt'
,
'class'
,
'for'
,
'id'
,
'label'
,
'name'
,
'pattern'
,
'placeholder'
,
'role'
,
'summary'
,
'title'
,
'value'
,
'style'
,
'xmlns'
]
)
;
const
MATHML_NAMESPACE
=
'http://www.w3.org/1998/Math/MathML'
;
const
SVG_NAMESPACE
=
'http://www.w3.org/2000/svg'
;
const
HTML_NAMESPACE
=
'http://www.w3.org/1999/xhtml'
;
/* Document namespace */
let
NAMESPACE
=
HTML_NAMESPACE
;
let
IS_EMPTY_INPUT
=
false
;
/* Allowed XHTML+XML namespaces */
let
ALLOWED_NAMESPACES
=
null
;
const
DEFAULT_ALLOWED_NAMESPACES
=
addToSet
(
{
}
,
[
MATHML_NAMESPACE
,
SVG_NAMESPACE
,
HTML_NAMESPACE
]
,
)
;
let
MATHML_TEXT_INTEGRATION_POINTS
=
addToSet
(
{
}
,
[
'mi'
,
'mo'
,
'mn'
,
'ms'
,
'mtext'
]
)
;
let
HTML_INTEGRATION_POINTS
=
addToSet
(
{
}
,
[
'annotation-xml'
]
)
;
// Certain elements are allowed in both SVG and HTML
// namespace. We need to specify them explicitly
// so that they don't get erroneously deleted from
// HTML namespace.
const
COMMON_SVG_AND_HTML_ELEMENTS
=
addToSet
(
{
}
,
[
'title'
,
'style'
,
'font'
,
'a'
,
'script'
]
)
;
/* Parsing of strict XHTML documents */
let
PARSER_MEDIA_TYPE
=
null
;
const
SUPPORTED_PARSER_MEDIA_TYPES
=
[
'application/xhtml+xml'
,
'text/html'
]
;
const
DEFAULT_PARSER_MEDIA_TYPE
=
'text/html'
;
let
=
null
;
/* Keep a reference to config to pass to hooks */
let
CONFIG
=
null
;
/* Ideally, do not touch anything below this line */
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
=
PARSER_MEDIA_TYPE
===
'application/xhtml+xml'
?
:
;
/* Set configuration parameters */
ALLOWED_TAGS
=
objectHasOwnProperty
(
,
'ALLOWED_TAGS'
)
&&
arrayIsArray
(
.
ALLOWED_TAGS
)
?
addToSet
(
{
}
,
.
ALLOWED_TAGS
,
)
:
DEFAULT_ALLOWED_TAGS
;
ALLOWED_ATTR
=
objectHasOwnProperty
(
,
'ALLOWED_ATTR'
)
&&
arrayIsArray
(
.
ALLOWED_ATTR
)
?
addToSet
(
{
}
,
.
ALLOWED_ATTR
,
)
:
DEFAULT_ALLOWED_ATTR
;
ALLOWED_NAMESPACES
=
objectHasOwnProperty
(
,
'ALLOWED_NAMESPACES'
)
&&
arrayIsArray
(
.
ALLOWED_NAMESPACES
)
?
addToSet
(
{
}
,
.
ALLOWED_NAMESPACES
,
)
:
DEFAULT_ALLOWED_NAMESPACES
;
URI_SAFE_ATTRIBUTES
=
objectHasOwnProperty
(
,
'ADD_URI_SAFE_ATTR'
)
&&
arrayIsArray
(
.
ADD_URI_SAFE_ATTR
)
?
addToSet
(
clone
(
DEFAULT_URI_SAFE_ATTRIBUTES
)
,
.
ADD_URI_SAFE_ATTR
,
)
:
DEFAULT_URI_SAFE_ATTRIBUTES
;
DATA_URI_TAGS
=
objectHasOwnProperty
(
,
'ADD_DATA_URI_TAGS'
)
&&
arrayIsArray
(
.
ADD_DATA_URI_TAGS
)
?
addToSet
(
clone
(
DEFAULT_DATA_URI_TAGS
)
,
.
ADD_DATA_URI_TAGS
,
)
:
DEFAULT_DATA_URI_TAGS
;
FORBID_CONTENTS
=
objectHasOwnProperty
(
,
'FORBID_CONTENTS'
)
&&
arrayIsArray
(
.
FORBID_CONTENTS
)
?
addToSet
(
{
}
,
.
FORBID_CONTENTS
,
)
:
DEFAULT_FORBID_CONTENTS
;
FORBID_TAGS
=
objectHasOwnProperty
(
,
'FORBID_TAGS'
)
&&
arrayIsArray
(
.
FORBID_TAGS
)
?
addToSet
(
{
}
,
.
FORBID_TAGS
,
)
:
clone
(
{
}
)
;
FORBID_ATTR
=
objectHasOwnProperty
(
,
'FORBID_ATTR'
)
&&
arrayIsArray
(
.
FORBID_ATTR
)
?
addToSet
(
{
}
,
.
FORBID_ATTR
,
)
:
clone
(
{
}
)
;
USE_PROFILES
=
objectHasOwnProperty
(
,
'USE_PROFILES'
)
?
.
USE_PROFILES
&&
typeof
.
USE_PROFILES
===
'object'
?
clone
(
.
USE_PROFILES
)
:
.
USE_PROFILES
:
false
;
ALLOW_ARIA_ATTR
=
.
ALLOW_ARIA_ATTR
!==
false
;
// Default true
ALLOW_DATA_ATTR
=
.
ALLOW_DATA_ATTR
!==
false
;
// Default true
ALLOW_UNKNOWN_PROTOCOLS
=
.
ALLOW_UNKNOWN_PROTOCOLS
||
false
;
// Default false
ALLOW_SELF_CLOSE_IN_ATTR
=
.
ALLOW_SELF_CLOSE_IN_ATTR
!==
false
;
// Default true
SAFE_FOR_TEMPLATES
=
.
SAFE_FOR_TEMPLATES
||
false
;
// Default false
SAFE_FOR_XML
=
.
SAFE_FOR_XML
!==
false
;
// Default true
WHOLE_DOCUMENT
=
.
WHOLE_DOCUMENT
||
false
;
// Default false
RETURN_DOM
=
.
RETURN_DOM
||
false
;
// Default false
RETURN_DOM_FRAGMENT
=
.
RETURN_DOM_FRAGMENT
||
false
;
// Default false
RETURN_TRUSTED_TYPE
=
.
RETURN_TRUSTED_TYPE
||
false
;
// Default false
FORCE_BODY
=
.
FORCE_BODY
||
false
;
// Default false
SANITIZE_DOM
=
.
SANITIZE_DOM
!==
false
;
// Default true
SANITIZE_NAMED_PROPS
=
.
SANITIZE_NAMED_PROPS
||
false
;
// Default false
KEEP_CONTENT
=
.
KEEP_CONTENT
!==
false
;
// Default true
IN_PLACE
=
.
IN_PLACE
||
false
;
// Default false
IS_ALLOWED_URI
=
isRegex
(
.
ALLOWED_URI_REGEXP
)
?
.
ALLOWED_URI_REGEXP
:
IS_ALLOWED_URI
;
// Default regexp
NAMESPACE
=
typeof
.
NAMESPACE
===
'string'
?
.
NAMESPACE
:
HTML_NAMESPACE
;
// Default HTML namespace
MATHML_TEXT_INTEGRATION_POINTS
=
objectHasOwnProperty
(
,
'MATHML_TEXT_INTEGRATION_POINTS'
)
&&
.
MATHML_TEXT_INTEGRATION_POINTS
&&
typeof
.
MATHML_TEXT_INTEGRATION_POINTS
===
'object'
?
clone
(
.
MATHML_TEXT_INTEGRATION_POINTS
)
:
addToSet
(
{
}
,
[
'mi'
,
'mo'
,
'mn'
,
'ms'
,
'mtext'
]
)
;
// Default built-in map
HTML_INTEGRATION_POINTS
=
objectHasOwnProperty
(
,
'HTML_INTEGRATION_POINTS'
)
&&
.
HTML_INTEGRATION_POINTS
&&
typeof
.
HTML_INTEGRATION_POINTS
===
'object'
?
clone
(
.
HTML_INTEGRATION_POINTS
)
:
addToSet
(
{
}
,
[
'annotation-xml'
]
)
;
// Default built-in map
const
=
objectHasOwnProperty
(
,
'CUSTOM_ELEMENT_HANDLING'
)
&&
.
CUSTOM_ELEMENT_HANDLING
&&
typeof
.
CUSTOM_ELEMENT_HANDLING
===
'object'
?
clone
(
.
CUSTOM_ELEMENT_HANDLING
)
:
create
(
null
)
;
CUSTOM_ELEMENT_HANDLING
=
create
(
null
)
;
if
(
objectHasOwnProperty
(
,
'tagNameCheck'
)
&&
isRegexOrFunction
(
.
tagNameCheck
)
)
{
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
=
.
tagNameCheck
;
// Default undefined
}
if
(
objectHasOwnProperty
(
,
'attributeNameCheck'
)
&&
isRegexOrFunction
(
.
attributeNameCheck
)
)
{
CUSTOM_ELEMENT_HANDLING
.
attributeNameCheck
=
.
attributeNameCheck
;
// Default undefined
}
if
(
objectHasOwnProperty
(
,
'allowCustomizedBuiltInElements'
)
&&
typeof
.
allowCustomizedBuiltInElements
===
'boolean'
)
{
CUSTOM_ELEMENT_HANDLING
.
allowCustomizedBuiltInElements
=
.
allowCustomizedBuiltInElements
;
// Default undefined
}
if
(
SAFE_FOR_TEMPLATES
)
{
ALLOW_DATA_ATTR
=
false
;
}
if
(
RETURN_DOM_FRAGMENT
)
{
RETURN_DOM
=
true
;
}
/* Parse profile info */
if
(
USE_PROFILES
)
{
ALLOWED_TAGS
=
addToSet
(
{
}
,
)
;
ALLOWED_ATTR
=
create
(
null
)
;
if
(
USE_PROFILES
.
html
===
true
)
{
addToSet
(
ALLOWED_TAGS
,
)
;
addToSet
(
ALLOWED_ATTR
,
)
;
}
if
(
USE_PROFILES
.
svg
===
true
)
{
addToSet
(
ALLOWED_TAGS
,
)
;
addToSet
(
ALLOWED_ATTR
,
)
;
addToSet
(
ALLOWED_ATTR
,
)
;
}
if
(
USE_PROFILES
.
svgFilters
===
true
)
{
addToSet
(
ALLOWED_TAGS
,
)
;
addToSet
(
ALLOWED_ATTR
,
)
;
addToSet
(
ALLOWED_ATTR
,
)
;
}
if
(
USE_PROFILES
.
mathMl
===
true
)
{
addToSet
(
ALLOWED_TAGS
,
)
;
addToSet
(
ALLOWED_ATTR
,
)
;
addToSet
(
ALLOWED_ATTR
,
)
;
}
}
/* Always reset function-based ADD_TAGS / ADD_ATTR checks to prevent
* leaking across calls when switching from function to array config */
EXTRA_ELEMENT_HANDLING
.
tagCheck
=
null
;
EXTRA_ELEMENT_HANDLING
.
attributeCheck
=
null
;
/* Merge configuration parameters */
if
(
objectHasOwnProperty
(
,
'ADD_TAGS'
)
)
{
if
(
typeof
.
ADD_TAGS
===
'function'
)
{
EXTRA_ELEMENT_HANDLING
.
tagCheck
=
.
ADD_TAGS
;
}
else
if
(
arrayIsArray
(
.
ADD_TAGS
)
)
{
if
(
ALLOWED_TAGS
===
DEFAULT_ALLOWED_TAGS
)
{
ALLOWED_TAGS
=
clone
(
ALLOWED_TAGS
)
;
}
addToSet
(
ALLOWED_TAGS
,
.
ADD_TAGS
,
)
;
}
}
if
(
objectHasOwnProperty
(
,
'ADD_ATTR'
)
)
{
if
(
typeof
.
ADD_ATTR
===
'function'
)
{
EXTRA_ELEMENT_HANDLING
.
attributeCheck
=
.
ADD_ATTR
;
}
else
if
(
arrayIsArray
(
.
ADD_ATTR
)
)
{
if
(
ALLOWED_ATTR
===
DEFAULT_ALLOWED_ATTR
)
{
ALLOWED_ATTR
=
clone
(
ALLOWED_ATTR
)
;
}
addToSet
(
ALLOWED_ATTR
,
.
ADD_ATTR
,
)
;
}
}
if
(
objectHasOwnProperty
(
,
'ADD_URI_SAFE_ATTR'
)
&&
arrayIsArray
(
.
ADD_URI_SAFE_ATTR
)
)
{
addToSet
(
URI_SAFE_ATTRIBUTES
,
.
ADD_URI_SAFE_ATTR
,
)
;
}
if
(
objectHasOwnProperty
(
,
'FORBID_CONTENTS'
)
&&
arrayIsArray
(
.
FORBID_CONTENTS
)
)
{
if
(
FORBID_CONTENTS
===
DEFAULT_FORBID_CONTENTS
)
{
FORBID_CONTENTS
=
clone
(
FORBID_CONTENTS
)
;
}
addToSet
(
FORBID_CONTENTS
,
.
FORBID_CONTENTS
,
)
;
}
if
(
objectHasOwnProperty
(
,
'ADD_FORBID_CONTENTS'
)
&&
arrayIsArray
(
.
ADD_FORBID_CONTENTS
)
)
{
if
(
FORBID_CONTENTS
===
DEFAULT_FORBID_CONTENTS
)
{
FORBID_CONTENTS
=
clone
(
FORBID_CONTENTS
)
;
}
addToSet
(
FORBID_CONTENTS
,
.
ADD_FORBID_CONTENTS
,
)
;
}
/* Add #text in case KEEP_CONTENT is set to true */
if
(
KEEP_CONTENT
)
{
ALLOWED_TAGS
[
'#text'
]
=
true
;
}
/* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
if
(
WHOLE_DOCUMENT
)
{
addToSet
(
ALLOWED_TAGS
,
[
'html'
,
'head'
,
'body'
]
)
;
}
/* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
if
(
ALLOWED_TAGS
.
table
)
{
addToSet
(
ALLOWED_TAGS
,
[
'tbody'
]
)
;
delete
FORBID_TAGS
.
tbody
;
}
if
(
.
TRUSTED_TYPES_POLICY
)
{
if
(
typeof
.
TRUSTED_TYPES_POLICY
.
createHTML
!==
'function'
)
{
throw
typeErrorCreate
(
'TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.'
)
;
}
if
(
typeof
.
TRUSTED_TYPES_POLICY
.
createScriptURL
!==
'function'
)
{
throw
typeErrorCreate
(
'TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.'
)
;
}
// Overwrite existing TrustedTypes policy.
const
=
;
=
.
TRUSTED_TYPES_POLICY
;
// Sign local variables required by `sanitize`. If the supplied policy's
// `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
// throws via the re-entrancy guard. Restore the previous policy first so
// the instance is not left in a poisoned state. See #1422.
try
{
=
_createTrustedHTML
(
''
)
;
}
catch
(
)
{
=
;
throw
;
}
}
else
{
// Uninitialized policy, attempt to initialize the internal dompurify policy.
if
(
===
undefined
&&
.
TRUSTED_TYPES_POLICY
!==
null
)
{
=
_createTrustedTypesPolicy
(
,
)
;
}
// If creating the internal policy succeeded sign internal variables.
// Note: a falsy `trustedTypesPolicy` (null when policy creation failed or
// was skipped via `TRUSTED_TYPES_POLICY: null`, or undefined when no
// policy has been initialized yet) must be excluded here, otherwise we
// would call `.createHTML` on a non-policy and throw. See #1422.
if
(
&&
typeof
===
'string'
)
{
=
_createTrustedHTML
(
''
)
;
}
}
/*
* Mirror the clone-before-mutate pattern already applied above for
* cfg.ADD_TAGS / cfg.ADD_ATTR: if any uponSanitize* hook is
* registered AND the set still points at the default constant,
* clone it. The hook then mutates the clone (in-call widening
* still works exactly as documented) and the next default-cfg
* call rebinds to the untouched original via the reassignment at
* the top of this function.
*/
if
(
(
.
uponSanitizeElement
.
length
>
0
||
.
uponSanitizeAttribute
.
length
>
0
)
&&
ALLOWED_TAGS
===
DEFAULT_ALLOWED_TAGS
)
{
ALLOWED_TAGS
=
clone
(
ALLOWED_TAGS
)
;
}
if
(
.
uponSanitizeAttribute
.
length
>
0
&&
ALLOWED_ATTR
===
DEFAULT_ALLOWED_ATTR
)
{
ALLOWED_ATTR
=
clone
(
ALLOWED_ATTR
)
;
}
// Prevent further manipulation of configuration.
// Not available in IE8, Safari 5, etc.
if
(
)
{
freeze
(
)
;
}
CONFIG
=
;
}
;
/* Keep track of all possible SVG and MathML tags
* so that we can perform the namespace checks
* correctly. */
const
ALL_SVG_TAGS
=
addToSet
(
{
}
,
[
...
,
...
,
...
]
)
;
const
ALL_MATHML_TAGS
=
addToSet
(
{
}
,
[
...
,
...
]
)
;
/**
* @paramelement a DOM element whose namespace is being checked
* @returns Return false if the element has a
* namespace that a spec-compliant parser would never
* return. Return true otherwise.
*/
const
_checkValidNamespace
=
function
_checkValidNamespace
(
element
)
{
let
=
getParentNode
(
)
;
// In JSDOM, if we're inside shadow DOM, then parentNode
// can be null. We just simulate parent in this case.
if
(
!
||
!
.
tagName
)
{
=
{
namespaceURI
:
NAMESPACE
,
tagName
:
'template'
}
;
}
const
=
stringToLowerCase
(
.
tagName
)
;
const
=
stringToLowerCase
(
.
tagName
)
;
if
(
!
ALLOWED_NAMESPACES
[
.
namespaceURI
]
)
{
return
false
;
}
if
(
.
namespaceURI
===
SVG_NAMESPACE
)
{
// The only way to switch from HTML namespace to SVG
// is via <svg>. If it happens via any other tag, then
// it should be killed.
if
(
.
namespaceURI
===
HTML_NAMESPACE
)
{
return
===
'svg'
;
}
// The only way to switch from MathML to SVG is via`
// svg if parent is either <annotation-xml> or MathML
// text integration points.
if
(
.
namespaceURI
===
MATHML_NAMESPACE
)
{
return
===
'svg'
&&
(
===
'annotation-xml'
||
MATHML_TEXT_INTEGRATION_POINTS
[
]
)
;
}
// We only allow elements that are defined in SVG
// spec. All others are disallowed in SVG namespace.
return
Boolean
(
ALL_SVG_TAGS
[
]
)
;
}
if
(
.
namespaceURI
===
MATHML_NAMESPACE
)
{
// The only way to switch from HTML namespace to MathML
// is via <math>. If it happens via any other tag, then
// it should be killed.
if
(
.
namespaceURI
===
HTML_NAMESPACE
)
{
return
===
'math'
;
}
// The only way to switch from SVG to MathML is via
// <math> and HTML integration points
if
(
.
namespaceURI
===
SVG_NAMESPACE
)
{
return
===
'math'
&&
HTML_INTEGRATION_POINTS
[
]
;
}
// We only allow elements that are defined in MathML
// spec. All others are disallowed in MathML namespace.
return
Boolean
(
ALL_MATHML_TAGS
[
]
)
;
}
if
(
.
namespaceURI
===
HTML_NAMESPACE
)
{
// The only way to switch from SVG to HTML is via
// HTML integration points, and from MathML to HTML
// is via MathML text integration points
if
(
.
namespaceURI
===
SVG_NAMESPACE
&&
!
HTML_INTEGRATION_POINTS
[
]
)
{
return
false
;
}
if
(
.
namespaceURI
===
MATHML_NAMESPACE
&&
!
MATHML_TEXT_INTEGRATION_POINTS
[
]
)
{
return
false
;
}
// We disallow tags that are specific for MathML
// or SVG and should never appear in HTML namespace
return
!
ALL_MATHML_TAGS
[
]
&&
(
COMMON_SVG_AND_HTML_ELEMENTS
[
]
||
!
ALL_SVG_TAGS
[
]
)
;
}
// For XHTML and XML documents that support custom namespaces
if
(
PARSER_MEDIA_TYPE
===
'application/xhtml+xml'
&&
ALLOWED_NAMESPACES
[
.
namespaceURI
]
)
{
return
true
;
}
// The code should never reach this place (this means
// that the element somehow got namespace that is not
// HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
/*
* Use the DOMParser API by default, fallback later if needs be
* DOMParser not work for svg when has multiple root element.
*/
if
(
NAMESPACE
===
HTML_NAMESPACE
)
{
try
{
=
new
DOMParser
(
)
.
parseFromString
(
,
PARSER_MEDIA_TYPE
)
;
}
catch
(
)
{
}
}
/* Use createHTMLDocument in case DOMParser is not available */
if
(
!
||
!
.
documentElement
)
{
=
.
createDocument
(
NAMESPACE
,
'template'
,
null
)
;
try
{
.
documentElement
.
innerHTML
=
IS_EMPTY_INPUT
?
:
;
}
catch
(
)
{
// Syntax error if dirtyPayload is invalid xml
}
}
const
=
.
body
||
.
documentElement
;
if
(
&&
)
{
.
insertBefore
(
document
.
createTextNode
(
)
,
.
childNodes
[
0
]
||
null
)
;
}
/* Work on whole document or just its body */
if
(
NAMESPACE
===
HTML_NAMESPACE
)
{
return
.
call
(
,
WHOLE_DOCUMENT
?
'html'
:
'body'
)
[
0
]
;
}
return
WHOLE_DOCUMENT
?
.
documentElement
:
;
}
;
/**
* Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
*
* @paramroot The root element or node to start traversing on.
* @return The created NodeIterator
*/
const
_createNodeIterator
=
function
_createNodeIterator
(
root
)
{
return
.
call
(
.
ownerDocument
||
,
,
// eslint-disable-next-line no-bitwise
NodeFilter
.
SHOW_ELEMENT
|
NodeFilter
.
SHOW_COMMENT
|
NodeFilter
.
SHOW_TEXT
|
NodeFilter
.
SHOW_PROCESSING_INSTRUCTION
|
NodeFilter
.
SHOW_CDATA_SECTION
,
null
)
;
}
;
/**
* Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
* character data of an element subtree. Used as the final safety net for
* SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
* which only form after text-node normalization (e.g. fragments split across
* stripped elements) cannot survive into a template-evaluating framework.
*
* Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
* in place rather than round-tripping through innerHTML. This preserves
* descendant node references (important for IN_PLACE callers), avoids a
* serialize/reparse cycle, and reads literal character data — which means
* `<%...%>` in text content matches the ERB regex against its real bytes
* instead of the HTML-entity-escaped form innerHTML would produce.
*
* Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
* attributes is performed during the per-node `_sanitizeAttributes` pass.
*
* @paramnode The root element whose character data should be scrubbed.
*/
const
_scrubTemplateExpressions2
=
function
_scrubTemplateExpressions
(
node
)
{
var
,
;
.
normalize
(
)
;
const
=
.
call
(
.
ownerDocument
||
,
,
// eslint-disable-next-line no-bitwise
NodeFilter
.
SHOW_TEXT
|
NodeFilter
.
SHOW_COMMENT
|
NodeFilter
.
SHOW_CDATA_SECTION
|
NodeFilter
.
SHOW_PROCESSING_INSTRUCTION
,
null
)
;
let
=
.
nextNode
(
)
;
while
(
)
{
let
=
.
data
;
arrayForEach
(
[
MUSTACHE_EXPR
,
ERB_EXPR
,
TMPLIT_EXPR
]
,
expr
=>
{
=
stringReplace
(
,
,
' '
)
;
}
)
;
.
data
=
;
=
.
nextNode
(
)
;
}
// NodeIterator does not descend into <template>.content per the DOM spec,
// so we must explicitly recurse into each template's content fragment,
// mirroring the approach used by _sanitizeShadowDOM.
const
=
(
=
(
=
.
querySelectorAll
)
===
null
||
===
void
0
?
void
0
:
.
call
(
,
'template'
)
)
!==
null
&&
!==
void
0
?
:
[
]
;
arrayForEach
(
Array
.
from
(
)
,
tmpl
=>
{
if
(
_isDocumentFragment
(
.
content
)
)
{
_scrubTemplateExpressions2
(
.
content
)
;
}
}
)
;
}
;
/**
* _isClobbered
*
* Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
* interface with [LegacyOverrideBuiltIns]; a descendant element with a
* `name` attribute matching a prototype property shadows that property
* on direct reads. We use this check at the IN_PLACE entry-point and
* during attribute sanitization to refuse clobbered forms.
*
* @paramelement element to check for clobbering attacks
* @return true if clobbered, false if safe
*/
const
_isClobbered
=
function
_isClobbered
(
element
)
{
// Realm-independent tag-name probe. If we can't determine the tag
// name at all, we can't reason about clobbering — return false
// (the caller's other defences still apply).
const
=
?
getNodeName
(
)
:
null
;
if
(
typeof
!==
'string'
)
{
return
false
;
}
if
(
transformCaseFunc
(
)
!==
'form'
)
{
return
false
;
}
return
typeof
.
nodeName
!==
'string'
||
typeof
.
textContent
!==
'string'
||
typeof
.
removeChild
!==
'function'
||
// Realm-safe NamedNodeMap detection: equality against the cached
// returns the integer 1 for any Element regardless of realm; direct
// read on a clobbered form (e.g. <input name="nodeType">) returns
// the named child element. Cheap addition — nodeType is read from
// an internal slot, no serialization cost — and removes a residual
// clobbering surface used by several mXSS / PI / comment branches
// in _sanitizeElements that compare currentNode.nodeType directly.
.
nodeType
!==
getNodeType
(
)
||
// HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
// "childNodes" shadows the prototype getter. Direct reads of
// form.childNodes from a clobbered form return the named child
// instead of the real NodeList, so any walk that reads it directly
// skips the form's real children. Compare the direct read to the
// cached Node.prototype getter — when the form's named-property
// getter intercepts the read, the two values differ and we flag
// the form. This catches every clobbering child type (input,
// select, etc.) regardless of whether the named child happens to
// carry a numeric .length, which a typeof-based probe would miss
// (e.g. HTMLSelectElement.length is a defined unsigned-long).
.
childNodes
!==
getChildNodes
(
)
;
}
;
/**
* Checks whether the given value is a DocumentFragment from any realm.
*
* The realm-independent replacement reads `nodeType` through the cached
* Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
* constant (11). nodeType is a numeric value resolved from the node's
* internal slot, identical across realms for the same kind of node.
*
* @paramvalue object to check
* @return true if value is a DocumentFragment-shaped node from any realm
*/
const
_isDocumentFragment
=
function
_isDocumentFragment
(
value
)
{
if
(
!
||
typeof
!==
'object'
||
===
null
)
{
return
false
;
}
try
{
return
getNodeType
(
)
===
NODE_TYPE
.
documentFragment
;
}
catch
(
)
{
return
false
;
}
}
;
/**
* Checks whether the given object is a DOM node, including nodes that
* originate from a different window/realm (e.g. an iframe's
* contentDocument). The previous `value instanceof Node` check was
* realm-bound: nodes from a different window failed it, causing
* sanitize() to silently stringify them and reset IN_PLACE to false,
* returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
*
* @paramvalue object to check whether it's a DOM node
* @return true if value is a DOM node from any realm
*/
const
_isNode
=
function
_isNode
(
value
)
{
if
(
!
||
typeof
!==
'object'
||
===
null
)
{
return
false
;
}
try
{
return
typeof
getNodeType
(
)
===
'number'
;
}
catch
(
)
{
return
false
;
}
}
;
function
_executeHooks
(
hooks, currentNode, data
)
{
arrayForEach
(
,
hook
=>
{
.
call
(
DOMPurify
,
,
,
CONFIG
)
;
}
)
;
}
/**
* _sanitizeElements
*
* @protect nodeName
* @protect textContent
* @protect removeChild
* @paramcurrentNode to check for permission to exist
* @return true if node was killed, false if left alive
*/
const
_sanitizeElements
=
function
_sanitizeElements
(
currentNode
)
{
let
=
null
;
/* Execute a hook if present */
_executeHooks
(
.
beforeSanitizeElements
,
,
null
)
;
/* Check if element is clobbered or can clobber */
/* Remove risky CSS construction leading to mXSS */
if
(
SAFE_FOR_XML
&&
.
namespaceURI
===
HTML_NAMESPACE
&&
===
'style'
&&
_isNode
(
.
firstElementChild
)
)
{
_forceRemove
(
)
;
return
true
;
}
/* Remove any occurrence of processing instructions */
if
(
.
nodeType
===
NODE_TYPE
.
progressingInstruction
)
{
_forceRemove
(
)
;
return
true
;
}
/* Remove any kind of possibly harmful comments */
if
(
SAFE_FOR_XML
&&
.
nodeType
===
NODE_TYPE
.
comment
&&
regExpTest
(
/<[/\w]/g
,
.
data
)
)
{
_forceRemove
(
)
;
return
true
;
}
/* Remove element if anything forbids its presence */
if
(
FORBID_TAGS
[
]
||
!
(
EXTRA_ELEMENT_HANDLING
.
tagCheck
instanceof
Function
&&
EXTRA_ELEMENT_HANDLING
.
tagCheck
(
)
)
&&
!
ALLOWED_TAGS
[
]
)
{
/* Check if we have a custom element to handle */
if
(
!
FORBID_TAGS
[
]
&&
_isBasicCustomElement
(
)
)
{
if
(
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
instanceof
RegExp
&&
regExpTest
(
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
,
)
)
{
return
false
;
}
if
(
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
instanceof
Function
&&
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
(
)
)
{
return
false
;
}
}
/* Keep content except for bad-listed elements.
Use the cached prototype getters exclusively — the previous code
had `|| currentNode.parentNode` / `|| currentNode.childNodes`
fallbacks, but the cached getters always return the canonical
value (or null for a real parent-less node), so the fallback
path was dead in safe cases and a clobbering surface in unsafe
ones. Falsy cached results stay falsy; the `if (childNodes &&
parentNode)` check already gates correctly. */
if
(
KEEP_CONTENT
&&
!
FORBID_CONTENTS
[
]
)
{
const
=
getParentNode
(
)
;
const
=
getChildNodes
(
)
;
if
(
&&
)
{
const
=
.
length
;
for
(
let
=
-
1
;
>=
0
;
--
)
{
const
=
cloneNode
(
[
]
,
true
)
;
.
insertBefore
(
,
getNextSibling
(
)
)
;
}
}
}
_forceRemove
(
)
;
return
true
;
}
/* Check whether element has a valid namespace.
Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
nodeType getter rather than `instanceof Element`, which is realm-
bound and short-circuits to false for any node minted in a different
realm — letting a foreign-realm element with a forbidden namespace
slip past the namespace check entirely. */
const
=
?
getNodeType
(
)
:
.
nodeType
;
if
(
===
NODE_TYPE
.
element
&&
!
_checkValidNamespace
(
)
)
{
_forceRemove
(
)
;
return
true
;
}
/* Make sure that older browsers don't get fallback-tag mXSS */
if
(
(
===
'noscript'
||
===
'noembed'
||
===
'noframes'
)
&&
regExpTest
(
/<\/no(script|embed|frames)/i
,
.
innerHTML
)
)
{
_forceRemove
(
)
;
return
true
;
}
/* Sanitize element content to be template-safe */
if
(
SAFE_FOR_TEMPLATES
&&
.
nodeType
===
NODE_TYPE
.
text
)
{
/* Get the element's text content */
=
.
textContent
;
arrayForEach
(
[
MUSTACHE_EXPR
,
ERB_EXPR
,
TMPLIT_EXPR
]
,
expr
=>
{
=
stringReplace
(
,
,
' '
)
;
}
)
;
if
(
.
textContent
!==
)
{
arrayPush
(
DOMPurify
.
removed
,
{
element
:
.
cloneNode
(
)
}
)
;
.
textContent
=
;
}
}
/* Execute a hook if present */
_executeHooks
(
.
afterSanitizeElements
,
,
null
)
;
return
false
;
}
;
/**
* _isValidAttribute
*
* @paramlcTag Lowercase tag name of containing element.
* @paramlcName Lowercase attribute name.
* @paramvalue Attribute value.
* @return Returns true if `value` is valid, otherwise false.
*/
// eslint-disable-next-line complexity
const
_isValidAttribute
=
function
_isValidAttribute
(
lcTag, lcName, value
)
{
/* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
if
(
FORBID_ATTR
[
]
)
{
return
false
;
}
/* Make sure attribute cannot clobber */
if
(
SANITIZE_DOM
&&
(
===
'id'
||
===
'name'
)
&&
(
in
document
||
in
)
)
{
return
false
;
}
const
=
ALLOWED_ATTR
[
]
||
EXTRA_ELEMENT_HANDLING
.
attributeCheck
instanceof
Function
&&
EXTRA_ELEMENT_HANDLING
.
attributeCheck
(
,
)
;
/* Allow valid data-* attributes: At least one character after "-"
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
We don't need to check the value; it's always URI safe. */
if
(
ALLOW_DATA_ATTR
&&
!
FORBID_ATTR
[
]
&&
regExpTest
(
DATA_ATTR
,
)
)
;
else
if
(
ALLOW_ARIA_ATTR
&&
regExpTest
(
ARIA_ATTR
,
)
)
;
else
if
(
!
||
FORBID_ATTR
[
]
)
{
if
(
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
_isBasicCustomElement
(
)
&&
(
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
instanceof
RegExp
&&
regExpTest
(
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
,
)
||
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
instanceof
Function
&&
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
(
)
)
&&
(
CUSTOM_ELEMENT_HANDLING
.
attributeNameCheck
instanceof
RegExp
&&
regExpTest
(
CUSTOM_ELEMENT_HANDLING
.
attributeNameCheck
,
)
||
CUSTOM_ELEMENT_HANDLING
.
attributeNameCheck
instanceof
Function
&&
CUSTOM_ELEMENT_HANDLING
.
attributeNameCheck
(
,
)
)
||
// Alternative, second condition checks if it's an `is`-attribute, AND
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
===
'is'
&&
CUSTOM_ELEMENT_HANDLING
.
allowCustomizedBuiltInElements
&&
(
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
instanceof
RegExp
&&
regExpTest
(
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
,
)
||
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
instanceof
Function
&&
CUSTOM_ELEMENT_HANDLING
.
tagNameCheck
(
)
)
)
;
else
{
return
false
;
}
/* Check value is safe. First, is attr inert? If so, is safe */
}
else
if
(
URI_SAFE_ATTRIBUTES
[
]
)
;
else
if
(
regExpTest
(
IS_ALLOWED_URI
,
stringReplace
(
,
ATTR_WHITESPACE
,
''
)
)
)
;
else
if
(
(
===
'src'
||
===
'xlink:href'
||
===
'href'
)
&&
!==
'script'
&&
stringIndexOf
(
,
'data:'
)
===
0
&&
DATA_URI_TAGS
[
]
)
;
else
if
(
ALLOW_UNKNOWN_PROTOCOLS
&&
!
regExpTest
(
IS_SCRIPT_OR_DATA
,
stringReplace
(
,
ATTR_WHITESPACE
,
''
)
)
)
;
else
if
(
)
{
return
false
;
}
else
;
return
true
;
}
;
/* Names the HTML spec reserves from valid-custom-element-name; these must
* never be treated as basic custom elements even when a permissive
* CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
const
RESERVED_CUSTOM_ELEMENT_NAMES
=
addToSet
(
{
}
,
[
'annotation-xml'
,
'color-profile'
,
'font-face'
,
'font-face-format'
,
'font-face-name'
,
'font-face-src'
,
'font-face-uri'
,
'missing-glyph'
]
)
;
/**
* _isBasicCustomElement
* checks if at least one dash is included in tagName, and it's not the first char
* for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
*
* @paramtagName name of the tag of the node to sanitize
* @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
*/
/* Make sure we cannot easily use animated hrefs, even if animations are allowed */
if
(
===
'attributename'
&&
stringMatch
(
,
'href'
)
)
{
_removeAttribute
(
,
)
;
continue
;
}
/* Did the hooks approve of the attribute? */
if
(
.
forceKeepAttr
)
{
continue
;
}
/* Did the hooks approve of the attribute? */
if
(
!
.
keepAttr
)
{
_removeAttribute
(
,
)
;
continue
;
}
/* Work around a security issue in jQuery 3.0 */
if
(
!
ALLOW_SELF_CLOSE_IN_ATTR
&&
regExpTest
(
/\/>/i
,
)
)
{
_removeAttribute
(
,
)
;
continue
;
}
/* Sanitize attribute content to be template-safe */
if
(
SAFE_FOR_TEMPLATES
)
{
arrayForEach
(
[
MUSTACHE_EXPR
,
ERB_EXPR
,
TMPLIT_EXPR
]
,
expr
=>
{
=
stringReplace
(
,
,
' '
)
;
}
)
;
}
/* Is `value` valid for this attribute? */
const
=
transformCaseFunc
(
.
nodeName
)
;
if
(
!
_isValidAttribute
(
,
,
)
)
{
_removeAttribute
(
,
)
;
continue
;
}
/* Handle attributes that require Trusted Types */
if
(
&&
typeof
===
'object'
&&
typeof
.
getAttributeType
===
'function'
)
{
if
(
)
;
else
{
switch
(
.
getAttributeType
(
,
)
)
{
case
'TrustedHTML'
:
{
=
_createTrustedHTML
(
)
;
break
;
}
case
'TrustedScriptURL'
:
{
=
.
createScriptURL
(
)
;
break
;
}
}
}
}
/* Handle invalid data-* attribute set by try-catching it */
if
(
!==
)
{
try
{
if
(
)
{
.
setAttributeNS
(
,
,
)
;
}
else
{
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
.
setAttribute
(
,
)
;
}
if
(
_isClobbered
(
)
)
{
_forceRemove
(
)
;
}
else
{
arrayPop
(
DOMPurify
.
removed
)
;
}
}
catch
(
)
{
_removeAttribute
(
,
)
;
}
}
}
/* Execute a hook if present */
_executeHooks
(
.
afterSanitizeAttributes
,
,
null
)
;
}
;
/**
* _sanitizeShadowDOM
*
* @paramfragment to iterate over recursively
*/
const
_sanitizeShadowDOM2
=
function
_sanitizeShadowDOM
(
fragment
)
{
let
=
null
;
const
=
_createNodeIterator
(
)
;
/* Execute a hook if present */
_executeHooks
(
.
beforeSanitizeShadowDOM
,
,
null
)
;
while
(
=
.
nextNode
(
)
)
{
/* Execute a hook if present */
_executeHooks
(
.
uponSanitizeShadowNode
,
,
null
)
;
/* Sanitize tags and elements */
_sanitizeElements
(
)
;
/* Check attributes next */
_sanitizeAttributes
(
)
;
/* Deep shadow DOM detected.
Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
recurse into <template>.content from foreign realms too. */
if
(
_isDocumentFragment
(
.
content
)
)
{
_sanitizeShadowDOM2
(
.
content
)
;
}
/* An element iterated here may itself host an attached
shadow root. The default NodeIterator does not enter shadow
trees, so a shadow root nested inside template.content was
previously reached by no walk at all (the pre-pass at
_sanitizeAttachedShadowRoots descends via childNodes, which
doesn't enter template.content; the template-content recursion
above iterates the content but never inspected shadowRoot).
Walk it explicitly. The nodeType guard avoids reading
shadowRoot off text / comment / CDATA / PI nodes that the
iterator also surfaces. */
const
=
?
getNodeType
(
)
:
.
nodeType
;
if
(
===
NODE_TYPE
.
element
)
{
const
=
?
getShadowRoot
(
)
:
.
shadowRoot
;
if
(
_isDocumentFragment
(
)
)
{
_sanitizeAttachedShadowRoots2
(
)
;
_sanitizeShadowDOM2
(
)
;
}
}
}
/* Execute a hook if present */
_executeHooks
(
.
afterSanitizeShadowDOM
,
,
null
)
;
}
;
/**
* _sanitizeAttachedShadowRoots
*
* Walks `root` and feeds every attached shadow root we encounter into
* the existing _sanitizeShadowDOM pipeline. The default node iterator
* does not descend into shadow trees, so nodes inside an attached
* shadow root would otherwise be skipped entirely.
*
* Two real input paths put attached shadow roots in front of us:
* 1. IN_PLACE on a DOM node that already has shadow roots attached.
* 2. DOM-node input where importNode(dirty, true) deep-clones the
* shadow root because it was created with `clonable: true`.
*
* This pass runs once, up front, so the main iteration loop (and the
* existing _sanitizeShadowDOM template-content recursion) stay
* untouched — string-input paths are not affected.
*
* @paramroot the subtree root to walk for attached shadow roots
*/
const
_sanitizeAttachedShadowRoots2
=
function
_sanitizeAttachedShadowRoots
(
root
)
{
const
=
?
getNodeType
(
)
:
.
nodeType
;
if
(
===
NODE_TYPE
.
element
)
{
const
=
?
getShadowRoot
(
)
:
.
shadowRoot
;
// Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType-based
// detection rather than `instanceof DocumentFragment`, which is
// realm-bound and silently skipped shadow roots whose host element
// belonged to a foreign realm (e.g. iframe.contentDocument
// attachShadow). A foreign-realm ShadowRoot extends the foreign
// realm's DocumentFragment, not ours, so the old instanceof check
// returned false and the shadow subtree was never walked.
if
(
_isDocumentFragment
(
)
)
{
// Recurse first so that nested shadow roots are reached even if
// _sanitizeShadowDOM removes hosts at this level.
_sanitizeAttachedShadowRoots2
(
)
;
_sanitizeShadowDOM2
(
)
;
}
}
// Snapshot children before recursing. Sanitization of one subtree
// (e.g. via an uponSanitizeShadowNode hook) may detach siblings,
// and naive nextSibling traversal would silently skip the rest of
// the list once a node is detached.
const
=
?
getChildNodes
(
)
:
.
childNodes
;
if
(
!
)
{
return
;
}
const
=
[
]
;
arrayForEach
(
,
child
=>
{
arrayPush
(
,
)
;
}
)
;
for
(
const
of
)
{
_sanitizeAttachedShadowRoots2
(
)
;
}
/* When the root is a <template>, also descend into root.content */
if
(
===
NODE_TYPE
.
element
)
{
const
=
?
getNodeName
(
)
:
null
;
if
(
typeof
===
'string'
&&
transformCaseFunc
(
)
===
'template'
)
{
const
=
.
content
;
if
(
_isDocumentFragment
(
)
)
{
_sanitizeAttachedShadowRoots2
(
)
;
}
}
}
}
;
// eslint-disable-next-line complexity
DOMPurify
.
sanitize
=
function
(
dirty
)
{
let
=
.
length
>
1
&&
[
1
]
!==
undefined
?
[
1
]
:
{
}
;
let
=
null
;
let
=
null
;
let
=
null
;
let
=
null
;
/* Make sure we have a string to sanitize.
DO NOT return early, as this will return the wrong type if
the user has requested a DOM object rather than a string */
IS_EMPTY_INPUT
=
!
;
if
(
IS_EMPTY_INPUT
)
{
=
'<!-->'
;
}
/* Stringify, in case dirty is an object */
if
(
typeof
!==
'string'
&&
!
_isNode
(
)
)
{
=
stringifyValue
(
)
;
if
(
typeof
!==
'string'
)
{
throw
typeErrorCreate
(
'dirty is not a string, aborting'
)
;
}
}
/* Return dirty HTML if DOMPurify cannot run */
if
(
!
DOMPurify
.
isSupported
)
{
return
;
}
/* Assign config vars */
if
(
!
SET_CONFIG
)
{
_parseConfig
(
)
;
}
/* Clean up removed elements */
DOMPurify
.
removed
=
[
]
;
/* Check if dirty is correctly typed for IN_PLACE */
if
(
typeof
===
'string'
)
{
IN_PLACE
=
false
;
}
if
(
IN_PLACE
)
{
/* Do some early pre-sanitization to avoid unsafe root nodes.
Read nodeName through the cached prototype getter — a clobbering
child named "nodeName" on the form root would otherwise shadow
the property and let this check skip the root-allowlist
validation entirely. */
const
=
?
getNodeName
(
)
:
.
nodeName
;
if
(
typeof
===
'string'
)
{
const
=
transformCaseFunc
(
)
;
if
(
!
ALLOWED_TAGS
[
]
||
FORBID_TAGS
[
]
)
{
throw
typeErrorCreate
(
'root node is forbidden and cannot be sanitized in-place'
)
;
}
}
/* Pre-flight the root through _isClobbered. The iterator-driven
removal path can not detach a parent-less root: _forceRemove
falls through to Element.prototype.remove(), which per spec
is a no-op on a node with no parent. A clobbered root would
then survive the main loop with its attributes uninspected,
because _sanitizeAttributes early-returns on _isClobbered. The
result would be an attacker-controlled form, complete with any
event-handler attributes the caller passed in, handed back to
the application unsanitized. Refuse to sanitize such a root
the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
if
(
_isClobbered
(
)
)
{
throw
typeErrorCreate
(
'root node is clobbered and cannot be sanitized in-place'
)
;
}
/* Sanitize attached shadow roots before the main iterator runs.
The iterator does not descend into shadow trees. */
_sanitizeAttachedShadowRoots2
(
)
;
}
else
if
(
_isNode
(
)
)
{
/* If dirty is a DOM element, append to an empty document to avoid
elements being stripped by the parser */
/* Clonable shadow roots are deep-cloned by importNode(); sanitize
them before the main iterator runs, since the iterator does not
descend into shadow trees. The walk routes every read through a
cached prototype getter so clobbering descendants on a form root
cannot hide a shadow host from this pass. */
/* Remove first element node (ours) if FORCE_BODY is set */
if
(
&&
FORCE_BODY
)
{
_forceRemove
(
.
firstChild
)
;
}
/* Get node iterator */
const
=
_createNodeIterator
(
IN_PLACE
?
:
)
;
/* Now start iterating over the created document */
while
(
=
.
nextNode
(
)
)
{
/* Sanitize tags and elements */
_sanitizeElements
(
)
;
/* Check attributes next */
_sanitizeAttributes
(
)
;
/* Shadow DOM detected, sanitize it.
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
instead of instanceof, so foreign-realm <template>.content is
walked correctly. */
if
(
_isDocumentFragment
(
.
content
)
)
{
_sanitizeShadowDOM2
(
.
content
)
;
}
}
/* If we sanitized `dirty` in-place, return it. */
/*
AdoptNode() is not used because internal state is not reset
(e.g. the past names map of a HTMLFormElement), this is safe
in theory but we would rather not risk another attack vector.
The state that is cloned by importNode() is explicitly defined
by the specs.
*/