Summary
SiYuan's README rendering pipeline failed to sanitize HTML in Markdown content and injected the result directly into the DOM via innerHTML.
A malicious package author could embed arbitrary JavaScript in their README, which executes when users view package details and, due to insecure Electron settings, can escalate to full remote code execution.
Affected context
The vulnerability appears in SiYuan's handling of package README files in versions 3.6.0 and below.
The backend uses lute.New() to render Markdown without enabling sanitization, allowing raw HTML to survive rendering.
The frontend then assigns this untrusted HTML to innerHTML in an Electron environment configured with nodeIntegration: true and contextIsolation: false.
When a user opens a malicious package's details view, the README content is rendered and executed in this privileged context.
Exploit preconditions
- Attack surface: SiYuan's package README viewer within the Electron-based desktop application.
- Required access: Ability to publish or otherwise influence package README content that a victim will later view.
- Victim interaction: A user must browse or click to view the package details for the malicious package.
- Trigger point: The backend renders the README with
lute.New()(withoutSetSanitize(true)), and the frontend injects the resulting HTML viainnerHTML. - Why exploitation is possible:
- Raw HTML in Markdown is not sanitized server-side.
- The client trusts the rendered HTML and inserts it directly into the DOM.
- Electron is configured with
nodeIntegration: trueandcontextIsolation: false, so injected JavaScript gains access to Node.js APIs and the underlying system.
Why this happens
At its core, this is a Cross-Site Scripting (CWE-79) issue stemming from insufficient output sanitization and risky browser integration.
The backend Markdown renderer (lute.New()) is used without enabling HTML sanitization (SetSanitize(true)), so user-controlled README content can include arbitrary HTML and script-related constructs.
On the frontend, this content is assigned to innerHTML without sanitization or a content security boundary, allowing any embedded script to execute.
In a standard browser this would already be XSS, but in this case, the Electron configuration (nodeIntegration: true, contextIsolation: false) conflates web and system privileges, turning a markup injection bug into a direct remote code execution pathway.
Potential impact
- Execution of arbitrary JavaScript whenever a user views a malicious package's README.
- Full remote code execution on the user's machine via Node.js APIs in Electron.
- Exfiltration of local knowledge data, configuration files, or authentication secrets handled by the app.
- Installation of additional malware or persistence mechanisms on the host system.
- Lateral movement by accessing other local resources or network services reachable from the victim's machine.
- Impersonation of the user within the application and tampering with stored notes or knowledge bases.
General mitigation guidance
Effective mitigation combines robust HTML sanitization with safer Electron isolation defaults and defensive rendering patterns:
- Prefer Markdown renderers configured in a "safe HTML" mode, or explicitly enable sanitization options so that dangerous tags, attributes, and protocols are stripped from README content.
- Treat all package metadata and documentation as untrusted; apply a well-maintained HTML sanitizer on the final HTML, not just the Markdown, before it reaches the UI.
- Avoid directly assigning untrusted HTML to
innerHTML; instead, use templating mechanisms that encode content by default, only whitelisting specific markup if truly required. - In Electron, design the application around
contextIsolation: trueandnodeIntegration: false, delegating privileged operations to carefully scoped preload scripts or IPC handlers. - Apply least-privilege principles for renderer processes: limit the available APIs and file system access so that, even if a rendering bug appears, the impact is constrained.
- Document and enforce a security model where package content cannot directly invoke privileged APIs, regardless of the UI surface it flows through.
How teams detect issues like this
Identifying similar vulnerabilities involves both code-centric and configuration-centric checks:
- Static analysis and linting:
- Search for
innerHTML,outerHTML, or equivalent DOM sinks fed from variables that originate in network, file, or package content without passing through a sanitizer. - Flag uses of Markdown/HTML rendering libraries where sanitization flags (such as
SetSanitize(true)or equivalents) are not set while processing untrusted content. - Configuration review:
- Audit Electron configuration for
nodeIntegration: true,contextIsolation: false, or other settings that expose Node.js in regular web contexts. - Review preload scripts and IPC handlers to ensure they do not expose overly broad system capabilities to rendered web content.
- Code review patterns:
- Trace data flows from package repositories or registries into UI components; highlight any path that leads to raw HTML rendering.
- Check for centralized sanitization utilities; if they are absent or inconsistently used, treat it as a sign of elevated risk across the codebase.
- Automated tooling:
- Incorporate SAST tools that recognize XSS sinks and insecure Electron settings into CI pipelines.
- Add custom checks or policies that block merges when new uses of dangerous DOM APIs or insecure Electron flags are introduced.

