Summary
SiYuan contains a cross-site scripting vulnerability in its file upload validation flow because filenames are inserted into HTML without adequate escaping. An attacker who can provide a maliciously named file may execute script when a user drags, drops, or pastes that file into the editor; in the desktop application context, this could expose OS command capabilities.
Affected context
The vulnerability occurs in SiYuan's file handling and editor integration when a filename is accepted from an untrusted source and later inserted into the document interface. Risk is increased when users interact with attacker-supplied files through drag-and-drop or paste operations and when the application runs with access to local operating-system capabilities.
Exploit preconditions
- Attack surface: File upload, drag-and-drop, or paste handling in the editor
- Required access: The ability to provide or cause a user to handle a file with a crafted filename
- Trigger point: Filename validation or rendering that inserts the name into the DOM
- Why exploitation is possible: Unescaped filename content is interpreted as HTML and may execute in the application's trusted origin
- Additional condition: Impact may be greater in desktop deployments that expose privileged OS integration to rendered content
Why this happens
The underlying bug is a failure to treat filenames as untrusted text before placing them into an HTML parsing context. Using insertAdjacentHTML with unescaped user-controlled data allows markup and script-bearing content to be interpreted by the browser or embedded webview rather than displayed literally. This maps to CWE-79: Improper Neutralization of Input During Web Page Generation, commonly known as cross-site scripting.
Potential impact
- An attacker may execute script in the application's trusted origin
- A script could access application data available to the affected document context
- User actions or editor content could be manipulated
- In desktop deployments, malicious content could potentially invoke exposed OS command capabilities
- The application session could be abused for further local or network activity
General mitigation guidance
Mitigation generally focuses on preserving the distinction between untrusted filenames and executable markup.
Common defensive patterns include:
- Rendering filenames with text-oriented DOM APIs such as
textContentor equivalent safe element properties - Applying context-appropriate output encoding whenever dynamic values enter HTML
- Avoiding string-based HTML construction for user-controlled values
- Using narrowly scoped sanitization only when HTML rendering is genuinely required
- Validating filenames against an allowlist of expected characters and formats as a secondary control
- Limiting web-content privileges and OS integration available to rendered application content
- Applying defense-in-depth browser, webview, and content security policies where supported
How teams detect issues like this
Detection can combine static analysis, review, and runtime controls:
- Search for
insertAdjacentHTML,innerHTML, template interpolation, and similar HTML sinks receiving filename or upload metadata - Flag data flows from file names, drag-and-drop events, clipboard data, or upload responses into HTML-generating APIs
- Review whether output encoding is appropriate for the exact rendering context
- Add tests using markup-like filenames to verify literal rendering rather than execution
- Enforce secure DOM-manipulation and content-security policies through automated quality gates
- Use neutral automated code-review tools to identify untrusted data reaching browser or webview execution sinks

