🛡️ Sentinel: [CRITICAL] Fix DOMPurify bypass in Mermaid foreignObject attributes#270
Conversation
Co-authored-by: ImChong <74563097+ImChong@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Vulnerability: Found a critical DOM-based XSS vulnerability in
assets/js/mermaid-config.js(sanitizeMermaidSvg) where an attacker could bypassDOMPurifyby embedding malicious attributes (e.g.,onload="alert(1)") in SVGforeignObjecttags. The code extractedforeignObjecttags using a regex, stored their unsanitized attributes, sanitized the rest of the SVG structure viaDOMPurify, and then blindly re-injected the raw attributes when restoring theforeignObjectcontent.Impact: A malicious actor could provide specially crafted Markdown that compiles into a Mermaid graph with malicious JavaScript, bypassing the site's default DOMPurify sanitization.
Fix: Let
DOMPurifynatively sanitize the placeholder attributes. The regex swap was updated to attach the extracted attributes directly onto thedata-fo-placeholderelement beforeDOMPurifyprocesses the entire SVG, effectively enforcing the sanitizer on those attributes.Verification: Manual verification via unit test scripts that DOMPurify properly scrubs
onloadattributes. All pytest Python test suites complete with success.PR created automatically by Jules for task 3219942391315052121 started by @ImChong