Summary
SiYuan versions before 3.7.4 contain a stored cross-site scripting vulnerability in the Template calculation operator, which renders user-authored Go templates and stores their output without sanitization. Malicious HTML or JavaScript may execute in the desktop client when the affected database is opened, potentially enabling arbitrary code execution where Node integration is available.
Affected context
The issue occurs in SiYuan desktop deployments that use the Template calculation operator to process user-authored templates and later render the resulting content in a client context with Node integration enabled. Risk depends on whether an attacker can influence template content or stored calculation output and whether a user opens the affected database in the vulnerable renderer.
Exploit preconditions
- Attack surface: Template calculation content and the desktop database renderer
- Required access: Ability to create or modify user-authored templates, calculation content, or synchronized database data
- Trigger point: Opening the affected database in the SiYuan desktop client
- Why exploitation is possible: Template output is stored and rendered without adequate HTML and script sanitization, while the renderer exposes privileged Node-enabled capabilities
Why this happens
The vulnerability results from treating generated template output as trusted content and rendering it without context-appropriate sanitization or isolation. This allows attacker-controlled markup and script content to persist in stored data and execute when displayed. The issue maps to CWE-79: Improper Neutralization of Input During Web Page Generation, with the impact amplified when a desktop renderer exposes Node integration or other privileged runtime capabilities.
Potential impact
- Arbitrary JavaScript execution in the desktop client context
- Execution of operating-system commands where renderer privileges permit it
- Theft or modification of accessible local files and application data
- Account, session, or database compromise
- Data tampering or malicious content propagation through synchronized databases
General mitigation guidance
Mitigation generally focuses on preventing untrusted template output from becoming executable markup and reducing renderer privileges.
Common defensive patterns include:
- Applying context-aware output encoding and sanitization before storing or rendering generated content
- Treating template results as data rather than trusted HTML by default
- Disabling Node integration and other unnecessary privileged browser capabilities
- Enforcing content isolation through a strict content security policy and separate rendering contexts
- Restricting who can author or synchronize templates and database content
- Applying least privilege to the desktop process and accessible files
- Separating preview or rendering functionality from sensitive application operations
How teams detect issues like this
Organizations can detect related risks through:
- Static analysis rules for unsanitized template output assigned to HTML-rendering sinks
- Code review checks for innerHTML-like APIs, dynamic script execution, and privileged renderer configuration
- Tests that place harmless markup and script markers in template fields and verify they remain inert
- Policy enforcement requiring context-aware encoding, strict content security policies, and disabled Node integration unless specifically justified
- Monitoring database synchronization and template changes for unexpected markup or script content
- Automated application-security and dependency review tools that flag stored XSS patterns and unsafe desktop webview settings

