Published

XML Module: update the HTML sanitizer configuration

Last modified by Michael Hamann on 2026/11/17 15:39

Mirror the updated HTML sanitizer section of xwiki.properties (XWIKI-25787, XCOMMONS-3871): built-in restriction of the for attribute (XCOMMONS-3866), sms and matrix in the default allowed URI pattern, and up-to-date links to the lists of allowed tags and attributes.

All changes

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.MichaelHamann
1 +xwiki:XWiki.MichaelHamannNoAdmin
ExtensionCode.ExtensionClass[0]
Description
... ... @@ -52,9 +52,9 @@
52 52  #-# Comma-separated list of additional tags that should be allowed by the HTML sanitizer. These tags will be allowed
53 53  #-# in addition to the already extensive built-in list of tags that are considered safe. Use with care to avoid
54 54  #-# introducing security issues. By default, the following tags are allowed:
55 -#-# HTML tags: https://github.com/xwiki/xwiki-commons/blob/99484d48e899a68a1b6e33d457825b776c6fe8c3/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/HTMLDefinitions.java#L63-L74
56 -#-# SVG tags: https://github.com/xwiki/xwiki-commons/blob/b11eae9d82cb53f32962056b5faa73f3720c6182/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/SVGDefinitions.java#L91-L102
57 -#-# MathML tags: https://github.com/xwiki/xwiki-commons/blob/b11eae9d82cb53f32962056b5faa73f3720c6182/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/MathMLDefinitions.java#L62-L64
55 +#-# HTML tags: https://github.com/xwiki/xwiki-commons/blob/f03af50387bcbed086c16437980a4736ad96f71a/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/HTMLDefinitions.java#L76-L86
56 +#-# SVG tags: https://github.com/xwiki/xwiki-commons/blob/f03af50387bcbed086c16437980a4736ad96f71a/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/SVGDefinitions.java#L100-L115
57 +#-# MathML tags: https://github.com/xwiki/xwiki-commons/blob/f03af50387bcbed086c16437980a4736ad96f71a/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/MathMLDefinitions.java#L257-L260
58 58  # xml.htmlElementSanitizer.extraAllowedTags =
59 59  
60 60  #-# [Since 14.6RC1]
... ... @@ -62,10 +62,10 @@
62 62  #-# be allowed in addition to the already extensive built-in list of attributes that are considered safe. This option
63 63  #-# is useful if your content uses attributes that are invalid in HTML. Use with care to avoid introducing security
64 64  #-# issues. By default, the following attributes are allowed:
65 -#-# HTML attributes: https://github.com/xwiki/xwiki-commons/blob/99484d48e899a68a1b6e33d457825b776c6fe8c3/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/HTMLDefinitions.java#L76-L91
66 -#-# SVG attributes: https://github.com/xwiki/xwiki-commons/blob/b11eae9d82cb53f32962056b5faa73f3720c6182/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/SVGDefinitions.java#L66-L89
67 -#-# MathML attributes: https://github.com/xwiki/xwiki-commons/blob/b11eae9d82cb53f32962056b5faa73f3720c6182/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/MathMLDefinitions.java#L73-L79
68 -#-# XML attributes: https://github.com/xwiki/xwiki-commons/blob/b11eae9d82cb53f32962056b5faa73f3720c6182/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/SecureHTMLElementSanitizer.java#L135
65 +#-# HTML attributes: https://github.com/xwiki/xwiki-commons/blob/f03af50387bcbed086c16437980a4736ad96f71a/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/HTMLDefinitions.java#L92-L105
66 +#-# SVG attributes: https://github.com/xwiki/xwiki-commons/blob/f03af50387bcbed086c16437980a4736ad96f71a/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/SVGDefinitions.java#L72-L98
67 +#-# MathML attributes: https://github.com/xwiki/xwiki-commons/blob/f03af50387bcbed086c16437980a4736ad96f71a/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/MathMLDefinitions.java#L268-L274
68 +#-# XML attributes: https://github.com/xwiki/xwiki-commons/blob/f03af50387bcbed086c16437980a4736ad96f71a/xwiki-commons-core/xwiki-commons-xml/src/main/java/org/xwiki/xml/internal/html/SecureHTMLElementSanitizer.java#L158-L159
69 69  # xml.htmlElementSanitizer.extraAllowedAttributes =
70 70  
71 71  #-# [Since 14.6RC1]
... ... @@ -90,9 +90,12 @@
90 90  #-# This property can be set on several lines to declare several attributes (one attribute per line); listing the same
91 91  #-# attribute on several lines does not accumulate, only the last line is kept, so list all elements of an attribute
92 92  #-# in a single value.
93 -#-# By default, only the "name" attribute is restricted: to mitigate DOM clobbering it is allowed solely on "a" (legacy
94 -#-# anchors) and "map" (image maps) and forbidden on all other elements. For example, to additionally allow "name" on
95 -#-# "div" and "section" and to restrict the "headers" attribute to the table cells "th" and "td":
93 +#-# By default, two attributes are restricted:
94 +#-# - "name" is allowed solely on "a" (legacy anchors) and "map" (image maps) to mitigate DOM clobbering
95 +#-# - "for" is allowed solely on "label" and "output", as on other elements like "template" it can be used to patch
96 +#-# content into other parts of the page (declarative partial updates)
97 +#-# For example, to additionally allow "name" on "div" and "section" and to restrict the "headers" attribute to the
98 +#-# table cells "th" and "td":
96 96  #-# xml.htmlElementSanitizer.extraElementRestrictedAttributes = name = div section, headers = th td
97 97  # xml.htmlElementSanitizer.extraElementRestrictedAttributes =
98 98  
... ... @@ -104,8 +104,8 @@
104 104  
105 105  #-# [Since 14.6RC1]
106 106  #-# If unknown protocols are disallowed (see above), the (Java) regular expression URIs are matched against.
107 -#-# The default values is ^(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):
108 -# xml.htmlElementSanitizer.allowedUriRegexp = ^(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):
110 +#-# The default values is ^(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):
111 +# xml.htmlElementSanitizer.allowedUriRegexp = ^(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):
109 109  
110 110  #-# [Since 14.6RC1]
111 111  #-# Comma-separated list of additional tags on which data-URIs should be allowed in "src", "xlink:href" or "href".
... ... @@ -121,8 +121,16 @@
121 121  #-# security issues.
122 122  # xml.htmlElementSanitizer.extraURISafeAttributes =
123 123  {{/code}}
127 +
128 +{{version since="17.10.15,18.4.9,18.10.0-rc-1"}}
129 +By default, the ##for## attribute is only allowed on the ##label## and ##output## elements. On other elements like ##template##, it can be used to patch content into other parts of the page ([[declarative partial updates>>https://github.com/WICG/declarative-partial-updates]]). Use ##xml.htmlElementSanitizer.extraElementRestrictedAttributes## to allow it on further elements.
124 124  {{/version}}
125 125  
132 +{{version since="18.10.0-rc-1"}}
133 +The ##sms:## and ##matrix:## protocols are part of the default value of ##xml.htmlElementSanitizer.allowedUriRegexp##.
134 +{{/version}}
135 +{{/version}}
136 +
126 126  {{version since="15.10"}}
127 127  A special filter with name ##restrictedFilterDetector## can be added to the list of filters to detect if restricted mode would affect the outcome of HTML cleaning by removing elements, attributes or comments. It's result is available as a boolean (value ##true##/##false##) attribute with name ##restrictedFiltering## on the document element of the filtered content. This can be used to determine automatically if HTML content could also be used with restricted cleaning without risking any breakage. This filter cannot be used in restricted mode.
128 128  {{/version}}
Nov 17, 2026, 3:39:54 PM

Approved by Michael Hamann

Approvers

Approvers have not been explicitly defined for this Change Request. Approvers will be based entirely on approval rights.

Get Connected