fix(security): 防止 Markdown / 文本对比 / 正则结果中的 XSS - #13
Draft
cursor[bot] wants to merge 1 commit into
Draft
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Markdown preview, text diff, and regex match output inserted raw user input into innerHTML, allowing script injection from pasted content. Add escapeHtml() and apply it to these code paths. Co-authored-by: Muki182 <Muki182@users.noreply.github.com>
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.
问题与影响
index.html中多处将用户输入直接写入innerHTML(Markdown 预览、文本对比、正则匹配结果)。攻击者可诱导用户粘贴恶意 HTML/脚本(例如<img src=x onerror=...>),在同源页面上下文执行脚本,属于存储型/反射型混合的 DOM XSS,影响机密性与完整性。根因
未对用户可控文本做 HTML 转义即拼接进 HTML 字符串。
修复
escapeHtml(),对&、"、'、<、>进行实体转义。innerHTML。message转义后再写入innerHTML。验证
escapeHtml逻辑做了断言(<script>→<script>,a&b→a&b)。<img src=x onerror=alert(1)>验证不再执行脚本。