Summary
SiYuan desktop prior to 3.6.5 contains a DOM-based cross-site scripting vulnerability in its notification system, where user-controlled messages are rendered as raw HTML inside an Electron renderer.
Because the Electron windows run with nodeIntegration enabled, contextIsolation disabled, and webSecurity off, injected JavaScript can directly access Node APIs and escalate from XSS to arbitrary desktop code execution when crafted messages reach the notification sink.
Affected context
This issue affects the SiYuan desktop application where notifications are rendered in an Electron renderer process.
The vulnerable path is triggered when the backend endpoint POST /api/notification/pushMsg accepts a msg parameter, forwards it through the broadcast layer, and the frontend inserts it into the DOM via insertAdjacentHTML(...) in message.ts.
The risk is specific to desktop builds configured with nodeIntegration: true, contextIsolation: false, and webSecurity: false in main.js, which together allow JavaScript in the notification context to reach Node.js APIs.
Exploit preconditions
- Attack surface: The
/api/notification/pushMsgHTTP endpoint used to deliver notifications to desktop clients. - Required access: Ability to send or influence requests that set the
msgfield, either directly or via an upstream feature that calls this API. - Trigger point: Rendering of the notification in the Electron renderer, where
msgis inserted into the DOM usinginsertAdjacentHTML(...). - Why exploitation is possible: The application treats
msgas trusted HTML, performing no encoding or sanitization, and renders it in a context where Electron is configured with full Node integration and disabled isolation, enabling script execution to bridge from the browser environment into the Node.js runtime.
Why this happens
The core issue is untrusted HTML content being directly injected into the DOM in a privileged renderer without sanitization or contextual encoding.
The use of insertAdjacentHTML(...) on a user-controlled msg value embodies CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting), because it allows arbitrary script execution in the renderer.
In the Electron environment, this DOM XSS is amplified: nodeIntegration: true, contextIsolation: false, and webSecurity: false merge the web and Node.js contexts, so injected scripts can invoke Node APIs, spawn processes, and interact with the host OS.
When an attacker-controlled script can drive OS-level commands via Node facilities, the behavior aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command, as untrusted input is effectively channeled into command execution through the Node bridge.
Potential impact
- Execution of arbitrary JavaScript within the SiYuan desktop renderer context.
- Direct access to Node.js APIs from injected scripts, including file system and process management capabilities.
- Arbitrary code execution on the desktop system running SiYuan, subject to the application's privileges.
- Reading, modifying, or exfiltrating local knowledge base data managed by the application.
- Use of the compromised application as a foothold for broader system compromise or lateral movement in the user's environment.
General mitigation guidance
Effective mitigation focuses on both output handling and Electron security posture:
- Neutralize untrusted HTML in notifications:
- Treat notification messages as plain text by default and apply strict output encoding before inserting into the DOM.
- Where rich formatting is required, restrict to a whitelist of safe tags and attributes using a robust HTML sanitizer, avoiding script execution contexts entirely.
- Avoid APIs such as
insertAdjacentHTML(...)andinnerHTMLfor untrusted data; prefer safe DOM construction (e.g.,textContent,createTextNode) and explicit element creation.
- Harden the Electron environment:
- Disable
nodeIntegrationin renderer windows that display any remotely or indirectly supplied content. - Enable
contextIsolationso that web content runs in a separate JavaScript context from privileged APIs. - Re-enable
webSecurityto enforce origin and content restrictions wherever feasible. - Route all privileged operations through a minimal, well-audited IPC layer that validates and constrains messages from the renderer.
- Reduce trust boundaries around notifications:
- Treat any data reaching notification sinks as untrusted, regardless of internal origin.
- Apply centralized validation and encoding at the boundary where messages cross into the UI layer, rather than relying on upstream callers.
How teams detect issues like this
Detection can leverage both code-level and behavioral approaches:
- Static analysis and linting:
- Configure rules to flag usage of
innerHTML,insertAdjacentHTML, and similar sinks when they receive variables originating from external inputs or internal messaging APIs. - Add Electron-specific checks for windows created with
nodeIntegration: true,contextIsolation: false, orwebSecurity: false, especially when those windows display dynamic content. - Use taint analysis where available to trace the flow of data from HTTP endpoints like
/api/notification/pushMsginto DOM sinks in renderer code.
- Code review patterns:
- During review, scrutinize all notification and messaging features for direct DOM insertion patterns and confirm that outputs are encoded according to context.
- Verify that any bridge between backend notifications and frontend renderers applies sanitization in a single, consistent layer rather than piecemeal.
- Policy and tooling:
- Establish internal guidelines that forbid enabling Node integration for windows rendering content influenced by user or network data.
- Integrate automated checks into CI/CD pipelines that enforce Electron security baselines and flag deviations for manual review.

