Summary
Open WebUI's Markdown preview feature renders Mermaid diagrams with a loose security level and injects the resulting SVG into the DOM using innerHTML.
If an attacker can supply crafted Mermaid content in Markdown files, this can lead to JavaScript execution in the victim's browser under the Open WebUI origin.
Affected context
This vulnerability appears in Open WebUI instances that:
- Allow users to upload, store, or edit Markdown content
- Render Mermaid diagram blocks in the file preview panel
- Use Mermaid with
securityLevel: 'loose'and insert generated SVG viainnerHTML
It is relevant wherever Markdown content can be influenced by untrusted or semi-trusted users and is later previewed by other users in the web interface.
Exploit preconditions
- Attack surface: Web UI file preview panel that displays Markdown with Mermaid blocks.
- Required access: Ability to create or modify Markdown files rendered by Open WebUI (e.g., upload, sync, or edit documents).
- Trigger point: A victim opens the Markdown file in the preview panel, causing Mermaid to render the attacker-controlled diagram.
- Why exploitation is possible: Mermaid is configured with
securityLevel: 'loose', and the resulting SVG is injected viainnerHTMLwithout sufficient sanitization, allowing script-capable markup to execute in the victim's browser.
Why this happens
The underlying issue is a cross-site scripting pattern where untrusted content is rendered into the browser and inserted into the DOM using APIs that interpret HTML.
By configuring Mermaid with a loose security level and combining it with innerHTML, the application treats attacker-controlled diagram definitions as trusted markup.
This maps to CWE-79 (Improper Neutralization of Input During Web Page Generation), where failure to correctly sanitize or encode user-supplied content allows script execution in the client.
Potential impact
- Attacker-controlled JavaScript may execute in the victim's browser.
- Session data and authentication tokens could be accessed or exfiltrated.
- User actions within Open WebUI can be hijacked or performed on the user's behalf.
- Malicious scripts may alter displayed content, conduct phishing, or pivot into broader browser-based attacks.
General mitigation guidance
Effective mitigation focuses on reducing trust in rendered content and hardening the rendering pipeline:
- Use stricter security settings for diagram-rendering libraries (e.g., disallow script-capable constructs).
- Avoid inserting library output into the DOM via
innerHTMLor similar APIs; prefer safe DOM construction that treats content as data, not HTML. - Apply robust HTML and SVG sanitization to any content derived from user-controlled sources before rendering.
- Limit who can author or upload Markdown that will be previewed by others, and apply least-privilege controls around content features that can affect rendering.
How teams detect issues like this
Organizations can detect similar vulnerabilities by:
- Running static analysis or linters that flag
innerHTML,outerHTML, and other sink APIs when used with untrusted data. - Reviewing code paths that integrate Markdown, diagram libraries, or other rich text renderers for unsafe configurations and missing sanitization.
- Establishing security review policies for UI features that transform user content into HTML, SVG, or scriptable markup.
- Using automated application security testing tools to probe Markdown and diagram-rendering features for XSS behaviors.

