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.
This configuration removes the following sorts of items:
- Those that are known to be XSS-unsafe:
- Additional items that might be used in clickjacking, spoofing, or other attacks.
- 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.
Note:
Calling 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
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