fix(security): escape mXSS-detection text fallback in sanitizeHtmlCore - #182
Merged
Conversation
The double-parse stability check returned raw fragment.textContent when serialize->re-parse output differed. Since every caller assigns the result to an HTML sink (innerHTML/insertAdjacentHTML), entity-smuggled payloads (e.g. <img onerror=...> combined with table foster-parenting to force instability) were handed back as live markup - the mXSS defense itself became the injection sink. The fallback is now HTML-escaped before being returned. Fixes #162 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
Fixes #162 (Critical).
The anti-mXSS double-parse in
sanitizeHtmlCorereturned raw, unescapedfragment.textContentwhen the serialize→re-parse output was unstable. Every caller assigns the return value to an HTML sink (innerHTML/insertAdjacentHTMLvia.html(),.append(),bq-html, …), so an attacker could smuggle an entity-encoded payload (<img src=x onerror=...>) plus a construct that forces re-parse instability (<a><table><a>…foster-parenting) and get live markup back — the mXSS defense itself was the injection sink.Fix
The text fallback is now HTML-escaped before being returned (local
escapeHtmlTexthelper insanitize-core.tsto avoid a circular import withsanitize.ts).Verification
<a><table><a><img src=x onerror=alert(1)>; asserts no<img>element materializes when the result is assigned toinnerHTML.<img src=x onerror=alert(1)>(inert text).bun test tests/security.test.ts: 59 pass / 0 fail.tsc --noEmitclean.🤖 Generated with Claude Code