fix: 对用户内容 innerHTML 输出做转义以防止 XSS - #19
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 Markdown preview, text diff, and regex match output so pasted HTML or event handlers cannot execute in the same origin. 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.
问题与影响
在 Markdown 预览、文本对比与正则测试结果中,用户输入被直接拼进
innerHTML。攻击者可诱导用户粘贴恶意片段(例如包含<img onerror=...>或事件属性的内容),在同一页面上下文中执行脚本,存在存储型/反射型 DOM XSS 风险(同源下可滥用页面能力)。根因
将未转义的用户可控字符串插入
innerHTML,浏览器会解析其中的 HTML 与事件处理器。修复与验证
escapeHtml(),在写入innerHTML前对用户侧文本做实体转义。验证:手动在 Markdown 中输入
**<img src=x onerror=alert(1)>**、在文本对比中输入含<img onerror=...>的行、在正则测试文本中含 HTML,修复后应显示为纯文本而非执行脚本。仓库为纯静态单页,未引入 Node 测试框架;未添加自动化测试。