Default sanitizer configuration

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{DefaultAPISidebar("HTML Sanitizer API")}}

The default sanitizer configuration defines the configuration returned by the [Sanitizer() constructor](/en-US/docs/Web/API/Sanitizer/Sanitizer) if no configuration is passed as an argument. This same configuration is implicitly used if you call the safe sanitization methods, such as {{domxref("Element.setHTML()")}}, {{domxref("ShadowRoot.setHTML()")}}, and {{domxref("Document.parseHTML_static","Document.parseHTML()")}}, without specifying a custom sanitizer.

This configuration removes the following sorts of items:

  1. Those that are known to be XSS-unsafe:
  • {{htmlelement("base")}}, {{htmlelement("embed")}}, {{htmlelement("frame")}}, {{htmlelement("iframe")}}, {{htmlelement("object")}}, {{htmlelement("script")}}, and {{SVGElement("use")}}.
  • All event handler content attributes, such as onafterprint, onbeforeinput, and so on.
  1. Items that might be used in clickjacking, spoofing, or other attacks.
  2. Deprecated items.
  3. Comments and data-* attributes.

It therefore provides a sanitizer with a minimal attack surface, which is still suitable for the majority of sanitization use cases.

توجه: Calling {{domxref("Sanitizer.removeUnsafe()")}}, or passing a custom sanitizer to the safe sanitization method, only removes the XSS-unsafe items. It does not remove the additional items, comments, and data-* attributes.

The following sections list all the elements, with a ✓ mark indicating those that are _allowed_ by the default configuration (the ❌ therefore indicates those that will be removed). The "Additional allowed attributes" column lists the attributes that are allowed for the corresponding elements; any other attributes on the element would be removed (unless allowed by the global attributes). The Global attributes section lists the attributes that are allowed on all elements (the attributes that are not removed when the configuration is used).

HTML elements

ElementAllowedAdditional allowed attributes
{{HTMLElement("a")}}✓[href](/en-US/docs/Web/HTML/Reference/Elements/a#href), [hreflang](/en-US/docs/Web/HTML/Reference/Elements/a#hreflang), [type](/en-US/docs/Web/HTML/Reference/Elements/a#type)
{{HTMLElement("abbr")}}✓
{{HTMLElement("acronym")}}❌
{{HTMLElement("address")}}✓
{{HTMLElement("area")}}❌
{{HTMLElement("article")}}✓
{{HTMLElement("aside")}}✓
{{HTMLElement("audio")}}❌
{{HTMLElement("b")}}✓
{{HTMLElement("base")}}❌
{{HTMLElement("bdi")}}✓
{{HTMLElement("bdo")}}✓
{{HTMLElement("big")}}❌
{{HTMLElement("blockquote")}}✓[cite](/en-US/docs/Web/HTML/Reference/Elements/blockquote#cite)
{{HTMLElement("body")}}✓
{{HTMLElement("br")}}✓
{{HTMLElement("button")}}❌
{{HTMLElement("canvas")}}❌
{{HTMLElement("caption")}}✓
{{HTMLElement("center")}}❌
{{HTMLElement("cite")}}✓
{{HTMLElement("code")}}✓
{{HTMLElement("col")}}✓[span](/en-US/docs/Web/HTML/Reference/Elements/col#span)
{{HTMLElement("colgroup")}}✓[span](/en-US/docs/Web/HTML/Reference/Elements/colgroup#span)
{{HTMLElement("data")}}✓[value](/en-US/docs/Web/HTML/Reference/Elements/data#value)
{{HTMLElement("datalist")}}❌
{{HTMLElement("dd")}}✓
{{HTMLElement("del")}}✓[cite](/en-US/docs/Web/HTML/Reference/Elements/del#cite), [datetime](/en-US/docs/Web/HTML/Reference/Elements/del#datetime)
{{HTMLElement("details")}}❌
{{HTMLElement("dfn")}}✓
{{HTMLElement("dialog")}}❌
{{HTMLElement("dir")}}❌
{{HTMLElement("div")}}✓
{{HTMLElement("dl")}}✓
{{HTMLElement("dt")}}✓
{{HTMLElement("em")}}✓
{{HTMLElement("embed")}}❌
{{HTMLElement("fencedframe")}}❌
{{HTMLElement("fieldset")}}❌
{{HTMLElement("figcaption")}}✓
{{HTMLElement("figure")}}✓
{{HTMLElement("font")}}❌
{{HTMLElement("footer")}}✓
{{HTMLElement("form")}}❌
{{HTMLElement("frame")}}❌
{{HTMLElement("frameset")}}❌
{{HTMLElement("Heading_Elements", "<h1> – <h6>")}}✓
{{HTMLElement("head")}}✓
{{HTMLElement("header")}}✓
{{HTMLElement("hgroup")}}✓
{{HTMLElement("hr")}}✓
{{HTMLElement("html")}}✓
{{HTMLElement("i")}}✓
{{HTMLElement("iframe")}}❌
{{HTMLElement("img")}}❌
{{HTMLElement("input")}}❌
{{HTMLElement("ins")}}✓[cite](/en-US/docs/Web/HTML/Reference/Elements/ins#cite), [datetime](/en-US/docs/Web/HTML/Reference/Elements/ins#datetime)
{{HTMLElement("kbd")}}✓
{{HTMLElement("label")}}❌
{{HTMLElement("legend")}}❌
{{HTMLElement("li")}}✓[value](/en-US/docs/Web/HTML/Reference/Elements/li#value)
{{HTMLElement("link")}}❌
{{HTMLElement("main")}}✓
{{HTMLElement("map")}}❌
{{HTMLElement("mark")}}✓
{{HTMLElement("marquee")}}❌
{{HTMLElement("menu")}}✓
{{HTMLElement("meta")}}❌
{{HTMLElement("meter")}}❌
{{HTMLElement("nav")}}✓
{{HTMLElement("nobr")}}❌
{{HTMLElement("noembed")}}❌
{{HTMLElement("noframes")}}❌
{{HTMLElement("noscript")}}❌
{{HTMLElement("object")}}❌
{{HTMLElement("ol")}}✓[reversed](/en-US/docs/Web/HTML/Reference/Elements/ol#reversed), [start](/en-US/docs/Web/HTML/Reference/Elements/ol#start), [type](/en-US/docs/Web/HTML/Reference/Elements/ol#type)
{{HTMLElement("optgroup")}}❌
{{HTMLElement("option")}}❌
{{HTMLElement("output")}}❌
{{HTMLElement("p")}}✓
{{HTMLElement("param")}}❌
{{HTMLElement("picture")}}❌
{{HTMLElement("plaintext")}}❌
{{HTMLElement("pre")}}✓
{{HTMLElement("progress")}}❌
{{HTMLElement("q")}}✓
{{HTMLElement("rb")}}❌
{{HTMLElement("rp")}}✓
{{HTMLElement("rt")}}✓
{{HTMLElement("rtc")}}❌
{{HTMLElement("ruby")}}✓
{{HTMLElement("s")}}✓
{{HTMLElement("samp")}}✓
{{HTMLElement("script")}}❌
{{HTMLElement("search")}}✓
{{HTMLElement("section")}}✓
{{HTMLElement("select")}}❌
{{HTMLElement("selectedcontent")}}❌
{{HTMLElement("slot")}}❌
{{HTMLElement("small")}}✓
{{HTMLElement("source")}}❌
{{HTMLElement("span")}}✓
{{HTMLElement("strike")}}❌
{{HTMLElement("strong")}}✓
{{HTMLElement("style")}}❌
{{HTMLElement("sub")}}✓
{{HTMLElement("summary")}}❌
{{HTMLElement("sup")}}✓
{{HTMLElement("table")}}✓
{{HTMLElement("tbody")}}✓
{{HTMLElement("td")}}✓[colspan](/en-US/docs/Web/HTML/Reference/Elements/td#colspan), [headers](/en-US/docs/Web/HTML/Reference/Elements/td#headers), [rowspan](/en-US/docs/Web/HTML/Reference/Elements/td#rowspan)
{{HTMLElement("template")}}❌
{{HTMLElement("textarea")}}❌
{{HTMLElement("tfoot")}}✓
{{HTMLElement("th")}}✓[abbr](/en-US/docs/Web/HTML/Reference/Elements/th#abbr), [colspan](/en-US/docs/Web/HTML/Reference/Elements/th#colspan), [headers](/en-US/docs/Web/HTML/Reference/Elements/th#headers), [rowspan](/en-US/docs/Web/HTML/Reference/Elements/th#rowspan), [scope](/en-US/docs/Web/HTML/Reference/Elements/th#scope)
{{HTMLElement("thead")}}✓
{{HTMLElement("time")}}✓[datetime](/en-US/docs/Web/HTML/Reference/Elements/time#datetime)
{{HTMLElement("title")}}✓
{{HTMLElement("tr")}}✓
{{HTMLElement("track")}}❌
{{HTMLElement("tt")}}❌
{{HTMLElement("u")}}✓
{{HTMLElement("ul")}}✓
{{HTMLElement("var")}}✓
{{HTMLElement("video")}}❌
{{HTMLElement("wbr")}}✓
{{HTMLElement("xmp")}}❌

SVG elements

ElementAllowedAdditional allowed attributes
{{SVGElement("a")}}✓{{SVGAttr("href")}}, [hreflang](/en-US/docs/Web/HTML/Reference/Elements/a#hreflang), {{SVGAttr("type")}}
{{SVGElement("animate")}}❌
{{SVGElement("animateMotion")}}❌
{{SVGElement("animateTransform")}}❌
{{SVGElement("circle")}}✓{{SVGAttr("cx")}}, {{SVGAttr("cy")}}, {{SVGAttr("pathLength")}}, {{SVGAttr("r")}}
{{SVGElement("clipPath")}}❌
{{SVGElement("defs")}}✓
{{SVGElement("desc")}}✓
{{SVGElement("ellipse")}}✓{{SVGAttr("cx")}}, {{SVGAttr("cy")}}, {{SVGAttr("pathLength")}}, {{SVGAttr("rx")}}, {{SVGAttr("ry")}}
{{SVGElement("feBlend")}}❌
{{SVGElement("feColorMatrix")}}❌
{{SVGElement("feComponentTransfer")}}❌
{{SVGElement("feComposite")}}❌
{{SVGElement("feConvolveMatrix")}}❌
{{SVGElement("feDiffuseLighting")}}❌
{{SVGElement("feDisplacementMap")}}❌
{{SVGElement("feDistantLight")}}❌
{{SVGElement("feDropShadow")}}❌
{{SVGElement("feFlood")}}❌
{{SVGElement("feFuncA")}}❌
{{SVGElement("feFuncB")}}❌
{{SVGElement("feFuncG")}}❌
{{SVGElement("feFuncR")}}❌
{{SVGElement("feGaussianBlur")}}❌
{{SVGElement("feImage")}}❌
{{SVGElement("feMerge")}}❌
{{SVGElement("feMergeNode")}}❌
{{SVGElement("feMorphology")}}❌
{{SVGElement("feOffset")}}❌
{{SVGElement("fePointLight")}}❌
{{SVGElement("feSpecularLighting")}}❌
{{SVGElement("feSpotLight")}}❌
{{SVGElement("feTile")}}❌
{{SVGElement("feTurbulence")}}❌
{{SVGElement("filter")}}❌
{{SVGElement("foreignObject")}}✓{{SVGAttr("height")}}, {{SVGAttr("width")}}, {{SVGAttr("x")}}, {{SVGAttr("y")}}
{{SVGElement("g")}}✓
{{SVGElement("image")}}❌
{{SVGElement("line")}}✓{{SVGAttr("pathLength")}}, {{SVGAttr("x1")}}, {{SVGAttr("x2")}}, {{SVGAttr("y1")}}, {{SVGAttr("y2")}}
{{SVGElement("linearGradient")}}❌
{{SVGElement("marker")}}✓{{SVGAttr("markerHeight")}}, {{SVGAttr("markerUnits")}}, {{SVGAttr("markerWidth")}}, {{SVGAttr("orient")}}, {{SVGAttr("preserveAspectRatio")}}, {{SVGAttr("refX")}}, {{SVGAttr("refY")}}, {{SVGAttr("viewBox")}}
{{SVGElement("mask")}}❌
{{SVGElement("metadata")}}✓
{{SVGElement("mpath")}}❌
{{SVGElement("path")}}✓{{SVGAttr("d")}}, {{SVGAttr("pathLength")}}
{{SVGElement("pattern")}}❌
{{SVGElement("polygon")}}✓{{SVGAttr("pathLength")}}, {{SVGAttr("points")}}
{{SVGElement("polyline")}}✓{{SVGAttr("pathLength")}}, {{SVGAttr("points")}}
{{SVGElement("radialGradient")}}❌
{{SVGElement("rect")}}✓{{SVGAttr("height")}}, {{SVGAttr("pathLength")}}, {{SVGAttr("rx")}}, {{SVGAttr("ry")}}, {{SVGAttr("width")}}, {{SVGAttr("x")}}, {{SVGAttr("y")}}
{{SVGElement("script")}}❌
{{SVGElement("set")}}❌
{{SVGElement("stop")}}❌
{{SVGElement("style")}}❌
{{SVGElement("svg")}}✓{{SVGAttr("height")}}, {{SVGAttr("preserveAspectRatio")}}, {{SVGAttr("viewBox")}}, {{SVGAttr("width")}}, {{SVGAttr("x")}}, {{SVGAttr("y")}}
{{SVGElement("switch")}}❌
{{SVGElement("symbol")}}❌
{{SVGElement("text")}}✓{{SVGAttr("dx")}}, {{SVGAttr("dy")}}, {{SVGAttr("lengthAdjust")}}, {{SVGAttr("rotate")}}, {{SVGAttr("textLength")}}, {{SVGAttr("x")}}, {{SVGAttr("y")}}
{{SVGElement("textPath")}}✓{{SVGAttr("lengthAdjust")}}, {{SVGAttr("method")}}, {{SVGAttr("path")}}, {{SVGAttr("side")}}, {{SVGAttr("spacing")}}, {{SVGAttr("startOffset")}}, {{SVGAttr("textLength")}}
{{SVGElement("title")}}✓
{{SVGElement("tspan")}}✓{{SVGAttr("dx")}}, {{SVGAttr("dy")}}, {{SVGAttr("lengthAdjust")}}, {{SVGAttr("rotate")}}, {{SVGAttr("textLength")}}, {{SVGAttr("x")}}, {{SVGAttr("y")}}
{{SVGElement("use")}}❌
{{SVGElement("view")}}❌

MathML elements

ElementAllowedAdditional allowed attributes
{{MathMLElement("annotation")}}❌
{{MathMLElement("annotation-xml")}}❌
{{MathMLElement("maction")}}❌
{{MathMLElement("math")}}✓
{{MathMLElement("menclose")}}❌
{{MathMLElement("merror")}}✓
{{MathMLElement("mfenced")}}❌
{{MathMLElement("mfrac")}}✓
{{MathMLElement("mi")}}✓
{{MathMLElement("mmultiscripts")}}✓
{{MathMLElement("mn")}}✓
{{MathMLElement("mo")}}✓[fence](/en-US/docs/Web/MathML/Reference/Element/mo#fence), [form](/en-US/docs/Web/MathML/Reference/Element/mo#form), [largeop](/en-US/docs/Web/MathML/Reference/Element/mo#largeop), [lspace](/en-US/docs/Web/MathML/Reference/Element/mo#lspace), [maxsize](/en-US/docs/Web/MathML/Reference/Element/mo#maxsize), [minsize](/en-US/docs/Web/MathML/Reference/Element/mo#minsize), [movablelimits](/en-US/docs/Web/MathML/Reference/Element/mo#movablelimits), [rspace](/en-US/docs/Web/MathML/Reference/Element/mo#rspace), [separator](/en-US/docs/Web/MathML/Reference/Element/mo#separator), [stretchy](/en-US/docs/Web/MathML/Reference/Element/mo#stretchy), [symmetric](/en-US/docs/Web/MathML/Reference/Element/mo#symmetric)
{{MathMLElement("mover")}}✓[accent](/en-US/docs/Web/MathML/Reference/Element/mover#accent)
{{MathMLElement("mpadded")}}✓[depth](/en-US/docs/Web/MathML/Reference/Element/mpadded#depth), [height](/en-US/docs/Web/MathML/Reference/Element/mpadded#height), [lspace](/en-US/docs/Web/MathML/Reference/Element/mpadded#lspace), [voffset](/en-US/docs/Web/MathML/Reference/Element/mpadded#voffset), [width](/en-US/docs/Web/MathML/Reference/Element/mpadded#width)
{{MathMLElement("mphantom")}}✓
{{MathMLElement("mprescripts")}}✓
{{MathMLElement("mroot")}}✓
{{MathMLElement("mrow")}}✓
{{MathMLElement("ms")}}✓
{{MathMLElement("mspace")}}✓[depth](/en-US/docs/Web/MathML/Reference/Element/mspace#depth), [height](/en-US/docs/Web/MathML/Reference/Element/mspace#height), [width](/en-US/docs/Web/MathML/Reference/Element/mspace#width)
{{MathMLElement("msqrt")}}✓
{{MathMLElement("mstyle")}}✓
{{MathMLElement("msub")}}✓
{{MathMLElement("msubsup")}}✓
{{MathMLElement("msup")}}✓
{{MathMLElement("mtable")}}✓
{{MathMLElement("mtd")}}✓[columnspan](/en-US/docs/Web/MathML/Reference/Element/mtd#columnspan), [rowspan](/en-US/docs/Web/MathML/Reference/Element/mtd#rowspan)
{{MathMLElement("mtext")}}✓
{{MathMLElement("mtr")}}✓
{{MathMLElement("munder")}}✓[accentunder](/en-US/docs/Web/MathML/Reference/Element/munder#accentunder)
{{MathMLElement("munderover")}}✓[accent](/en-US/docs/Web/MathML/Reference/Element/munderover#accent), [accentunder](/en-US/docs/Web/MathML/Reference/Element/munderover#accentunder)
{{MathMLElement("semantics")}}✓

Global attributes

The default configuration allows the following attributes on all elements.

HTML global attributes

  • [dir](/en-US/docs/Web/HTML/Reference/Global_attributes/dir)
  • [lang](/en-US/docs/Web/HTML/Reference/Global_attributes/lang)
  • [title](/en-US/docs/Web/HTML/Reference/Global_attributes/title)

MathML global attributes

  • displaystyle
  • [mathbackground](/en-US/docs/Web/MathML/Reference/Global_attributes/mathbackground)
  • [mathcolor](/en-US/docs/Web/MathML/Reference/Global_attributes/mathcolor)
  • [mathsize](/en-US/docs/Web/MathML/Reference/Global_attributes/mathsize)
  • [scriptlevel](/en-US/docs/Web/MathML/Reference/Global_attributes/scriptlevel)

SVG attributes

  • {{SVGAttr("alignment-baseline")}}
  • {{SVGAttr("baseline-shift")}}
  • {{SVGAttr("clip-path")}}
  • {{SVGAttr("clip-rule")}}
  • {{SVGAttr("color")}}
  • {{SVGAttr("color-interpolation")}}
  • {{SVGAttr("cursor")}}
  • {{SVGAttr("direction")}}
  • {{SVGAttr("display")}}
  • {{SVGAttr("dominant-baseline")}}
  • {{SVGAttr("fill")}}
  • {{SVGAttr("fill-opacity")}}
  • {{SVGAttr("fill-rule")}}
  • {{SVGAttr("font-family")}}
  • {{SVGAttr("font-size")}}
  • {{SVGAttr("font-size-adjust")}}
  • {{SVGAttr("font-stretch")}}
  • {{SVGAttr("font-style")}}
  • {{SVGAttr("font-variant")}}
  • {{SVGAttr("font-weight")}}
  • {{SVGAttr("letter-spacing")}}
  • {{SVGAttr("marker-end")}}
  • {{SVGAttr("marker-mid")}}
  • {{SVGAttr("marker-start")}}
  • {{SVGAttr("opacity")}}
  • {{SVGAttr("paint-order")}}
  • {{SVGAttr("pointer-events")}}
  • {{SVGAttr("shape-rendering")}}
  • {{SVGAttr("stop-color")}}
  • {{SVGAttr("stop-opacity")}}
  • {{SVGAttr("stroke")}}
  • {{SVGAttr("stroke-dasharray")}}
  • {{SVGAttr("stroke-dashoffset")}}
  • {{SVGAttr("stroke-linecap")}}
  • {{SVGAttr("stroke-linejoin")}}
  • {{SVGAttr("stroke-miterlimit")}}
  • {{SVGAttr("stroke-opacity")}}
  • {{SVGAttr("stroke-width")}}
  • {{SVGAttr("text-anchor")}}
  • {{SVGAttr("text-decoration")}}
  • {{SVGAttr("text-overflow")}}
  • {{SVGAttr("text-rendering")}}
  • {{SVGAttr("transform")}}
  • {{SVGAttr("transform-origin")}}
  • {{SVGAttr("unicode-bidi")}}
  • {{SVGAttr("vector-effect")}}
  • {{SVGAttr("visibility")}}
  • {{SVGAttr("white-space")}}
  • {{SVGAttr("word-spacing")}}
  • {{SVGAttr("writing-mode")}}