Summary
SiYuan's Electron desktop client prior to 3.6.4 contains a stored cross-site scripting (XSS) vulnerability where unescaped table caption content is rendered as HTML in the desktop app.
In vulnerable configurations with nodeIntegration enabled and contextIsolation disabled, an attacker who can sync a malicious note into a victim's workspace may execute arbitrary JavaScript with access to Node.js APIs, effectively achieving remote code execution on the victim's machine.
Affected context
The issue occurs in the SiYuan Electron desktop application when:
- Notes are synced or shared across users or devices.
- Table caption content in a note is stored without proper escaping.
- The desktop renderer later injects this caption content directly into the DOM as HTML.
- The Electron environment is configured with nodeIntegration enabled and contextIsolation disabled, exposing Node.js APIs to renderer JavaScript.
Under these conditions, any synced note containing crafted table caption content can become an execution point for attacker-supplied script when a victim opens the note.
Exploit preconditions
- Attack surface: SiYuan Electron desktop client rendering synced or imported notes.
- Required access: Ability to introduce or modify note content that will be synced into a victim's workspace (e.g., shared workspace, compromised sync source, or imported notes).
- Trigger point: Victim synchronizes the workspace and opens or renders the malicious note containing a crafted table caption.
- Why exploitation is possible: Caption text is stored without safe encoding and later rendered as raw HTML/JavaScript inside an Electron renderer that has powerful Node.js APIs exposed due to nodeIntegration being enabled and contextIsolation being disabled.
Why this happens
The root cause is improper neutralization of user-controlled content before it is inserted into an HTML context, mapping to CWE-79: Improper Neutralization of Input During Web Page Generation (XSS).
Specifically:
- Table caption content from notes is treated as trusted and stored without robust escaping.
- During rendering, this content is injected unescaped into the DOM, creating a persistent XSS sink.
In a standard browser this would "only" be stored XSS, but in this Electron-based desktop client, nodeIntegration and disabled contextIsolation bridge the web and system boundaries, allowing injected JavaScript to reach Node.js APIs.
This combination effectively escalates a traditional XSS bug into a code execution flaw on the underlying operating system, aligning with the downstream impact related to CWE-94: Code Injection through scriptable host interfaces.
Potential impact
- Execution of arbitrary JavaScript in the SiYuan Electron renderer.
- Remote code execution on the victim's machine via Node.js APIs (spawning processes, reading/writing files, etc.).
- Theft or manipulation of locally stored notes and other knowledge base data.
- Exfiltration of authentication tokens, API keys, or other secrets stored or accessible via the desktop client.
- Lateral movement by using the compromised machine to attack other applications or network resources.
General mitigation guidance
Effective mitigation focuses on breaking the chain from user content to privileged script execution:
- Treat all note content, including table captions, as untrusted and apply strict output encoding/escaping before insertion into the DOM.
- Use safe, well-maintained HTML sanitization libraries to strip or neutralize script tags, event handlers, and dangerous URL schemes from rendered content.
- Prefer content-rendering strategies that separate data from HTML structure (e.g., text-only insertion APIs or virtual DOM frameworks that handle escaping by default).
- Harden the Electron security model by disabling nodeIntegration in renderers and enabling contextIsolation wherever possible, limiting direct access to Node.js from page JavaScript.
- Apply the principle of least privilege to any IPC bridge between renderer and main process, exposing only narrowly scoped, validated operations.
How teams detect issues like this
Detection can rely on a mix of code-centric and behavior-centric approaches:
- Static analysis and linting rules that flag direct injection of user-controlled strings into innerHTML, outerHTML, or similar DOM sinks.
- Code review checklists emphasizing safe rendering of markdown/HTML content, especially around captions, titles, and other rich-text fields.
- Automated scanning of the rendering code for insecure Electron configurations (nodeIntegration: true, contextIsolation: false) combined with untrusted content rendering.
- Dynamic or fuzz testing using crafted note content to validate that scripts and event handlers are not executed when notes are rendered.
- Integration of secure coding policies in CI pipelines to prevent reintroducing unsafe DOM APIs or loosening Electron security settings without explicit review.

