Skip to content

fix: strip event handlers in htmlToFragment before compose DOM insertion#171

Open
JuliaKalder wants to merge 1 commit into
mainfrom
fix/issue-161
Open

fix: strip event handlers in htmlToFragment before compose DOM insertion#171
JuliaKalder wants to merge 1 commit into
mainfrom
fix/issue-161

Conversation

@JuliaKalder
Copy link
Copy Markdown
Owner

Summary

Strips inline event-handler attributes (on*) and dangerous URI schemes from DOM nodes before inserting template HTML into the Thunderbird compose window in cursor mode.

Problem

Template HTML was inserted directly into the Thunderbird compose editor DOM via Range.insertNode without stripping inline event handlers. The compose window is not governed by the extension's script-src 'self' CSP, so on* attributes (onerror, onload, onmouseover, etc.) fire immediately upon DOM insertion.

Template HTML can reach this code from attacker-controlled sources:

Changes

  • Added stripDangerousContent(root) using TreeWalker to remove all on* attributes from every element in the imported node tree
  • Also strips javascript: and data: URIs from src/href attributes to block navigation-based XSS
  • Updated htmlToFragment() to call stripDangerousContent() on each imported element node before appending to the fragment

Testing

All 96 existing tests pass. The fix is minimal and isolated to modules/compose-script.js.

Fixes #161

Adds stripDangerousContent() that walks the imported node tree and
removes all on* attributes, plus javascript: and data: URIs from
src/href. Called in htmlToFragment() for every imported element node
before it is appended to the fragment that Range.insertNode places
into the compose-window DOM.

The compose window is not governed by the extension's script-src 'self'
CSP, so inline event handlers would execute immediately on insertion.
Template HTML can originate from saved emails or imported JSON files,
both of which are attacker-controlled sources.

Fixes #161
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.

[HIGH] compose-script.js: cursor-mode insertion executes event handlers in compose window DOM without sanitization

1 participant