Skip to content

安全修复:对用户输入做 HTML 转义,修复 Markdown/文本对比/正则结果中的 XSS - #8

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-inspection-2f59
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-inspection-2f59

Conversation

@cursor

@cursor cursor Bot commented May 14, 2026

Copy link
Copy Markdown

问题与影响

多个工具将用户可控内容直接拼进模板并赋给 innerHTML,可在当前页面执行任意脚本(自 XSS),并可能配合剪贴板/钓鱼造成实质危害。

可复现场景示例

  1. 打开「Markdown 预览」,在左侧输入 <img src=x onerror=alert(1)>,右侧预览会执行脚本。
  2. 「文本对比」中在某一侧输入包含 </div><script>...</script> 的行,对比结果会解析为 HTML。
  3. 「正则测试」中若匹配结果包含 HTML 片段,会以未转义形式写入结果区。

根因

renderMDtextDifftestRegex 使用 innerHTML 拼接用户输入,未做 HTML 实体转义。

修复与验证

  • 新增 escapeHtml,在写入 innerHTML 前对用户来源字符串转义。
  • Markdown:先对全文 escapeHtml 再做轻量 Markdown 替换,避免标签注入。
  • 文本对比、正则匹配结果及正则错误信息:对插入片段使用 escapeHtml
  • 新增 tests/escape-html.mjs,运行:node tests/escape-html.mjs(已通过)。

说明

近期提交主要为 Pages 部署工作流;upload-pages-artifact 会排除 .git/.github,未发现需改工作流的同等严重问题。本次缺陷位于首版 index.html 的客户端渲染路径。

Open in Web View Automation 

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>
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