Configure the HTML Sanitizer

Last modified by superadmin on 2026/12/04 14:35

XWiki removes from untrusted content every HTML element and attribute it does not know to be safe; xwiki.properties is where that list is adjusted.

Steps

Form elements, iframe and anything that can carry a script are not on that list, so content that legitimately needs one of them is rendered without it. Widening the list, or narrowing it further, is the one thing about the sanitizer you configure, and the threats it closes are described in Attack Vectors.

  1. Identify what was removed, by reading the HTML the wiki produced for the content that lost it:
    curl -s https://wiki.example.org/xwiki/bin/view/Sandbox/WebHome | grep -i iframe

    The command prints nothing when the element was sanitized away.

  2. Stop the XWiki instance, open the xwiki/WEB-INF/xwiki.properties configuration file and set the properties of its "HTML Sanitization" block that your content needs:
    # Keep elements and attributes that the built-in list does not have.
    xml.htmlElementSanitizer.extraAllowedTags = iframe
    xml.htmlElementSanitizer.extraAllowedAttributes = allowfullscreen
    
    # Drop ones that it does have. These win over everything allowed above.
    xml.htmlElementSanitizer.forbidTags = video, audio
    xml.htmlElementSanitizer.forbidAttributes = style

    Every name on the first two lines is a hole you choose to open: the sanitizer stops judging it, so anyone who can write wiki syntax or leave a comment can use it.

  3. Restart the XWiki instance, then reload the page and read its HTML again. What you allowed is now in the output:
    <iframe src="https://example.org/map" allowfullscreen></iframe>
Warning

xml.htmlElementSanitizer itself takes a second value, insecure, which allows everything including JavaScript. It is only defensible where every account that can write a page or leave a comment is trusted with the browser of everyone who reads the wiki. A value XWiki does not recognize falls back to secure, so a typo cannot quietly switch the sanitizer off.

FAQ

Why can this not be set in the wiki administration?

The sanitizer reads xwiki.properties alone, through the configuration source that ignores wiki pages. A user who can edit a page must not be able to switch off what sanitizes that page.

Why was a name attribute removed from a div?

name is allowed only on a and map, so that content cannot shadow a property of the page's JavaScript by naming an element after it. XWiki 17.10.10+ xml.htmlElementSanitizer.extraElementRestrictedAttributes widens that list, one attribute per line.

Can a link use a protocol the sanitizer refuses?

xml.htmlElementSanitizer.allowUnknownProtocols is on by default and already allows protocols such as xwiki:; switching it off restricts links to xml.htmlElementSanitizer.allowedUriRegexp. data: URIs are separate, and xml.htmlElementSanitizer.extraDataUriTags names the tags that may carry one.

Does this change the HTML macro's clean parameter?

No. Setting it to false turns the cleaning off for one macro, and using it requires Script right, so it is governed by rights rather than by these settings.

Related

Get Connected