@@ -11,49 +11,6 @@ const mediaTags = [
11
11
] ;
12
12
// Tags that are inherently vulnerable to being used in XSS attacks.
13
13
const vulnerableTags = [ 'script' , 'style' ] ;
14
- // Tags that cannot be boolean
15
- const nonBooleanAttributes = [
16
- 'abbr' , 'accept' , 'accept-charset' , 'accesskey' , 'action' ,
17
- 'allow' , 'alt' , 'as' , 'autocapitalize' , 'autocomplete' ,
18
- 'blocking' , 'charset' , 'cite' , 'class' , 'color' , 'cols' ,
19
- 'colspan' , 'content' , 'contenteditable' , 'coords' , 'crossorigin' ,
20
- 'data' , 'datetime' , 'decoding' , 'dir' , 'dirname' , 'download' ,
21
- 'draggable' , 'enctype' , 'enterkeyhint' , 'fetchpriority' , 'for' ,
22
- 'form' , 'formaction' , 'formenctype' , 'formmethod' , 'formtarget' ,
23
- 'headers' , 'height' , 'hidden' , 'high' , 'href' , 'hreflang' ,
24
- 'http-equiv' , 'id' , 'imagesizes' , 'imagesrcset' , 'inputmode' ,
25
- 'integrity' , 'is' , 'itemid' , 'itemprop' , 'itemref' , 'itemtype' ,
26
- 'kind' , 'label' , 'lang' , 'list' , 'loading' , 'low' , 'max' ,
27
- 'maxlength' , 'media' , 'method' , 'min' , 'minlength' , 'name' ,
28
- 'nonce' , 'optimum' , 'pattern' , 'ping' , 'placeholder' , 'popover' ,
29
- 'popovertarget' , 'popovertargetaction' , 'poster' , 'preload' ,
30
- 'referrerpolicy' , 'rel' , 'rows' , 'rowspan' , 'sandbox' , 'scope' ,
31
- 'shape' , 'size' , 'sizes' , 'slot' , 'span' , 'spellcheck' , 'src' ,
32
- 'srcdoc' , 'srclang' , 'srcset' , 'start' , 'step' , 'style' ,
33
- 'tabindex' , 'target' , 'title' , 'translate' , 'type' , 'usemap' ,
34
- 'value' , 'width' , 'wrap' ,
35
- // Event handlers
36
- 'onauxclick' , 'onafterprint' , 'onbeforematch' , 'onbeforeprint' ,
37
- 'onbeforeunload' , 'onbeforetoggle' , 'onblur' , 'oncancel' ,
38
- 'oncanplay' , 'oncanplaythrough' , 'onchange' , 'onclick' , 'onclose' ,
39
- 'oncontextlost' , 'oncontextmenu' , 'oncontextrestored' , 'oncopy' ,
40
- 'oncuechange' , 'oncut' , 'ondblclick' , 'ondrag' , 'ondragend' ,
41
- 'ondragenter' , 'ondragleave' , 'ondragover' , 'ondragstart' ,
42
- 'ondrop' , 'ondurationchange' , 'onemptied' , 'onended' ,
43
- 'onerror' , 'onfocus' , 'onformdata' , 'onhashchange' , 'oninput' ,
44
- 'oninvalid' , 'onkeydown' , 'onkeypress' , 'onkeyup' ,
45
- 'onlanguagechange' , 'onload' , 'onloadeddata' , 'onloadedmetadata' ,
46
- 'onloadstart' , 'onmessage' , 'onmessageerror' , 'onmousedown' ,
47
- 'onmouseenter' , 'onmouseleave' , 'onmousemove' , 'onmouseout' ,
48
- 'onmouseover' , 'onmouseup' , 'onoffline' , 'ononline' , 'onpagehide' ,
49
- 'onpageshow' , 'onpaste' , 'onpause' , 'onplay' , 'onplaying' ,
50
- 'onpopstate' , 'onprogress' , 'onratechange' , 'onreset' , 'onresize' ,
51
- 'onrejectionhandled' , 'onscroll' , 'onscrollend' ,
52
- 'onsecuritypolicyviolation' , 'onseeked' , 'onseeking' , 'onselect' ,
53
- 'onslotchange' , 'onstalled' , 'onstorage' , 'onsubmit' , 'onsuspend' ,
54
- 'ontimeupdate' , 'ontoggle' , 'onunhandledrejection' , 'onunload' ,
55
- 'onvolumechange' , 'onwaiting' , 'onwheel'
56
- ] ;
57
14
58
15
function each ( obj , cb ) {
59
16
if ( obj ) {
@@ -336,7 +293,7 @@ function sanitizeHtml(html, options, _recursing) {
336
293
}
337
294
// If the value is empty, and this is a known non-boolean attribute, delete it
338
295
// List taken from https://html.spec.whatwg.org/multipage/indices.html#attributes-3
339
- if ( value === '' && nonBooleanAttributes . includes ( a ) ) {
296
+ if ( value === '' && options . nonBooleanAttributes . includes ( a ) ) {
340
297
delete frame . attribs [ a ] ;
341
298
return ;
342
299
}
@@ -865,6 +822,49 @@ sanitizeHtml.defaults = {
865
822
'caption' , 'col' , 'colgroup' , 'table' , 'tbody' , 'td' , 'tfoot' , 'th' ,
866
823
'thead' , 'tr'
867
824
] ,
825
+ // Tags that cannot be boolean
826
+ nonBooleanAttributes : [
827
+ 'abbr' , 'accept' , 'accept-charset' , 'accesskey' , 'action' ,
828
+ 'allow' , 'alt' , 'as' , 'autocapitalize' , 'autocomplete' ,
829
+ 'blocking' , 'charset' , 'cite' , 'class' , 'color' , 'cols' ,
830
+ 'colspan' , 'content' , 'contenteditable' , 'coords' , 'crossorigin' ,
831
+ 'data' , 'datetime' , 'decoding' , 'dir' , 'dirname' , 'download' ,
832
+ 'draggable' , 'enctype' , 'enterkeyhint' , 'fetchpriority' , 'for' ,
833
+ 'form' , 'formaction' , 'formenctype' , 'formmethod' , 'formtarget' ,
834
+ 'headers' , 'height' , 'hidden' , 'high' , 'href' , 'hreflang' ,
835
+ 'http-equiv' , 'id' , 'imagesizes' , 'imagesrcset' , 'inputmode' ,
836
+ 'integrity' , 'is' , 'itemid' , 'itemprop' , 'itemref' , 'itemtype' ,
837
+ 'kind' , 'label' , 'lang' , 'list' , 'loading' , 'low' , 'max' ,
838
+ 'maxlength' , 'media' , 'method' , 'min' , 'minlength' , 'name' ,
839
+ 'nonce' , 'optimum' , 'pattern' , 'ping' , 'placeholder' , 'popover' ,
840
+ 'popovertarget' , 'popovertargetaction' , 'poster' , 'preload' ,
841
+ 'referrerpolicy' , 'rel' , 'rows' , 'rowspan' , 'sandbox' , 'scope' ,
842
+ 'shape' , 'size' , 'sizes' , 'slot' , 'span' , 'spellcheck' , 'src' ,
843
+ 'srcdoc' , 'srclang' , 'srcset' , 'start' , 'step' , 'style' ,
844
+ 'tabindex' , 'target' , 'title' , 'translate' , 'type' , 'usemap' ,
845
+ 'value' , 'width' , 'wrap' ,
846
+ // Event handlers
847
+ 'onauxclick' , 'onafterprint' , 'onbeforematch' , 'onbeforeprint' ,
848
+ 'onbeforeunload' , 'onbeforetoggle' , 'onblur' , 'oncancel' ,
849
+ 'oncanplay' , 'oncanplaythrough' , 'onchange' , 'onclick' , 'onclose' ,
850
+ 'oncontextlost' , 'oncontextmenu' , 'oncontextrestored' , 'oncopy' ,
851
+ 'oncuechange' , 'oncut' , 'ondblclick' , 'ondrag' , 'ondragend' ,
852
+ 'ondragenter' , 'ondragleave' , 'ondragover' , 'ondragstart' ,
853
+ 'ondrop' , 'ondurationchange' , 'onemptied' , 'onended' ,
854
+ 'onerror' , 'onfocus' , 'onformdata' , 'onhashchange' , 'oninput' ,
855
+ 'oninvalid' , 'onkeydown' , 'onkeypress' , 'onkeyup' ,
856
+ 'onlanguagechange' , 'onload' , 'onloadeddata' , 'onloadedmetadata' ,
857
+ 'onloadstart' , 'onmessage' , 'onmessageerror' , 'onmousedown' ,
858
+ 'onmouseenter' , 'onmouseleave' , 'onmousemove' , 'onmouseout' ,
859
+ 'onmouseover' , 'onmouseup' , 'onoffline' , 'ononline' , 'onpagehide' ,
860
+ 'onpageshow' , 'onpaste' , 'onpause' , 'onplay' , 'onplaying' ,
861
+ 'onpopstate' , 'onprogress' , 'onratechange' , 'onreset' , 'onresize' ,
862
+ 'onrejectionhandled' , 'onscroll' , 'onscrollend' ,
863
+ 'onsecuritypolicyviolation' , 'onseeked' , 'onseeking' , 'onselect' ,
864
+ 'onslotchange' , 'onstalled' , 'onstorage' , 'onsubmit' , 'onsuspend' ,
865
+ 'ontimeupdate' , 'ontoggle' , 'onunhandledrejection' , 'onunload' ,
866
+ 'onvolumechange' , 'onwaiting' , 'onwheel'
867
+ ] ,
868
868
disallowedTagsMode : 'discard' ,
869
869
allowedAttributes : {
870
870
a : [ 'href' , 'name' , 'target' ] ,
0 commit comments