/

CVE-2026-39846

Severity:

CRITICAL RISK

(9.0)

Stored XSS in SiYuan Electron Desktop Client

CVE-2026-39846

Analyzed

Vulnerability type

Category:

Stored Cross-Site Scripting (XSS)

CWE:

CWE-79, CWE-94

Impact:

Remote Code Execution via Stored XSS in Desktop Client

Severity:

CRITICAL RISK

(9.0)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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.

Sources

SourceLink
github.comgithub.com/siyuan-note/siyuan/security/advisories/GHSA-phhp-9rm9-6gr2

Frequently asked

questions

It is remotely exploitable in the sense that an attacker only needs a path to sync or import a malicious note into the victim's workspace; they do not require local shell or direct file system access on the victim's machine.

The attacker needs the ability to influence note content that the victim's desktop client will render—through a shared workspace, compromised sync channel, or a crafted note that the victim imports. No direct access to the victim's machine is required beyond this content injection path.

The safest pattern is to ensure robust output encoding and/or sanitization for all user-controlled content before rendering to HTML, combined with hardened Electron settings: disable nodeIntegration, enable contextIsolation, and strictly control any IPC bridges so that renderer scripts cannot directly access system-level APIs.

Adopt a default-deny approach to rendering rich content: treat all note data as untrusted, use standard sanitization libraries, avoid direct use of innerHTML with user content, and enforce secure Electron configurations by policy. Complement this with automated checks in CI/CD and regular security-focused code reviews of all rendering and synchronization logic.

Find out what's already
exploitable in your codebase.