Summary
SiYuan contains a stored cross-site scripting vulnerability in the asset search results interface, where asset filenames are inserted into HTML without proper escaping. An authenticated attacker who can create or rename assets may cause JavaScript to execute in another user's browser when that user searches assets, potentially enabling same-origin requests and application state changes.
Affected context
The vulnerability occurs in SiYuan deployments that render asset filenames in the Search Assets result list without applying context-appropriate output encoding. Exploitation depends on an authenticated user being able to influence an asset filename and another user viewing the affected result through the asset search interface.
Exploit preconditions
- Attack surface: The authenticated asset management and search interface
- Required access: An authenticated account with permission to create or modify asset filenames
- Trigger point: Rendering a matching asset in the Search Assets result list
- Why exploitation is possible: User-controlled filename content is interpolated into HTML without sufficient escaping, allowing browser-interpreted markup to execute in the application's origin
Why this happens
The underlying flaw is improper neutralization of user-controlled data in web page generation. Asset filenames are treated as trusted HTML content rather than encoded as text for the output context, which maps to CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'). Because the malicious content is stored as part of an asset name, it can affect later users who view matching search results.
Potential impact
- JavaScript execution in a victim's browser context
- Same-origin requests performed with the victim's authenticated session
- Unauthorized application state changes
- Exposure of data accessible to the victim's session
- Possible disruption of user workflows or administrative actions
General mitigation guidance
Mitigation generally focuses on ensuring that asset metadata is treated as untrusted data throughout its lifecycle.
Common defensive patterns include:
- Applying context-appropriate output encoding when rendering filenames
- Preferentially inserting filenames as text through safe DOM APIs rather than constructing HTML
- Validating and constraining metadata while preserving safe, legitimate filenames
- Using a restrictive Content Security Policy as a defense-in-depth control
- Limiting authenticated users' ability to alter shared asset metadata
- Applying least-privilege permissions to sensitive application actions
- Reducing reliance on ambient browser credentials for state-changing requests
How teams detect issues like this
Organizations can detect similar issues through:
- Static analysis rules for string interpolation into HTML or DOM sinks
- Code review checks for unescaped filenames, labels, and other stored metadata
- Dynamic testing with harmless markup markers in user-controlled fields
- Browser security testing focused on stored data displayed in search and listing views
- Policy enforcement requiring context-aware output encoding and safe DOM construction
- Automated security review tools that identify common cross-site scripting sinks

