Summary
SiYuan contains a stored cross-site scripting flaw in the Attribute View (database) feature where template column values are rendered as HTML without consistent auto-escaping.
An attacker who can save crafted HTML in a template cell can trigger script execution when the database is viewed, and in the desktop app this JavaScript can escalate to arbitrary command execution via Node integration.
Affected context
This vulnerability arises in SiYuan's Attribute View (database) when users define Template columns whose content is rendered through text/template into the UI.
In affected versions, the renderer selectively applies HTML escaping based on a heuristic that checks for unclosed HTML tags, and then inserts the result with innerHTML.
Balanced self-closing tags, such as <img>, bypass this check and are rendered unescaped, creating a persistent XSS condition in any environment where user-controlled template values are stored and later displayed.
Exploit preconditions
- Attack surface: Attribute View (database) UI where Template columns are used and rendered into the main page.
- Required access: Ability to create or modify database entries or templates so that crafted HTML is stored in a Template column.
- Trigger point: A victim (or the attacker) opens or refreshes the affected Attribute View so that the vulnerable cell is rendered via
innerHTML. - Why exploitation is possible: The rendering pipeline uses
text/templatewithout default auto-escaping and relies on aHasUnclosedHtmlTagheuristic before applyingEscapeHTML; self-closing tags such as<img>pass this heuristic and are inserted directly as HTML, allowing injected event handlers to run. In the desktop app withnodeIntegrationenabled, the injected script can accessrequireand pivot to arbitrary command execution.
Why this happens
The core issue is inconsistent output encoding in a context where user-controlled data is rendered as HTML.
SiYuan's template rendering engine treats template column values as trusted markup, using text/template and inserting the resulting string via innerHTML while only conditionally escaping content.
Because the decision to escape relies on detecting unclosed tags, structurally valid HTML fragments with self-closing tags are not sanitized, directly mapping to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).
This pattern allows untrusted content to be interpreted as active HTML/JavaScript in both the browser and Electron-like desktop renderer, broadening the impact to OS-level command execution when Node APIs are exposed.
Potential impact
- Stored execution of arbitrary JavaScript in the context of the SiYuan UI.
- Theft or manipulation of user data stored or displayed within SiYuan.
- Session hijacking or persistence of attacker-controlled scripts in shared workspaces.
- In the desktop application, arbitrary command execution via access to Node's
requireand related APIs. - Potential installation of additional malware or backdoors on the host system running the desktop app.
General mitigation guidance
Effective mitigation focuses on enforcing strict output encoding and reducing trust in user-controlled template content.
Common defensive patterns include:
- Treating all template-derived values as untrusted and applying context-appropriate escaping before assigning to
innerHTMLor equivalent sinks. - Configuring template engines to be HTML-escaping by default, only allowing raw HTML through tightly controlled and audited helpers.
- Avoiding heuristic-based escaping decisions; instead, apply consistent encoding for all outputs unless an explicit, well-reviewed exception exists.
- Segmenting untrusted data from markup by using DOM APIs (e.g.,
textContent, attribute setters) rather than building HTML strings where possible. - In desktop environments, disabling or minimizing
nodeIntegrationand applying least-privilege principles so that a single XSS does not directly yield OS command execution.
How teams detect issues like this
Detection can leverage both code-centric and behavioral approaches:
- Static analysis rules that flag uses of
innerHTML,dangerouslySetInnerHTML, or similar APIs combined with unescaped user-controlled data. - Checks in templating logic for non-escaping render paths, especially where
text/template, RAW blocks, or custom helpers bypass default encoders. - Code review guidelines that require reviewers to verify context-aware escaping for any data rendered into HTML, attributes, or event handlers.
- Automated security tests or fuzzing that inject typical XSS payloads into Template columns and observe whether scripts execute when views are rendered.
- Configuration audits for Electron or similar desktop frameworks to identify instances where
nodeIntegrationis enabled in windows that render untrusted content.

