Описание
SiYuan has Arbitrary File Write via /api/file/copyFile leading to RCE
Summary
The /api/file/copyFile endpoint does not validate the dest parameter, allowing authenticated users to write files to arbitrary locations on the filesystem. This can lead to Remote Code Execution (RCE) by writing to sensitive locations such as cron jobs, SSH authorized_keys, or shell configuration files.
- Affected Version: 3.5.3 (and likely all prior versions)
Details
- Type: Improper Limitation of a Pathname to a Restricted Directory (CWE-22)
- Location:
kernel/api/file.go- copyFile function
The src parameter is properly validated via model.GetAssetAbsPath(), but the dest parameter accepts any absolute path without validation, allowing files to be written outside the workspace directory.
PoC
Step 1: Upload malicious content to workspace
Step 2: Copy to arbitrary location (e.g., /tmp)
Response: {"code":0,"msg":"","data":null}
Step 3: Verify file was written outside workspace
Attack Scenarios
| Target Path | Impact |
|---|---|
/etc/cron.d/backdoor | Scheduled command execution (RCE) |
~/.ssh/authorized_keys | Persistent SSH access |
~/.bashrc | Command execution on user login |
/etc/ld.so.preload | Shared library injection |
RCE Demonstration
RCE was successfully demonstrated by writing a script and executing it:
Impact
An authenticated attacker (with API Token) can:
- Achieve Remote Code Execution with the privileges of the SiYuan process
- Establish persistent backdoor access via SSH keys
- Compromise the entire host system
- Access sensitive data on the same network (lateral movement)
Suggested Fix
Add path validation to ensure dest is within the workspace directory:
Solution
d7f790755edf8c78d2b4176171e5a0cdcd720feb
Пакеты
github.com/siyuan-note/siyuan/kernel
<= 0.0.0-20260126094835-d5d10dd41b0c
Отсутствует
Связанные уязвимости
SiYuan is a personal knowledge management system. Prior to version 3.5.5, the /api/file/copyFile endpoint does not validate the dest parameter, allowing authenticated users to write files to arbitrary locations on the filesystem. This can lead to Remote Code Execution (RCE) by writing to sensitive locations such as cron jobs, SSH authorized_keys, or shell configuration files. This issue has been patched in version 3.5.5.