Summary
SiYuan's file-copy API can allow authenticated administrators to write files outside the workspace because its sensitive-path deny-list omits locations such as shell initialization files and ~/.local. A malicious or misused copy operation could place a payload that runs under the user's account when a shell starts or the user logs in.
Affected context
The issue affects SiYuan deployments with a vulnerable IsSensitivePath deny-list and an API path that permits absolute destination paths outside the workspace. Shell initialization files such as .zshenv and .bash_profile, as well as ~/.local, are among the omitted locations. The risk is relevant when an authenticated administrator can invoke /api/file/copyFile and the SiYuan process has write access to those destinations.
Exploit preconditions
- Attack surface: The
/api/file/copyFileAPI. - Required access: Authenticated administrator access.
- Trigger point: A copy request specifying an absolute destination outside the workspace.
- Why exploitation is possible: The sensitive-path deny-list is incomplete, allowing certain destinations to be written. A written shell initialization payload may execute when the corresponding user next starts a shell or logs in.
Why this happens
The file-copy operation relies on an incomplete deny-list to determine which paths are sensitive. Because some destinations outside the workspace are not covered, path handling may permit writes beyond the intended boundary. This is a path traversal and improper path restriction issue associated with CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
Potential impact
- An attacker with the required administrative access could write files outside the workspace.
- A payload placed in a shell initialization file could execute as the affected user on a later shell start or login.
- The user account and accessible data or resources could be compromised.
- Changes to files under
~/.localcould affect user-level programs or configuration.
General mitigation guidance
Defensive patterns include resolving and canonicalizing destination paths, then enforcing that they remain within an explicitly permitted directory. Prefer an allow-list of approved destinations over a deny-list of sensitive paths, and reject absolute paths or path components that escape the workspace when they are not required. Reduce trust in client-supplied paths, restrict file operations to the minimum necessary locations, and run the service with least-privilege filesystem permissions.
How teams detect issues like this
- Review file-copy and file-management code for path checks based solely on deny-lists.
- Use static analysis to identify writes involving user-controlled paths, absolute destinations, or insufficient canonicalization.
- Audit API authorization and filesystem permissions to confirm which users and processes can write outside the workspace.
- Monitor file changes to shell initialization files and unexpected locations under user-level directories.
- Enforce policies that restrict application writes to designated directories, and include path-boundary tests in security reviews.

