Skip to content

fix: prevent DOM XSS in text diff, Markdown preview, and regex output - #2

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

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

Conversation

@cursor

@cursor cursor Bot commented May 2, 2026

Copy link
Copy Markdown

Summary

Fixes a DOM-based XSS in the static index.html tool page: user-controlled text was inserted into innerHTML without escaping in three places (text diff, Markdown preview, regex match highlights).

Bug and impact

  • Impact: A user pasting crafted HTML/JS in those tools could execute script in the same origin (e.g. steal session cookies on same-site apps, deface the page, or phish in the same tab). Severity is high for any deployment where this page shares origin with sensitive apps; it is still a real XSS class bug on GitHub Pages–hosted static sites.

Root cause

  • textDiff() built HTML from line strings with ${la} / ${lb} unescaped.
  • renderMD() ran markdown transforms on raw input, then assigned to innerHTML — any <script> or event handlers in input executed.
  • testRegex() embedded match substrings in innerHTML unescaped.

Fix

  • Added escapeHtml() and used it for diff lines, for Markdown input (before applying the simple regex-based “markdown” rules), and for each regex match string when building the result HTML.

Validation

  • Manual code review: all three innerHTML write paths that mixed user text with markup now escape that text first.
  • No package.json / test runner in repo; no automated tests added.
Open in Web View Automation 

Escape text in text diff, markdown preview (before applying markdown
substitutions), and regex match output so pasted content cannot run
as HTML/JS in the static tool page.

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