fix(editor): prevent XSS in details summary previews - #2942
Merged
Conversation
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.
Summary
Fix XSS in the Markdown editor’s source-backed details summary preview. Sanitize descendants before unwrapping unsupported HTML elements, reject foreign namespaces, and validate link/image protocols using browser URL parsing and explicit allowlists. Without a DOM, return escaped text instead of raw HTML.
Type and Areas
Type: Bug fix (security)
Areas: Web UI / Markdown editor, browser regression tests
Motivation / Impact
The previous traversal could retain event handlers inside an unsupported wrapper. Its URL prefix check also missed control characters normalized by the browser. These paths could execute document-controlled JavaScript when rendering or interacting with a details summary, including live source-block edits.
The fix preserves supported formatting, links, image metadata, and original Markdown bytes. Regression coverage exercises both initial document loading and live editing; the initial parser and source-backed preview use different paths.
Verification
pnpm run check:web: passed.pnpm --dir src/web-ui exec tsc --noEmit: passed on the final implementation.pnpm --dir src/web-ui exec vitest run src/tools/editor/meditor/utils/sanitizeDetailsSummaryHtml.test.ts: 39 passed after the final traversal adjustment.pnpm --dir tests/e2e exec wdio run ./config/wdio.markdown-browser.ts: the 10 existing browser cases passed. After correcting the new test fixture and interaction steps,pnpm --dir tests/e2e exec wdio run ./config/wdio.markdown-browser.ts --mochaOpts.grep 'sanitizes loaded'passed the new security case, including no script execution and exact save/source round-trip preservation.git diff --check: passed.Reviewer Notes
AI-assisted implementation; testing level: focused automated unit/DOM and real-browser verification. No native Tauri, live SSH workspace, Remote Connect, Peer Device Mode, or Detached Dispatch execution was tested. Relative and supported host/workspace URLs are covered as sanitizer inputs; that is not live remote-transport coverage.
No server configuration, dependency versions, persisted schemas, or user-facing strings change. No migration is required.
Checklist