Summary
SiYuan versions 3.6.0 and below contain a stored cross-site scripting vulnerability in the mobile file tree, where notebook names are rendered as HTML without escaping when processed from WebSocket rename events.
An authenticated user who can rename notebooks can inject arbitrary HTML/JavaScript that executes on mobile and narrow-window Electron clients, and due to permissive Electron settings this can escalate to full remote code execution via Node.js APIs.
Affected context
The vulnerability occurs in the mobile file tree rendering logic (MobileFiles.ts) of SiYuan when notebook names are updated over WebSocket (renamenotebook events).
Instead of safely escaping user-controlled notebook names, the mobile client inserts them directly using innerHTML.
While the traditional desktop file tree (Files.ts) applies escapeHtml(), the mobile layout (also used in desktop when the window is narrow) does not, creating a divergence where the same logical data path is handled securely in one view and insecurely in another.
Exploit preconditions
- Attack surface: Mobile UI and desktop Electron app when using the mobile layout (narrow window view of the file tree).
- Required access: Authenticated access to a SiYuan workspace with permission to rename notebooks.
- Trigger point: A victim user opens the file tree in the vulnerable mobile layout or in the Electron desktop app in a narrow window, causing the malicious notebook name to be rendered via
innerHTML. - Why exploitation is possible: The mobile file tree renderer uses
innerHTMLdirectly on notebook names received from WebSocket events without HTML escaping, allowing notebook names to embed script or HTML payloads. In the Electron context configured withnodeIntegration: trueandcontextIsolation: false, any executed JavaScript gains full Node.js privileges.
Why this happens
This vulnerability stems from inconsistent output encoding between different UI components handling the same data.
The desktop file tree correctly applies escapeHtml() before rendering notebook names, but the mobile file tree uses innerHTML with unescaped input coming from WebSocket renamenotebook events.
Conceptually, this maps to CWE-79: Improper Neutralization of Input During Web Page Generation, where user-controllable data is incorporated into an HTML context without appropriate escaping.
In a browser-only environment this would "only" be stored XSS, but because SiYuan's Electron configuration exposes Node.js APIs to renderer JavaScript, the XSS is effectively an RCE primitive.
Potential impact
- Execution of arbitrary JavaScript in the context of affected mobile and Electron clients.
- Full remote code execution on desktops via Node.js APIs (file system access, command execution, process manipulation).
- Theft or modification of notes, notebooks, and other user data stored by SiYuan.
- Credential/session token theft or impersonation within the application.
- Lateral movement if compromised hosts have access to other sensitive resources.
General mitigation guidance
Effective mitigation focuses on consistent output encoding and hardening the runtime environment:
- Apply strict HTML escaping or context-appropriate encoding to all user-controllable data (such as notebook names) before inserting into the DOM, regardless of view (mobile, desktop, narrow layout).
- Avoid using
innerHTMLfor dynamic content where possible; prefer text-oriented APIs (e.g.,textContent) or templating systems that escape output by default. - Enforce a single, shared rendering utility that always escapes notebook names so that both mobile and desktop paths use the same safe behavior.
- In Electron environments, reduce the impact of any UI injection by disabling
nodeIntegration, enablingcontextIsolation, and exposing only minimal, audited functionality via preload scripts or IPC bridges. - Adopt a least-privilege design for renderer processes so that even if a script executes unexpectedly, direct access to Node.js and the underlying OS is constrained.
How teams detect issues like this
To detect and prevent similar issues, teams can:
- Use static analysis rules to flag direct assignments to
innerHTMLand similar DOM sinks when the source is user-controllable or originates from WebSocket/event data. - Include code review checklists that explicitly require context-appropriate escaping for all rendered user data, and that scrutinize differences between mobile and desktop view implementations.
- Implement linting or custom ESLint rules that disallow unescaped DOM injection and require use of safe rendering helpers.
- Conduct security testing (including XSS-focused tests) on Electron views, particularly where web technologies interact with Node.js, to identify paths where unsafe rendering can escalate to RCE.

