Skip to content

fix(security): 防止 Markdown / 文本对比 / 正则结果中的 DOM XSS - #9

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

fix(security): 防止 Markdown / 文本对比 / 正则结果中的 DOM XSS#9
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-inspection-dbd4

Conversation

@cursor

@cursor cursor Bot commented May 15, 2026

Copy link
Copy Markdown

问题与影响

index.html 中,Markdown 预览、文本对比与正则匹配结果将用户可控字符串直接写入 innerHTML。攻击者可诱导用户粘贴恶意内容(例如包含 <img onerror=…><script> 的片段),在同一来源下执行脚本,存在会话劫持、钓鱼等风险。

根因

未对插入 DOM 的 HTML 上下文做转义,仅依赖简易 Markdown/差异渲染替换,原始 HTML 会原样进入 innerHTML

修复

  • 新增 escapeHtml(),对 & < > " ' 进行实体转义。
  • Markdown:在应用标题/加粗等替换前先对整个输入转义。
  • 文本对比:对每行差异文本转义后再拼入模板。
  • 正则:对匹配子串及异常信息转义后再写入结果区。

验证

  • 代码审查确认上述三处为唯一将用户内容写入 innerHTML 的路径(工具网格与面板 HTML 来自静态模板)。
  • 未引入独立测试运行器;仓库为单文件静态站点,修复为业界标准转义模式。

备注

已核对 actions/upload-pages-artifact:对 .git / .github 有硬编码排除,部署工作流不构成仓库元数据泄露,本次未改动 CI。

Open in Web View Automation 

Prevents DOM XSS in Markdown preview, text diff, and regex match
display when pasting HTML or script-like payloads.

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