/

CVE-2026-25539

Severity:

CRITICAL RISK

(9.1)

Path Traversal File Write in SiYuan copyFile Allows

CVE-2026-25539

Analyzed

Vulnerability type

Category:

Path Traversal / Arbitrary File Write

CWE:

CWE-22

Impact:

Remote Code Execution via Arbitrary File Write

Severity:

CRITICAL RISK

(9.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

An input validation flaw in SiYuan's /api/file/copyFile endpoint allows authenticated users to write files to arbitrary paths on the server filesystem by controlling the dest parameter.

When abused, this arbitrary file write can be used to place malicious content into sensitive locations such as cron jobs, SSH authorized_keys, or shell configuration files, enabling remote code execution under certain deployment conditions.

Affected context

The vulnerability affects SiYuan deployments that expose the /api/file/copyFile endpoint to authenticated users and rely on the server filesystem for configuration, scheduling, or authentication artifacts.

It becomes relevant where:

  • The application runs with permissions to write into sensitive directories (e.g., user home, system configuration, or cron paths), and
  • Application-level checks do not constrain the dest path to a safe, application-controlled directory.

In these environments, authenticated users who can invoke this API may be able to write files outside the intended storage area.

Exploit preconditions

  • Attack surface: HTTP(S) API endpoint /api/file/copyFile exposed by the SiYuan server.
  • Required access: Valid authenticated access to the SiYuan instance with permission to call the file copy API.
  • Trigger point: Supplying a crafted dest parameter that references an arbitrary or traversal-based filesystem path when invoking the copyFile endpoint.
  • Why exploitation is possible: The server-side implementation does not validate or constrain the dest parameter to a restricted directory, so user-controlled input directly influences the final filesystem write path.

Why this happens

This issue is rooted in improper path handling and insufficient input validation for filesystem operations.

The /api/file/copyFile endpoint trusts the dest parameter supplied by the client and uses it to determine the target path for the file write without enforcing that the destination remains within a dedicated, application-owned directory.

As described by CWE-22 (Improper Limitation of a Pathname to a Restricted Directory), this pattern occurs when path components from user input are combined with filesystem operations without canonicalization and without enforcing a strict allowlist of permitted locations.

In abstract terms, any API that exposes "copy", "save", "upload", or "export" functionality and lets callers control the filesystem path is vulnerable unless it normalizes the path and ensures it stays inside a permitted root.

Potential impact

  • Attacker-controlled content can be written to arbitrary locations on the server filesystem.
  • Remote code execution may occur if the attacker can:
  • Write to cron directories or files to schedule malicious commands, or
  • Modify shell initialization scripts to execute payloads on administrator login, or
  • Insert keys into SSH authorized_keys to gain persistent remote access.
  • Escalation of privileges may be possible if sensitive system or application configuration files are overwritten.
  • Integrity of the application and host system can be compromised through backdoors, persistence mechanisms, or tampered configuration.
  • Confidentiality of stored data may be impacted if filesystem modifications are used to exfiltrate or expose sensitive information.

General mitigation guidance

Long-term risk reduction for this class of issue involves constraining filesystem operations and treating all path input as untrusted:

  • Enforce a restricted root directory: Ensure any dest path is resolved relative to a dedicated application data directory and reject requests that attempt to escape that root after canonicalization.
  • Normalize and validate paths: Canonicalize paths (resolving .., symlinks, and redundant separators) before use, and verify they conform to an allowlisted prefix or pattern.
  • Avoid passing raw user paths to filesystem APIs: Use server-side identifiers, mapping logical file IDs to physical paths instead of exposing actual filesystem structure to the client.
  • Apply least-privilege to the runtime: Run the SiYuan process under an account that only has access to the minimal set of directories needed for operation, preventing writes to high-impact locations such as system cron or SSH directories.
  • Implement robust authorization checks: Restrict who can use file-related APIs and limit them to operations on files they own or that belong to their workspace.
  • Harden deployment configuration: Consider using containerization, read-only filesystems for system paths, and mandatory access control (e.g., AppArmor, SELinux) to minimize the blast radius of any unexpected file writes.

How teams detect issues like this

Identifying and monitoring for this vulnerability type can combine code-centric and operational approaches:

  • Static analysis and code scanning:
  • Search for filesystem write operations (copy, move, create, open-with-write) whose target path is derived from HTTP parameters or request bodies.
  • Flag any code where user input is concatenated to base paths without normalization and boundary checks.
  • Use rules or patterns specifically targeting CWE-22 and arbitrary file write patterns in API handlers.
  • Manual code review:
  • Review endpoints that handle file uploads, copies, exports, or imports to ensure they implement root directory enforcement and canonical path validation.
  • Check that any mapping between user-visible paths and real filesystem locations is mediated by server-side logic rather than direct client control.
  • Runtime monitoring and logging:
  • Log file operations that touch directories outside the expected application data area, and alert on unusual write activity (e.g., cron directories, SSH directories, /etc, or shell configuration files).
  • Correlate suspicious filesystem writes with API calls and user accounts to quickly detect and investigate abuse.
  • Policy and configuration controls:
  • Use host- or container-level security policies (such as MAC profiles) to prevent the application from writing into sensitive system paths, which reduces the impact even if a similar flaw exists.

Sources

SourceLink
github.comgithub.com/siyuan-note/siyuan/commit/d7f790755edf8c78d2b4176171e5a0cdcd720feb
github.comgithub.com/siyuan-note/siyuan/security/advisories/GHSA-c4jr-5q7w-f6r9

Frequently asked

questions

Exploitation is limited to authenticated users who can call the /api/file/copyFile endpoint, but within that scope it can be highly impactful.

In environments where the application account can write to sensitive system or user directories, an attacker may leverage this to achieve remote code execution or persistent access.

No local system access is required, but valid authentication to the SiYuan instance is needed.

The attacker must be able to send crafted HTTP requests to the vulnerable endpoint; privilege requirements beyond basic authentication depend on how the application authorizes file operations.

Constrain all filesystem operations to an application-controlled root directory, canonicalize incoming paths, and reject any request that attempts to escape that boundary.

Additionally, avoid exposing raw filesystem paths in APIs and instead operate on internal identifiers that the server maps to safe locations.

Treat every client-supplied path or filename as untrusted data that needs normalization and strict validation.

Design APIs around logical resources rather than paths, apply least privilege to the runtime account, and use automated checks—such as static analysis rules for CWE-22—to catch unsafe filesystem usage during development and code review.

Find out what's already
exploitable in your codebase.