Default sanitizer configuration
The default sanitizer configuration defines the configuration returned by the Sanitizer() constructor if no configuration is passed as an argument.
This same configuration is implicitly used if you call the safe sanitization methods, such as Element.setHTML(), ShadowRoot.setHTML(), and Document.parseHTML(), without specifying a custom sanitizer.
The default sanitizer configuration is applied on top of the XSS-safe baseline configuration which removes unsafe elements (for example <script>), event handlers, and JavaScript URLs.
This configuration removes the following items in addition to the XSS-safe baseline configuration:
- Elements that might be used in clickjacking, spoofing, or other attacks by only allowing an allow list of elements.
- Attributes that might be used in clickjacking, spoofing, or other attacks by only allowing an allow list of global, and element-specific attributes.
- Processing instructions and comments
data-*attributes.
It therefore provides a sanitizer with a minimal attack surface, which is still suitable for the majority of sanitization use cases.
Note:
Calling Sanitizer.removeUnsafe(), or passing an empty custom sanitizer to the safe sanitization method, only removes the XSS-unsafe items as defined in the XSS-safe baseline configuration.
It does not remove the additional elements, attributes, processing instructions, 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
SVG elements
MathML elements
| Element | Allowed | Additional allowed attributes |
|---|---|---|
<annotation> |
❌ | |
<annotation-xml> |
❌ | |
<maction> |
❌ | |
<math> |
✓ | |
<menclose> |
❌ | |
<merror> |
✓ | |
<mfenced> |
❌ | |
<mfrac> |
✓ | |
<mi> |
✓ | |
<mmultiscripts> |
✓ | |
<mn> |
✓ | |
<mo> |
✓ | fence, form, largeop, lspace, maxsize, minsize, movablelimits, rspace, separator, stretchy, symmetric |
<mover> |
✓ | accent |
<mpadded> |
✓ | depth, height, lspace, voffset, width |
<mphantom> |
✓ | |
<mprescripts> |
✓ | |
<mroot> |
✓ | |
<mrow> |
✓ | |
<ms> |
✓ | |
<mspace> |
✓ | depth, height, width |
<msqrt> |
✓ | |
<mstyle> |
✓ | |
<msub> |
✓ | |
<msubsup> |
✓ | |
<msup> |
✓ | |
<mtable> |
✓ | |
<mtd> |
✓ | columnspan, rowspan |
<mtext> |
✓ | |
<mtr> |
✓ | |
<munder> |
✓ | accentunder |
<munderover> |
✓ | accent, accentunder |
<semantics> |
✓ |
Global attributes
The default configuration allows the following attributes on all elements.
HTML global attributes
MathML global attributes
displaystylemathbackgroundmathcolormathsizescriptlevel
SVG attributes
alignment-baselinebaseline-shiftclip-pathclip-rulecolorcolor-interpolationcursordirectiondisplaydominant-baselinefillfill-opacityfill-rulefont-familyfont-sizefont-size-adjustfont-stretchfont-stylefont-variantfont-weightletter-spacingmarker-endmarker-midmarker-startopacitypaint-orderpointer-eventsshape-renderingstop-colorstop-opacitystrokestroke-dasharraystroke-dashoffsetstroke-linecapstroke-linejoinstroke-miterlimitstroke-opacitystroke-widthtext-anchortext-decorationtext-overflowtext-renderingtransformtransform-originunicode-bidivector-effectvisibilitywhite-spaceword-spacingwriting-mode