Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented May 7, 2026

Copy link
Copy Markdown

问题与影响

index.html 中多处将用户可控字符串直接拼进 innerHTML

  • Markdown 预览:未匹配的 HTML 片段(例如 <img src=x onerror=...>)会原样进入预览 DOM,形成 DOM XSS
  • 文本对比:对比结果按行写入 innerHTML,恶意文本可执行脚本。
  • 正则测试match() 返回的子串直接插入 DOM,匹配到含尖括号的内容时同样可 XSS。

在 GitHub Pages 的 *.github.io 上,同一用户下的不同仓库路径常共享 同一 origin,此类脚本可能扩大影响面(例如读取同 host 下其他路径可访问的存储)。

根因

为渲染富文本或高亮,使用 innerHTML 拼接字符串,但未对 用户输入 做 HTML 实体转义。

修复与验证

  • 新增 escapeHtml(),在写入 innerHTML 前对用户侧内容转义。
  • Markdown:先对全文 escapeHtml,再应用原有的轻量级 Markdown 替换规则。
  • 文本对比:对每行 la/lb 使用 escapeHtml
  • 正则:对匹配项与 catch 中的 e.message 使用 escapeHtml

验证:用 Node 对 escapeHtml 逻辑做了简单断言(含 <> 的字符串转义后不再含裸尖括号);仓库内暂无前端测试框架,未新增独立测试文件。

范围说明

未改动静态数据驱动的 renderGrid/renderPanels(工具名等为内置常量);部署工作流未改。

Open in Web View Automation 

Prevents DOM XSS when pasting HTML-like payloads; GitHub Pages project
sites share origin with other paths under the same github.io host.

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