fix: 对用户输入做 HTML 转义,修复 Markdown/文本对比/正则结果中的 XSS - #4
Draft
cursor[bot] wants to merge 1 commit into
Draft
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题与影响
index.html中多处将用户可控字符串直接拼进innerHTML:<img src=x onerror=...>)会原样进入预览 DOM,形成 DOM XSS。innerHTML,恶意文本可执行脚本。match()返回的子串直接插入 DOM,匹配到含尖括号的内容时同样可 XSS。在 GitHub Pages 的
*.github.io上,同一用户下的不同仓库路径常共享 同一 origin,此类脚本可能扩大影响面(例如读取同 host 下其他路径可访问的存储)。根因
为渲染富文本或高亮,使用
innerHTML拼接字符串,但未对 用户输入 做 HTML 实体转义。修复与验证
escapeHtml(),在写入innerHTML前对用户侧内容转义。escapeHtml,再应用原有的轻量级 Markdown 替换规则。la/lb使用escapeHtml。catch中的e.message使用escapeHtml。验证:用 Node 对
escapeHtml逻辑做了简单断言(含<>的字符串转义后不再含裸尖括号);仓库内暂无前端测试框架,未新增独立测试文件。范围说明
未改动静态数据驱动的
renderGrid/renderPanels(工具名等为内置常量);部署工作流未改。