Skip to content

fix(security): Prevent DOM XSS in Markdown, text diff, and regex outputs - #5

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

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

Conversation

@cursor

@cursor cursor Bot commented May 10, 2026

Copy link
Copy Markdown

Bug and impact

DOM-based XSS in three client-only tools: anyone who pastes crafted text (or opens a shared snippet) could run arbitrary JavaScript in the victim’s origin. That can lead to session/token theft if the site later adds auth, malicious redirects, or defacement.

Concrete triggers

  1. Markdown 预览: paste # <img src=x onerror=alert(1)> — the old pipeline injected raw HTML into #md-preview via innerHTML.
  2. 文本对比: a line containing <img src=x onerror=alert(1)> was concatenated into diff HTML unchanged.
  3. 正则测试: a match substring containing HTML tags was written into innerHTML unescaped.

Root cause

User input (or match substrings / error messages) was interpolated into template strings assigned to element.innerHTML without HTML entity encoding.

Fix

  • Add escapeHtml() and use it before Markdown regex transforms (markdown syntax still works; angle brackets in content are neutralized).
  • Escape line content in textDiff() and match / error strings in testRegex().

Validation

  • Ran node scripts/verify-security.mjs (asserts escapeHtml behavior and that index.html contains the expected guard patterns).
Open in Web View Automation 

User-controlled strings were assigned to innerHTML without escaping,
allowing script injection (e.g. <img onerror=...> in Markdown preview).

Add escapeHtml(), apply before Markdown transforms and for diff/regex
displays. Add scripts/verify-security.mjs for regression checks.

Co-authored-by: Muki182 <Muki182@users.noreply.github.com>

This branch has not been deployed

No deployments
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