🔒 Fix XSS vulnerability by replacing @html with a secure dompurify fragment action - #72
Conversation
Co-authored-by: Sparkier <5690524+Sparkier@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. |
🎯 What: The vulnerability fixed
The raw
@html contenttag was being used to render blog content, which poses a Cross-Site Scripting (XSS) vulnerability, even when the HTML is pre-sanitized due to DOM mutation-based bypasses.If an attacker can inject malicious payloads into the rendered Markdown (e.g. through a dompurify bypass or stored payload), the code will be executed in the user's browser, allowing unauthorized access, session hijacking, or defacement.
🛡️ Solution: How the fix addresses the vulnerability
Replaced the
{@html}rendering with a custom Svelte action,renderSanitizedHtml. This action parses the HTML safely utilizingisomorphic-dompurifyconfigured to return a directDocumentFragment({ RETURN_DOM_FRAGMENT: true }), preventing the string-to-DOM conversion typically exploited in mutation XSS. The fragment is then securely injected into the container viareplaceChildren(). Tests were added to ensure this action accurately purifies inputs while maintaining content updating dynamically.PR created automatically by Jules for task 8729800088616993268 started by @Sparkier