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.
Repository navigation
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.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Should I pick this up? This seems to be an issue as null or undefined are behaving the same as false. As per the documentation, only false value should be respected.
Also, @mikesamuel has given a very good example in which such mistakes can occur, if a function like computeAllowedTags is being used which misses a default return.
Please let me know your opinion. I will raise a PR if you want.
Activity
stale commentedon Jul 7, 2020
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
kedarchandrayan commentedon Sep 23, 2022
Hello @boutell,
Should I pick this up? This seems to be an issue as
nullorundefinedare behaving the same asfalse. As per the documentation, onlyfalsevalue should be respected.Also, @mikesamuel has given a very good example in which such mistakes can occur, if a function like
computeAllowedTagsis being used which misses a default return.Please let me know your opinion. I will raise a PR if you want.
Thanks,
Kedar Chandrayan
boutell commentedon Sep 30, 2022
Feel free. Sounds like there's a good reason for a runtime check on this.
kedarchandrayan commentedon Oct 11, 2022
Hello @boutell,
I have raised the PR as per the discussion. Also added new test cases for covering the expected behavior. Please let me know your comments.
Thanks,
Kedar Chandrayan