Summary
SiYuan before version 3.8.2 contains a stored cross-site scripting vulnerability in its search asset preview feature. Indexed asset content is inserted into the page without adequate escaping, allowing attackers who can place crafted text assets in a workspace to run JavaScript when another user previews them.
Affected context
The vulnerability occurs in SiYuan workspaces where asset content is indexed and later rendered by the search preview interface. Risk exists when an attacker can add or modify text assets and a victim with access to the workspace previews the affected content in the SiYuan origin.
Exploit preconditions
- Attack surface: SiYuan's search asset preview interface
- Required access: Ability to place or modify text assets in a workspace
- Trigger point: A victim previews the affected asset through search results
- Why exploitation is possible: Indexed content is inserted into the DOM through
innerHTMLwithout sufficient output encoding or sanitization
Why this happens
The underlying bug is a stored cross-site scripting condition caused by treating indexed asset content as trusted HTML when rendering search previews. Content that should remain data is inserted into the DOM through an HTML-interpreting sink without appropriate contextual escaping or sanitization. This maps to CWE-79: Improper Neutralization of Input During Web Page Generation, commonly known as cross-site scripting.
Potential impact
- JavaScript execution in the SiYuan origin
- Authenticated API requests performed in the victim's context
- Unauthorized workspace changes
- Exposure or modification of accessible workspace data
- Manipulation of content or settings available to the victim
General mitigation guidance
Mitigation generally focuses on preserving the distinction between asset content and executable markup.
Common defensive patterns include:
- Rendering untrusted preview content with text-safe DOM APIs rather than HTML-interpreting sinks
- Applying context-appropriate output encoding before inserting content into the page
- Using a narrowly scoped sanitizer when formatted markup is an intentional requirement
- Treating indexed assets and search results as untrusted data by default
- Applying a restrictive Content Security Policy as a defense-in-depth control
- Limiting workspace permissions so untrusted users cannot add or modify assets consumed by other users
How teams detect issues like this
Organizations can identify similar issues through:
- Static analysis rules for unsafe DOM sinks such as
innerHTML - Code review checks tracing asset, search, and index content into browser rendering paths
- Tests containing benign markup markers to verify that preview output remains inert
- Policies requiring contextual encoding or approved sanitization wrappers for untrusted content
- Automated security review tools that flag unsanitized data flows into HTML-rendering APIs

