Skip to content

Commit aff7818

Browse files
feat: move nonbooleanattributes to options
1 parent d560170 commit aff7818

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

index.js

+44-44
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,6 @@ const mediaTags = [
1111
];
1212
// Tags that are inherently vulnerable to being used in XSS attacks.
1313
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-
];
5714

5815
function each(obj, cb) {
5916
if (obj) {
@@ -336,7 +293,7 @@ function sanitizeHtml(html, options, _recursing) {
336293
}
337294
// If the value is empty, and this is a known non-boolean attribute, delete it
338295
// 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)) {
340297
delete frame.attribs[a];
341298
return;
342299
}
@@ -865,6 +822,49 @@ sanitizeHtml.defaults = {
865822
'caption', 'col', 'colgroup', 'table', 'tbody', 'td', 'tfoot', 'th',
866823
'thead', 'tr'
867824
],
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+
],
868868
disallowedTagsMode: 'discard',
869869
allowedAttributes: {
870870
a: [ 'href', 'name', 'target' ],

0 commit comments

Comments
 (0)