Summary
A stored cross-site scripting (XSS) vulnerability in SiYuan's Attribute View allows attacker-controlled URLs to be injected into an unescaped <img src="..."> attribute.
When a victim opens a Gallery or Kanban view with "Cover From -> Asset Field" enabled, malicious JavaScript can execute, and in the Electron desktop client this can escalate to arbitrary OS command execution under the victim's account.
Affected context
The vulnerability occurs in SiYuan's Attribute View when using Gallery or Kanban views that derive cover images from an "Asset Field" (mAsse field).
In affected configurations, the application:
- Accepts arbitrary http(s) URLs without file extensions as image sources
- Stores the value in a coverURL field
- Injects the raw value directly into an <img src="..."> attribute without HTML escaping or URL validation
The risk is highest in the Electron desktop client, where nodeIntegration is enabled and contextIsolation is disabled, allowing XSS to break out of the browser sandbox and interact with the underlying OS.
Exploit preconditions
- Attack surface: SiYuan Attribute View items rendered in Gallery or Kanban views with "Cover From -> Asset Field" enabled.
- Required access: Ability to create or modify an Attribute View mAsse/asset field value that will later be viewed by another user (or by the same user in a different session).
- Trigger point: A victim opens a Gallery or Kanban view that renders the attacker-controlled asset field as a cover image.
- Why exploitation is possible: The application treats untrusted text as a trusted image URL, omits output encoding, and interpolates it directly into the src attribute of an img tag. In the Electron client, the rendering environment is further weakened by nodeIntegration being enabled and contextIsolation being disabled, so injected JavaScript gains access to Node.js APIs and system-level capabilities.
Why this happens
The core bug is a classic stored XSS pattern where user-controlled data is rendered into HTML without proper escaping or validation.
SiYuan accepts arbitrary http(s) URLs as "image" sources, stores them as coverURL, and inserts them into <img src="..."> without HTML encoding or protocol/format restrictions.
This directly maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting), where script execution occurs because untrusted data is embedded into HTML context unsafely.
In the Electron desktop client, this XSS escalates due to insecure web preferences (nodeIntegration enabled, contextIsolation disabled), which is aligned with the risk profile described in CWE-94: Improper Control of Generation of Code, as attacker-supplied script effectively controls runtime behavior and can invoke OS-level operations via Node.js APIs.
Potential impact
- Execution of arbitrary JavaScript in the context of the SiYuan UI.
- Theft or manipulation of user data managed within SiYuan.
- Arbitrary OS command execution in the Electron desktop client via Node.js integration.
- Installation of additional malware or persistence mechanisms on the victim's machine.
- Use of the victim's workstation as a foothold for broader lateral movement within a network.
General mitigation guidance
Effective mitigation focuses on eliminating the unsafe rendering pattern and hardening the execution environment:
- Apply strict output encoding for any user-controlled data rendered into HTML attributes (e.g., proper HTML attribute escaping for src values).
- Enforce strong validation on "image" fields so only well-formed URLs with safe schemes and expected formats are accepted; consider whitelisting known-safe schemes and media types.
- Treat all content derived from user-editable notes, attributes, or metadata as untrusted by default, even if it "looks" like a URL or filename.
- In Electron or similar desktop environments, prefer secure-by-default settings: disable nodeIntegration where feasible, enable contextIsolation, and restrict access to powerful APIs behind well-defined IPC layers.
- Apply least-privilege principles to the desktop application's filesystem and process capabilities to reduce the blast radius if rendering bugs occur.
How teams detect issues like this
Detection usually combines code-centric and behavior-centric techniques:
- Static analysis: Search for string concatenation or template interpolation where user or document fields are placed directly into HTML attributes (especially src, href, on* event handlers) without an encoding or sanitization step.
- Code review: Flag any rendering paths where "asset", "cover", "URL", or similar fields are used to construct HTML elements; reviewers should confirm the presence of encoding, URL validation, and protocol checks.
- Policy enforcement: Introduce linting or CI checks that prohibit dangerous Electron settings (nodeIntegration: true, contextIsolation: false) unless accompanied by documented threat modeling and isolation layers.
- Dynamic testing: Use browser or Electron-focused security testing tools to scan for stored XSS by injecting test payloads into note attributes and verifying whether they are reflected into the DOM without escaping.

