Skip to content

fix: 修复 Markdown / 文本对比 / 正则结果中的 XSS - #16

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

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

Conversation

@cursor

@cursor cursor Bot commented May 21, 2026

Copy link
Copy Markdown

问题与影响

单页工具箱中多处将用户输入直接写入 innerHTML。攻击者可诱导用户在「Markdown 预览」「文本对比」或「正则测试」中粘贴恶意 HTML/脚本,从而在受害者浏览器中执行任意 JavaScript(窃取本页上下文中的敏感操作、钓鱼等)。

根因

  • renderMD():未对 Markdown 原文做 HTML 转义,原始标签会进入 DOM。
  • textDiff():对比行内容直接拼进 HTML 字符串。
  • testRegex():匹配子串与部分错误信息直接拼进 HTML。

修复

新增 escapeHtml(),在上述路径对用户可见内容转义后再写入 innerHTML。

验证

  • 已核对 actions/upload-pages-artifact 会排除 .git / .github,部署工作流不构成元数据泄露问题。
  • 仓库为纯静态单文件,未引入额外测试框架;修复为确定性字符串转义,逻辑上可阻断基于上述三处注入点的脚本执行。
Open in Web View Automation 

Escape user-controlled strings before assigning to innerHTML in
renderMD, textDiff, and testRegex so pasted HTML cannot execute as script.

Co-authored-by: Muki182 <Muki182@users.noreply.github.com>

This branch has not been deployed

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