Summary
SiYuan before v3.7.4 contains a cross-site scripting vulnerability in the file-tree picker used by move and link dialogs. Unsanitized document metadata can inject HTML attributes and event handlers; in the Electron environment, a victim hovering over a malicious document entry may enable arbitrary OS command execution.
Affected context
The vulnerability occurs in SiYuan's Electron file-tree path-selection dialogs when document metadata such as bookmarks, aliases, memos, or alternate names is incorporated into an HTML aria-label without adequate escaping. Risk depends on a malicious document reaching a victim through sharing, synchronization, import, or another content-distribution path, combined with the application's privileged Electron runtime configuration.
Exploit preconditions
- Attack surface: File-tree picker and path-selection dialogs in the SiYuan Electron application
- Required access: Ability to introduce or distribute a document containing malicious metadata
- Trigger point: A victim opens a move or link-to dialog and hovers over the affected document entry
- Why exploitation is possible: Metadata is concatenated into an HTML attribute without escaping, allowing attribute-context breakout and event-handler injection; Electron runtime privileges may expose operating-system capabilities to the injected script
Why this happens
The underlying bug is context-insensitive output construction. Document-controlled metadata is inserted into an HTML attribute as if it were trusted text, without applying attribute-aware escaping or using a safe DOM construction API. A quote in the metadata can terminate the intended attribute and introduce attacker-controlled markup or event handlers, mapping to CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'). The impact is amplified by the Electron configuration when renderer content has access to privileged Node.js functionality and lacks compensating isolation or content-security controls.
Potential impact
- A malicious document may execute script in the context of the SiYuan renderer.
- An attacker could potentially execute arbitrary operating-system commands on the victim's system.
- Local files, application data, or credentials may be exposed or modified.
- The attacker could potentially tamper with documents or use the application context for further compromise.
General mitigation guidance
Mitigation generally focuses on treating all document metadata as untrusted and preserving the correct output context.
Common defensive patterns include:
- Applying context-appropriate HTML attribute escaping, or constructing attributes through safe DOM APIs rather than string concatenation.
- Keeping document metadata as inert text and avoiding the creation of event-handler attributes from content.
- Reducing renderer privileges through secure Electron defaults, including disabling unnecessary Node.js access and maintaining context isolation.
- Applying a restrictive Content Security Policy that limits inline script execution where the application architecture permits it.
- Separating imported or synchronized content from privileged application capabilities and running with least privilege.
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules that flag string concatenation or interpolation into HTML attributes.
- Code review checks for document-controlled values used in templates, aria attributes, or event-handler contexts.
- Tests containing quotes and markup characters in metadata fields, followed by verification that rendered output remains inert.
- Policy enforcement requiring safe DOM APIs, contextual encoding, and secure Electron settings.
- Automated security review tools that identify DOM-based XSS sinks and unsafe renderer privilege configurations.

