Summary
SiYuan versions prior to 3.5.4 contain a stored Cross-Site Scripting (XSS) vulnerability in the block icon attribute, settable via the /api/attr/setBlockAttrs API.
Malicious HTML attributes injected into this field are later rendered without proper sanitization, enabling stored XSS in the browser and, in the desktop environment, possible remote code execution (RCE) via dynamic icon handling.
Affected context
The vulnerability appears in SiYuan's handling of block attributes, specifically the icon attribute used by the dynamic icon feature.
It affects deployments where:
- Users or integrations can call
/api/attr/setBlockAttrsto update block attributes, and - The resulting icon attributes are later rendered into an HTML context without strict sanitization, and
- In the desktop application, the rendering environment can bridge from script execution to host-level code execution.
Under these conditions, attacker-controlled icon attributes may persist in user content and execute whenever the affected block is viewed.
Exploit preconditions
- Attack surface: SiYuan instances that expose or use the
/api/attr/setBlockAttrsAPI for updating block attributes. - Required access: Ability to create or modify content blocks or invoke the attribute-setting API with attacker-controlled values; this may require a valid user session or compromised integration.
- Trigger point: Viewing or rendering a block whose
iconattribute contains malicious HTML attributes in the dynamic icon feature. - Why exploitation is possible: The
iconattribute is treated as partially trusted and inserted into an HTML context without robust escaping or sanitization of attribute values, allowing script-capable attributes or constructs to execute and, in the desktop environment, to escalate to RCE.
Why this happens
The issue stems from treating a user-controlled attribute (icon) as safe for direct insertion into the DOM or equivalent rendering context.
This maps to CWE-79: Improper Neutralization of Input During Web Page Generation (XSS) because attacker-controlled data is rendered without sufficient encoding or sanitization.
In the desktop setting, the executed script can gain access to APIs or integrations that allow running arbitrary code, effectively crossing into CWE-94: Improper Control of Generation of Code, as untrusted content indirectly controls the generation or execution of native code.
The previous fix for issue #15970 did not fully constrain what could be injected into the icon attributes, leaving a bypass path that still allowed dangerous attribute patterns to reach the rendering layer.
Potential impact
- Persistent execution of attacker-controlled JavaScript in affected SiYuan sessions (stored XSS).
- Account takeover within the application context via session hijacking or credential harvesting.
- Unauthorized access to or manipulation of stored notes and knowledge-base content.
- Execution of arbitrary code in the SiYuan desktop environment, potentially compromising the host system.
- Use of the compromised desktop client as a pivot point for further lateral movement or data exfiltration.
General mitigation guidance
Effective mitigation focuses on strict separation between data and executable content in UI rendering:
- Treat all user-controlled attributes, including
icon, as untrusted and apply context-appropriate encoding (e.g., HTML attribute encoding) before insertion into DOM or template output. - Restrict dynamic icon functionality to a safe, well-defined subset of allowed values (e.g., whitelisted icon identifiers rather than raw HTML or attributes).
- Introduce centralized sanitization routines for any attribute that can impact markup, ensuring that script-like constructs, event handlers, and protocol handlers are stripped or rejected.
- Reduce the privileges of the desktop runtime so that even if script executes, access to host-level code execution paths is minimized.
- Favor secure-by-default UI components that do not rely on raw HTML injection for customization.
How teams detect issues like this
Detection can leverage a combination of code-level and behavior-level techniques:
- Use static analysis or linters to flag patterns where user-controlled values are interpolated into HTML attributes or innerHTML without escaping.
- During code review, look for API endpoints such as
/api/attr/setBlockAttrsthat accept free-form strings and trace their flow into rendering code or templating engines. - Define security tests that attempt to store representative XSS payloads in icon or similar attributes and then exercise UI paths that render them, checking for script execution.
- Apply content security policies (CSP) in web contexts and monitor violation reports, which can highlight unexpected inline script execution.
- Incorporate automated dependency and configuration checks that enforce a rule: no feature should require raw HTML from untrusted sources for basic customization.

