安全修复:对用户输入做 HTML 转义,修复 Markdown/文本对比/正则结果中的 XSS - #8
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 used innerHTML with unescaped user input. Add escapeHtml and apply it before building HTML. Add a small Node test to lock in escapeHtml behavior. 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.
问题与影响
多个工具将用户可控内容直接拼进模板并赋给
innerHTML,可在当前页面执行任意脚本(自 XSS),并可能配合剪贴板/钓鱼造成实质危害。可复现场景示例
<img src=x onerror=alert(1)>,右侧预览会执行脚本。</div><script>...</script>的行,对比结果会解析为 HTML。根因
renderMD、textDiff、testRegex使用innerHTML拼接用户输入,未做 HTML 实体转义。修复与验证
escapeHtml,在写入innerHTML前对用户来源字符串转义。escapeHtml再做轻量 Markdown 替换,避免标签注入。escapeHtml。tests/escape-html.mjs,运行:node tests/escape-html.mjs(已通过)。说明
近期提交主要为 Pages 部署工作流;
upload-pages-artifact会排除.git/.github,未发现需改工作流的同等严重问题。本次缺陷位于首版index.html的客户端渲染路径。