Summary
SiYuan versions 3.6.0 and below render unescaped package metadata (displayName, description) in the Bazaar marketplace, allowing malicious packages to inject arbitrary HTML and JavaScript.
In the vulnerable Electron configuration (nodeIntegration: true, contextIsolation: false), this cross-site scripting flaw escalates to full remote code execution on the user's operating system when they simply open the Bazaar page.
Affected context
The vulnerability appears in SiYuan's built-in Bazaar marketplace UI where package metadata is rendered into HTML views.
It becomes relevant when:
- SiYuan is running as an Electron desktop application with nodeIntegration enabled and contextIsolation disabled
- Bazaar content is loaded that includes untrusted metadata from third-party packages
- The application interpolates these metadata fields directly into the DOM using template literals without HTML escaping or sanitization
Any user who opens the Bazaar page in affected versions is exposed to scripts embedded in malicious package metadata.
Exploit preconditions
- Attack surface: SiYuan Bazaar marketplace interface in the Electron client
- Required access: Ability to publish or influence package metadata (displayName, description) that will be visible in the Bazaar; or control of a registry/source feeding these fields
- Victim interaction: The victim only needs to open or refresh the Bazaar tab; no clicks or confirmations are required
- Trigger point: Rendering of package metadata into HTML via template literals without escaping
- Why exploitation is possible: Untrusted text is treated as HTML/JS in a privileged Electron renderer process where nodeIntegration is enabled and contextIsolation is disabled, so injected scripts gain access to Node.js and OS APIs.
Why this happens
This issue stems from directly interpolating untrusted metadata fields into HTML templates without escaping or sanitization, a classic pattern of CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).
The Bazaar view builds DOM content using template literals, embedding package displayName and description as raw HTML.
In a browser-like environment without proper output encoding, attackers can smuggle <script> tags, event handlers, or other active content that executes when the DOM is rendered.
Because SiYuan's Electron configuration exposes Node.js in the renderer process and lacks isolation boundaries, the XSS is not confined to the UI but effectively becomes a code execution primitive on the host system.
Potential impact
- Execution of arbitrary JavaScript in the SiYuan renderer process
- Escalation from XSS to arbitrary OS-level command execution via Node.js APIs
- Installation of additional malware or persistence mechanisms on the victim machine
- Theft or modification of local SiYuan data and notes
- Exfiltration of local files accessible to the Electron app
- Use of the compromised host as a pivot for broader network compromise
General mitigation guidance
Effective mitigation generally focuses on output encoding, content sanitization, and reducing renderer privileges:
- Apply strict HTML escaping or context-appropriate output encoding to all untrusted metadata fields before inserting them into the DOM.
- Use a robust, well-maintained HTML sanitization library when rich text is truly needed, limiting or stripping active content (scripts, event handlers, inline JS).
- Prefer safe DOM construction APIs (e.g.,
textContent,innerText, or programmatic element creation) rather than string-based HTML templating for untrusted data. - In Electron, configure the application for defense in depth by disabling
nodeIntegrationin renderer processes and enablingcontextIsolation, using preload scripts and IPC to mediate privileged operations. - Treat external marketplace/registry data as untrusted by default, with validation and normalization layers between data retrieval and UI rendering.
How teams detect issues like this
Organizations can look for this class of issue using both automated and manual techniques:
- Static analysis: Rules that flag direct insertion of variables into HTML via template literals (
innerHTML,outerHTML, or similar sinks) without prior escaping or sanitization; Electron-specific checks for XSS sinks in renderers withnodeIntegration: true. - Code review: Security-focused reviews of UI components that render marketplace or plugin metadata, with attention to any bypass of templating engines that normally escape content.
- Policy enforcement: Internal guidelines that prohibit raw HTML rendering of untrusted data and require security-conscious Electron configuration (no Node.js in untrusted views).
- Dynamic testing: Automated or manual tests that inject benign XSS payload markers into package metadata fields and verify whether they execute when displayed in the Bazaar interface.

