/

CVE-2026-40322

Severity:

CRITICAL RISK

(9.0)

Cross-Site Scripting (XSS) in SiYuan Desktop

CVE-2026-40322

Analyzed

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79, CWE-94

Impact:

Arbitrary Code Execution on Desktop via Stored XSS

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 versions 3.6.3 and below render Mermaid diagrams with a permissive security level and inject the resulting SVG into the DOM using innerHTML, allowing attacker-controlled javascript: URLs to persist in rendered output.

On Electron-based desktop builds with nodeIntegration enabled and contextIsolation disabled, this stored XSS can escalate to arbitrary code execution when a victim opens a malicious note and interacts with the rendered diagram.

Affected context

The vulnerability occurs in SiYuan's rendering pipeline for Mermaid diagrams inside notes, where:

  • Mermaid is configured with securityLevel set to loose
  • Generated SVG content is inserted into the document using innerHTML
  • On desktop builds, the application runs in an Electron environment with nodeIntegration enabled and contextIsolation disabled

The issue becomes relevant when users open or sync notes that may contain untrusted Mermaid code blocks, such as from shared workspaces, synced folders, or imported documents.

Exploit preconditions

  • Attack surface: Mermaid diagram rendering in SiYuan notes (preview/rendered mode).
  • Required access: Ability to create, edit, sync, or otherwise cause a note to contain attacker-controlled Mermaid code (e.g., shared workspace, imported notes, compromised sync source).
  • User interaction: A victim must open the note so it renders, and on desktop builds click or interact with the malicious diagram node that contains a javascript: URL.
  • Trigger point: Rendering of Mermaid diagrams with securityLevel = "loose" and injection of the resulting SVG via innerHTML into a privileged Electron renderer.
  • Why exploitation is possible: The permissive Mermaid configuration allows unsafe links/attributes, and the Electron window is configured with nodeIntegration enabled and contextIsolation disabled, so JavaScript execution can directly access Node.js APIs and the host environment.

Why this happens

The core issue is a combination of unsafe content rendering and overly permissive runtime configuration:

  • Mermaid is configured with securityLevel: "loose", which tolerates potentially dangerous javascript: URLs and other untrusted attributes in diagram output.
  • The resulting SVG is injected into the DOM using innerHTML, a pattern that directly interprets attacker-controlled markup and script-related attributes (mapping to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting)).
  • In the Electron desktop environment, windows are created with nodeIntegration enabled and contextIsolation disabled, violating isolation best practices and allowing browser JavaScript to reach Node.js APIs, effectively bridging a web XSS into system-level code execution (connected to CWE-94: Improper Control of Generation of Code when arbitrary script gains access to a code-capable environment).

Abstractly, this is an unsafe mixing of untrusted markup with privileged renderer capabilities, without applying strict sanitization or containment.

Potential impact

  • Execution of arbitrary JavaScript in the SiYuan renderer context when a malicious note is opened.
  • Escalation to arbitrary code execution on the victim's machine in desktop/Electron builds via Node.js APIs.
  • Reading, modifying, or exfiltrating note contents, including sensitive personal knowledge or private documents.
  • Tampering with application configuration or local files accessible to the Electron process.
  • Use of the compromised client as a foothold for broader system compromise, depending on OS-level protections and user privileges.

General mitigation guidance

Effective mitigation focuses on both safe content handling and hardened desktop runtime configuration:

  • Prefer stricter Mermaid configurations (e.g., secure securityLevel settings) that disallow javascript: URLs and unsafe link targets.
  • Avoid inserting diagram-rendered SVG or HTML directly with innerHTML; instead, use APIs or libraries that sanitize or safely construct DOM nodes.
  • Introduce a robust sanitization layer for all rendered rich-content blocks (including Markdown/HTML/Mermaid) that strips dangerous protocols, event handlers, and script-capable attributes before DOM insertion.
  • In Electron environments, follow secure-by-default practices:
  • Disable nodeIntegration in renderer windows unless absolutely necessary.
  • Enable contextIsolation so untrusted page scripts cannot directly access privileged objects.
  • Use preload scripts and explicit IPC channels to mediate any required privileged operations.
  • Treat synced and imported notes as untrusted content and render them within the same hardened, sandboxed pipeline as remotely sourced data.

How teams detect issues like this

Detection can leverage a mix of code-level and configuration-level reviews:

  • Static analysis and linting:
  • Search for innerHTML, outerHTML, or similar APIs used with content derived from user-editable notes or imported files, especially in rendering pipelines.
  • Flag uses of Mermaid configuration where securityLevel is set to "loose" or other permissive modes.
  • Identify Electron window creation with nodeIntegration: true or contextIsolation: false, especially for windows that load user-controlled or rich text content.
  • Code review patterns:
  • Review all Markdown/diagram rendering features for direct DOM injection, protocol handling for links, and lack of sanitization.
  • Check that all content transformers (Markdown → HTML, Mermaid → SVG, etc.) enforce safe default configurations and do not rely on client-side trust.
  • Policy and automated checks:
  • Enforce project policies that ban dangerous Electron flags in production builds unless tightly sandboxed.
  • Integrate security-focused linters or SAST tools into CI to surface insecure DOM sinks and unsafe Electron practices.
  • Log and, where feasible, monitor usage of high-risk rendering paths in test builds to ensure no unsafe patterns are reintroduced.

Sources

SourceLink
github.comgithub.com/siyuan-note/siyuan/releases/tag/v3.6.4
github.comgithub.com/siyuan-note/siyuan/security/advisories/GHSA-x63q-3rcj-hhp5

Frequently asked

questions

It can be remotely triggered in practice if an attacker can cause a victim to open a note containing malicious Mermaid code, for example via shared workspaces, synced documents, or imported files. The actual exploit occurs locally when the note is rendered in the desktop application.

The attacker needs the ability to influence the content of a note that the victim will open, such as creating or modifying a note in a shared or synchronized environment. No direct access to the victim's machine is required beyond that.

The safest pattern is to combine strict content sanitization with secure runtime configuration: use secure Mermaid settings, avoid innerHTML for user-controlled content, sanitize all rendered markup, and configure Electron windows with nodeIntegration disabled and contextIsolation enabled, exposing only minimal, vetted capabilities via IPC.

Treat all note content and rich text as untrusted, even if it appears local; route it through a dedicated sanitization and rendering pipeline; avoid direct DOM HTML injection; and design Electron or webview environments with strict isolation and least-privilege access to system resources.

Find out what's already
exploitable in your codebase.