Summary
SiYuan's import endpoints in versions 3.6.0 and below derive filesystem paths directly from user-supplied multipart filenames without proper sanitization, enabling path traversal and arbitrary file writes.
An authenticated admin who can access POST /api/import/importSY or POST /api/import/importZipMd may write archives to locations outside the temporary directory, potentially overwriting application or system files and, in common Docker-as-root deployments, achieving remote code execution within the container.
Affected context
This vulnerability occurs in SiYuan deployments (up to and including version 3.6.0) that expose the import functionality via:
- POST /api/import/importSY
- POST /api/import/importZipMd
The issue manifests when the server constructs filesystem paths from the multipart upload filename field and writes archives directly to disk. If the application runs with elevated privileges (such as root inside a Docker container) or has write access to sensitive directories, the risk increases significantly. The problem is limited to environments where administrative access to these endpoints is possible, but such access is common in self-hosted setups.
Exploit preconditions
- Attack surface: HTTP API endpoints:
- POST /api/import/importSY
- POST /api/import/importZipMd
- Required access: Authenticated administrative access (or any role allowed to use these import endpoints).
- Trigger point: Submission of a crafted multipart/form-data request where the filename field contains traversal sequences or targeted paths.
- Why exploitation is possible:
- The server uses the provided filename directly to construct the destination path.
- There is no sufficient normalization or validation to restrict writes to the intended temporary directory.
- The process may run with permissions that allow writing to application, workspace, or system directories, enabling overwrite of critical files and potential execution of attacker-controlled content.
Why this happens
The root cause is the lack of strict path validation and confinement when handling uploaded archives. The import handlers build file paths from the user-controlled multipart filename and write the received archive to those locations without enforcing that the resolved path stays within a designated temporary or import directory.
This behavior maps to:
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'): user input is allowed to influence directory traversal and final location.
- CWE-73: External Control of File Name or Path: external input directly controls which file is created or overwritten.
Instead of treating filenames as untrusted data that must be canonicalized and constrained, the implementation implicitly trusts them, enabling arbitrary file write and, in permissive runtime environments, code execution through overwritten binaries, scripts, or configuration files.
Potential impact
- Overwriting of SiYuan workspace data, leading to partial or complete data loss.
- Overwriting of SiYuan application files, potentially breaking the application or injecting malicious behavior.
- Writing files into directories that are later executed or interpreted (e.g., startup scripts, plugin directories), which can lead to code execution.
- Full compromise of Docker containers that run SiYuan as root, including the ability to:
- Install backdoors or web shells.
- Modify configuration for persistence or lateral movement within the container's environment.
- Potential escalation to host-level impact if the container has overly broad mounts or privileges and the process can write to sensitive host paths.
General mitigation guidance
Effective mitigation focuses on constraining how file paths are derived from user input and reducing the impact of any file-write capability:
- Enforce directory confinement:
- Resolve and canonicalize the destination path and ensure it remains within a dedicated, application-controlled import directory.
- Reject any path that, after normalization, would escape this directory.
- Treat filenames as untrusted:
- Strip directory separators and traversal sequences from user-supplied filenames.
- Replace user-provided filenames with server-generated names (e.g., UUIDs) and store original names only as metadata, not as paths.
- Implement least privilege for file writes:
- Run the application under a non-root account with minimal filesystem permissions.
- Ensure the process can write only to specific, non-executable directories required for operation.
- In container environments, avoid running as root and use read-only file systems where possible, with explicit writable volumes only for necessary data.
- Harden archive handling:
- When extracting archives, validate each entry's path to enforce that it stays within a predefined base directory.
- Reject archives with entries containing traversal sequences or absolute paths.
Collectively, these patterns limit how much control an attacker gains over filesystem locations even if they can upload content.
How teams detect issues like this
Detection efforts can target both code-level patterns and runtime behavior:
- Static analysis and code review:
- Search for file operations (e.g., open, write, extract) where the path or filename originates from HTTP request fields, especially multipart filenames.
- Verify that all such paths pass through canonicalization and checks against a strict base directory.
- Flag any use of raw user input in filesystem APIs without validation or normalization.
- Security-focused code review practices:
- Establish review checklists for upload and import features, explicitly asking whether filenames and archive entries are bounded to a safe directory.
- Review container/Dockerfile configurations for unnecessary root use and overly permissive volume mounts.
- Automated tooling and policies:
- Use application security testing tools (SAST/DAST) configured to detect path traversal and uncontrolled file write patterns.
- Integrate pre-commit or CI rules that disallow direct concatenation of request fields into filesystem paths.
- Operational monitoring:
- Monitor logs for import endpoints, looking for unexpected filename patterns (e.g.,
../, absolute paths, or system directory paths). - Watch for unexpected file modifications in application directories or system paths within containers.

