fix(security): prevent XSS in Mermaid WebView#678
Open
ex3ndr-bot wants to merge 1 commit intoslopus:mainfrom
Open
fix(security): prevent XSS in Mermaid WebView#678ex3ndr-bot wants to merge 1 commit intoslopus:mainfrom
ex3ndr-bot wants to merge 1 commit intoslopus:mainfrom
Conversation
Previously, mermaid diagram content was interpolated directly into the
WebView HTML template using ${props.content}, allowing XSS attacks with
payloads like </div><script>alert(1)</script>.
The fix:
- Pass content via JSON.stringify() which safely escapes all special chars
- Use mermaid.render() explicitly instead of startOnLoad to process the
JSON-parsed content
- Add error handling that also escapes error messages
This prevents HTML injection while maintaining full mermaid diagram
functionality.
Closes slopus#668
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
Fixes XSS vulnerability in the Mermaid diagram WebView renderer.
Problem
User/AI-supplied mermaid diagram content was interpolated directly into an HTML template without sanitisation:
A payload like
</div><img src=x onerror=alert(1)>could break out of the mermaid container and execute arbitrary JavaScript in the WebView context.Solution
Instead of HTML interpolation, the content is now:
JSON.stringify()which safely escapes all special charactersmermaid.render()explicitlyThis approach:
Testing
Tested with:
</div><script>alert(1)</script><,>,",')Closes #668