fix: 修复 Markdown / 文本对比 / 正则工具中的 XSS - #12
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
Escape user-controlled strings before innerHTML in diff/regex tools. Sanitize markdown-generated HTML with DOMPurify; plain-text fallback if CDN blocked. 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.
问题与影响
在纯前端工具页中,多处将用户输入直接写入
innerHTML,导致存储型 DOM XSS:攻击者诱导用户粘贴恶意内容即可在同一页面上下文执行脚本,可窃取剪贴板、篡改界面或劫持会话(对在本页粘贴敏感 Token 的用户风险尤其高)。根因
renderMD()将未匹配的原始 HTML 片段与简易替换结果一并赋给innerHTML。textDiff()将两侧行内容拼进 HTML 字符串而未转义。testRegex()将匹配子串及异常信息拼进 HTML 而未转义。修复
escapeHtml(),在textDiff与testRegex中对用户侧文本做 HTML 实体转义后再插入模板。sanitize;若脚本被拦截则回退为textContent纯文本预览,避免静默恢复为不安全路径。验证
innerHTML赋值路径中用户内容均已转义或由 DOMPurify 过滤;无自动化测试(仓库为单文件静态页,无现有测试框架)。