Fix: add filterXSSWithResult() to track removed tags and attributes (fixes #284) - #297
Merged
leizongmin merged 1 commit intoMay 6, 2026
Conversation
Joya-Biswas
force-pushed
the
feature/filter-xss-with-result
branch
2 times, most recently
from
April 17, 2026 20:53
8774ee5 to
d23efd4
Compare
Joya-Biswas
force-pushed
the
feature/filter-xss-with-result
branch
from
April 17, 2026 21:01
d23efd4 to
2c30203
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #284
Problem
When filterXSS() sanitizes HTML, it returns only the clean output string. There is no built-in way to know which tags or attributes were removed during sanitization. Users who need this information — for example, to display validation errors to their users — must manually wire up onIgnoreTag and onIgnoreTagAttr callbacks every single time they use the library. This is repetitive, easy to get wrong, and not obvious from the documentation.
Solution
This PR adds a new exported function:
filterXSSWithResult(html, options)It returns an object with two properties:
html— the sanitized HTML string, identical to whatfilterXSS()returnsremoved— an array of objects, one for each tag or attribute that was removedExample:
Notes
filterXSS()usage is completely unchangedonIgnoreTagoronIgnoreTagAttrin their options, those callbacks still fire correctlyremovedarray[]index.js— no changes to core filtering logicA note on process
I'm a beginner contributor and this is one of my first open source contributions.
I used Claude as a learning assistant to help me understand
the existing codebase and the JavaScript concepts involved. All decisions about
what to change, where to change it, and how to verify it were made by me and
tested locally before submitting.