Enhance Mermaid XSS protection with DOMPurify and input sanitization #200

Closed
opened 2026-02-02 18:07:54 +00:00 by jason.woltje · 0 comments
Owner

Context: Issue #190 was resolved with a minimal fix that addresses the critical vulnerability. However, a more comprehensive defense-in-depth implementation was designed by agent ad7f0e4.

Proposed Enhancement - 4-layer defense:

  1. Input Sanitization in useGraphData.ts with sanitizeMermaidLabel()
  2. Mermaid Strict Mode (already implemented)
  3. DOMPurify SVG sanitization
  4. Manual URI checking for dangerous protocols

Benefits:

  • Blocks advanced XSS vectors (foreignObject, SVG animations)
  • Prevents homograph attacks via Unicode control characters
  • DoS protection through input truncation
  • Defense-in-depth if Mermaid library has future vulnerabilities

Test Coverage: 90.15% (24 tests designed)
Priority: P2 (enhancement) - Core vulnerability patched

References: Agent ad7f0e4, docs/scratchpads/190-fix-mermaid-xss.md

Context: Issue #190 was resolved with a minimal fix that addresses the critical vulnerability. However, a more comprehensive defense-in-depth implementation was designed by agent ad7f0e4. Proposed Enhancement - 4-layer defense: 1. Input Sanitization in useGraphData.ts with sanitizeMermaidLabel() 2. Mermaid Strict Mode (already implemented) 3. DOMPurify SVG sanitization 4. Manual URI checking for dangerous protocols Benefits: - Blocks advanced XSS vectors (foreignObject, SVG animations) - Prevents homograph attacks via Unicode control characters - DoS protection through input truncation - Defense-in-depth if Mermaid library has future vulnerabilities Test Coverage: 90.15% (24 tests designed) Priority: P2 (enhancement) - Core vulnerability patched References: Agent ad7f0e4, docs/scratchpads/190-fix-mermaid-xss.md
jason.woltje added the p2securityweb labels 2026-02-02 18:07:54 +00:00
jason.woltje added this to the M7.1-Remediation (0.0.8) milestone 2026-02-03 22:31:44 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaic/stack#200