You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2026. It is now read-only.
"What if I want to allow all tags or all attributes?"
Simple! instead of leaving allowedTags or allowedAttributes out of the options, set either one or both to false:
allowedTags: false,allowedAttributes: false
The internal check checks whether allowedTags is falsey, not false.
Treating null equivalently to false is problematic since null is
much more likely as an output from a function that otherwise
returns an array than false, so treating null and undefined
as equivalent to false is a corner-case with very serious security consequences.
For example,
constMY_POLICY={allowedTags: computeAllowedTags()};functioncomputeAllowedTags(){if(complexCondition){returnINLINE_ELEMENTS;}elseif(anotherComplexCondition){returnBLOCK_AND_INLINE_ELEMENTS;}elseif(adNauseam){returnFORMATTING_ELEMENTS_AND_IMAGES;}// NOTE: Missing return at bottom implies return of undefined}
Since the behavior for undefined and null, 0, NaN, "" and other falsey values is not documented, I recommend either
changing the code that fils in blanks:
options=extend(sanitizeHtml.defaults,options);
to first remove any properties with falsey, but non-false values.
The docs say
The internal check checks whether
allowedTagsis falsey, not false.Treating
nullequivalently to false is problematic sincenullismuch more likely as an output from a function that otherwise
returns an array than
false, so treatingnullandundefinedas equivalent to
falseis a corner-case with very serious security consequences.For example,
Since the behavior for
undefinedandnull,0,NaN,""and other falsey values is not documented, I recommend eitherfalse:allowedAttributes.