fix(security): 防止文本对比/Markdown/正则结果中的 DOM XSS - #3
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
…results Prevent stored DOM XSS when pasting HTML or script-like payloads into text diff, Markdown preview, or regex match output paths that used innerHTML with unescaped user content. 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.
问题与影响
在「文本对比」「Markdown 预览」「正则测试」中,用户输入被直接拼进
innerHTML。攻击者可诱导受害者粘贴含 HTML/事件属性的载荷(例如<img src=x onerror=alert(1)>),在同源页面上下文中执行脚本,造成会话劫持、钓鱼等。根因
将未转义的用户字符串写入
innerHTML;Markdown 路径若仅转义捕获组,未匹配到 markdown 语法的裸 HTML 仍会原样进入 DOM。修复
escapeHtml(),在写入innerHTML前转义用户内容。textDiff():对每行差异内容转义。renderMD():先对整段输入escapeHtml再应用简易 markdown 替换。testRegex():对匹配子串与异常信息转义。验证
<script>或onerror载荷应显示为文本而非执行。