Skip to content

修复 Markdown 预览、文本对比与正则结果中的 XSS - #17

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-correctness-bugs-7767
Draft

修复 Markdown 预览、文本对比与正则结果中的 XSS#17
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-correctness-bugs-7767

Conversation

@cursor

@cursor cursor Bot commented May 22, 2026

Copy link
Copy Markdown

问题与影响

在单页 index.html 中,Markdown 预览文本对比正则测试结果将用户输入直接拼进 innerHTML。攻击者可构造包含 <script> 或事件属性的文本,在同一来源下执行脚本,属于客户端 XSS(钓鱼、篡改页面等)。

根因

未对用户可控字符串做 HTML 转义即写入 innerHTML

修复

  • 新增 escapeHtml(),对 &"'<> 进行实体转义。
  • renderMD():先对整段 Markdown 源码转义,再应用原有简易语法替换。
  • textDiff():对每行展示内容转义后再插入模板。
  • testRegex():对匹配子串与异常信息转义后再写入 DOM。

验证

innerHTML 写入路径做了代码审查;仓库内无既有自动化测试框架,未新增测试文件。GitHub Pages 部署使用的 upload-pages-artifact 会排除 .git/.github,部署工作流未发现需改动的严重问题。

Open in Web View Automation 

renderMD, textDiff, and regex test output injected unsanitized user
input into innerHTML, allowing script execution from crafted text.

Co-authored-by: Muki182 <Muki182@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant