Summary
SiYuan contains a stored cross-site scripting vulnerability in its asset-serving functionality because some script-capable file extensions are not blocked.
If an attacker can upload a file using one of these extensions and a victim opens or loads the served asset, JavaScript may execute in the SiYuan workspace context, exposing API tokens or workspace data.
Affected context
The vulnerability occurs in SiYuan deployments that allow users or other reachable components to upload assets and subsequently serve them through the application.
Risk increases when the asset handler determines content types from extensions without comprehensively restricting script-capable formats, and when uploaded content is rendered under a trusted application origin.
Exploit preconditions
- Attack surface: Asset upload and asset-serving functionality
- Required access: Permission or another pathway to place files in an accessible asset location
- Trigger point: A victim or automated client loads the stored asset through the SiYuan application
- Why exploitation is possible: Incompletely blocked extensions may be served with executable media types, allowing browser script execution within the application's origin
Why this happens
The underlying issue is an incomplete file-extension blocklist combined with unsafe handling of uploaded assets.
When script-capable formats are accepted and served with browser-executable content types, the browser may interpret stored attacker-controlled content as active script. This maps to CWE-79: Improper Neutralization of Input During Web Page Generation, specifically stored cross-site scripting caused by insufficient output and content-type controls.
Potential impact
- An attacker may steal API tokens available to the workspace
- Malicious script may act with the victim's application privileges
- Workspace content or configuration could be accessed or modified
- Other users may be targeted when they view or load the stored asset
- The application session or connected integrations could be compromised
General mitigation guidance
Mitigation generally focuses on treating uploaded files as untrusted data and preventing browsers from interpreting them as active content.
Common defensive patterns include:
- Using an allowlist of permitted, non-executable asset types instead of relying only on an extension blocklist
- Serving user-uploaded content from an isolated origin without application credentials
- Applying authoritative, safe content types and preventing content-type sniffing
- Rejecting script-capable and browser-interpretable formats at upload and serving boundaries
- Encoding or safely rendering user-controlled metadata and filenames
- Restricting token scope and applying least privilege to workspace and integration credentials
- Using browser security policies, such as an appropriate Content Security Policy, as defense in depth
How teams detect issues like this
Detection approaches can include:
- Static analysis and code review checks for extension-only validation and incomplete executable-file blocklists
- Tests covering uncommon script-capable and XML-based file formats at upload and download boundaries
- Monitoring asset uploads for unexpected extensions, MIME types, and content mismatches
- Policy enforcement requiring untrusted files to be served from a separate origin with restrictive headers
- Browser and application telemetry for unusual token use or requests originating from asset URLs
- Automated security review tools that identify stored XSS sinks and unsafe file-serving behavior

