Summary
SiYuan before v3.7.2 contains a stored cross-site scripting vulnerability in the rendering of Gallery and Kanban cover images, where a title-img attribute value is interpolated into a style attribute without proper escaping.
Editors can inject malicious handlers that execute arbitrary code in the Electron renderer with full Node.js access when other users open the affected documents, turning a client-side XSS into a high-impact desktop compromise.
SiYuan before v3.7.2 contains a stored cross-site scripting vulnerability in the rendering of Gallery and Kanban cover images, where a title-img attribute value is interpolated into a style attribute without proper escaping.
Editors can inject malicious handlers that execute arbitrary code in the Electron renderer with full Node.js access when other users open the affected documents, turning a client-side XSS into a high-impact desktop compromise.
Affected context
The issue arises in SiYuan's desktop environment when rendering documents that use Gallery or Kanban blocks with cover images.
The vulnerability is present where the title-img Individual Attribute List value is used to build inline style attributes without robust HTML and JavaScript escaping.
It becomes relevant in contexts where multiple users share or sync documents and at least one user has editor-level permissions to modify block attributes.
The issue arises in SiYuan's desktop environment when rendering documents that use Gallery or Kanban blocks with cover images.
The vulnerability is present where the title-img Individual Attribute List value is used to build inline style attributes without robust HTML and JavaScript escaping.
It becomes relevant in contexts where multiple users share or sync documents and at least one user has editor-level permissions to modify block attributes.
Exploit preconditions
- Attack surface: Document rendering in the SiYuan Electron-based desktop application
- Required access: Editor permissions on a document or template that supports Gallery and Kanban cover images
- Trigger point: Victim opens or previews an affected document, causing the unescaped attribute interpolation to render in the UI
- Why exploitation is possible: The title-img attribute is injected into a style attribute without proper sanitization, enabling injection of script-like constructs (such as onload handlers) that execute in a privileged renderer with Node.js access
- Attack surface: Document rendering in the SiYuan Electron-based desktop application
- Required access: Editor permissions on a document or template that supports Gallery and Kanban cover images
- Trigger point: Victim opens or previews an affected document, causing the unescaped attribute interpolation to render in the UI
- Why exploitation is possible: The title-img attribute is injected into a style attribute without proper sanitization, enabling injection of script-like constructs (such as onload handlers) that execute in a privileged renderer with Node.js access
Why this happens
The root cause is improper neutralization of user-controlled data before it is injected into HTML attributes, mapping directly to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).
SiYuan's rendering path for Gallery and Kanban cover images trusts the title-img Individual Attribute List value and interpolates it directly into a style attribute.
Without a dedicated escaping and validation layer for attribute values, an attacker can craft input that transforms intended presentation data into executable script, which in Electron-based environments can escalate to arbitrary system-level code execution.
The root cause is improper neutralization of user-controlled data before it is injected into HTML attributes, mapping directly to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).
SiYuan's rendering path for Gallery and Kanban cover images trusts the title-img Individual Attribute List value and interpolates it directly into a style attribute.
Without a dedicated escaping and validation layer for attribute values, an attacker can craft input that transforms intended presentation data into executable script, which in Electron-based environments can escalate to arbitrary system-level code execution.
Potential impact
- Execution of arbitrary JavaScript in the Electron renderer
- Arbitrary Node.js code execution with the privileges of the SiYuan desktop user
- Theft or corruption of local notes and configuration data
- Access to local filesystem resources via Node.js APIs
- Potential installation of malware or backdoors on the victim's machine
- Execution of arbitrary JavaScript in the Electron renderer
- Arbitrary Node.js code execution with the privileges of the SiYuan desktop user
- Theft or corruption of local notes and configuration data
- Access to local filesystem resources via Node.js APIs
- Potential installation of malware or backdoors on the victim's machine
General mitigation guidance
Effective mitigation focuses on treating all document attributes as untrusted input and enforcing strict output encoding before injecting them into HTML or CSS contexts.
Common defensive patterns include:
- Applying context-aware escaping for style and HTML attributes, ensuring that special characters, URL fragments, and script-like payloads are neutralized
- Introducing a validation layer that restricts title-img values to safe formats (e.g., constrained URLs or predefined tokens instead of raw strings)
- Designing rendering components to avoid mixing executable contexts with user-controlled data, especially in Electron where JavaScript often has extended privileges
- Running the renderer with reduced capabilities where feasible (for example, limiting direct Node.js access) to reduce impact if a script is injected
Effective mitigation focuses on treating all document attributes as untrusted input and enforcing strict output encoding before injecting them into HTML or CSS contexts.
Common defensive patterns include:
- Applying context-aware escaping for style and HTML attributes, ensuring that special characters, URL fragments, and script-like payloads are neutralized
- Introducing a validation layer that restricts title-img values to safe formats (e.g., constrained URLs or predefined tokens instead of raw strings)
- Designing rendering components to avoid mixing executable contexts with user-controlled data, especially in Electron where JavaScript often has extended privileges
- Running the renderer with reduced capabilities where feasible (for example, limiting direct Node.js access) to reduce impact if a script is injected
How teams detect issues like this
Detection usually combines static analysis, targeted code review, and runtime validation.
Common approaches include:
- Static analysis rules that flag direct concatenation or interpolation of user-controlled data into HTML, CSS, or JavaScript contexts without escaping
- Code review practices that treat attribute rendering paths and markdown-to-HTML conversions as high-risk areas requiring explicit sanitization checks
- Automated linting or policy enforcement that mandates use of safe templating helpers for any style, src, or event-handler-related attributes
- Optional use of security-oriented scanning tools that crawl rendered documents and look for suspicious inline attributes or script-like patterns
Detection usually combines static analysis, targeted code review, and runtime validation.
Common approaches include:
- Static analysis rules that flag direct concatenation or interpolation of user-controlled data into HTML, CSS, or JavaScript contexts without escaping
- Code review practices that treat attribute rendering paths and markdown-to-HTML conversions as high-risk areas requiring explicit sanitization checks
- Automated linting or policy enforcement that mandates use of safe templating helpers for any style, src, or event-handler-related attributes
- Optional use of security-oriented scanning tools that crawl rendered documents and look for suspicious inline attributes or script-like patterns

