Summary
SiYuan contains an arbitrary file deletion vulnerability in the template removal API because a user-controlled path is passed directly to a recursive filesystem deletion function. An authenticated administrator may use this behavior to delete files or directories that the SiYuan process has permission to remove.
Affected context
The vulnerability occurs in SiYuan deployments where the /api/search/removeTemplate endpoint is reachable and accepts a path parameter without sufficient validation. Risk is greatest when an authenticated administrator can influence that parameter and the application process has broad filesystem permissions, allowing the deletion operation to affect locations beyond the intended template directory.
Exploit preconditions
- Attack surface: The
/api/search/removeTemplateHTTP API endpoint - Required access: Authenticated administrator privileges
- Trigger point: Processing of the endpoint's path parameter
- Why exploitation is possible: The supplied path is passed to a recursive removal operation without reliably restricting it to an approved template directory
- Environmental dependency: The target files or directories must be accessible to the operating-system account running the SiYuan process
Why this happens
The underlying bug is improper restriction of filesystem paths, mapping to CWE-22: Improper Limitation of a Pathname to a Restricted Directory. The endpoint treats caller-controlled path data as a trusted filesystem location and passes it directly to a recursive deletion API. Without canonicalization, allowlisting, and enforcement of a fixed storage boundary, absolute or otherwise escaping paths may resolve outside the intended application directory.
Potential impact
- An attacker may delete application data, configuration files, or user content.
- The service may become unavailable if required runtime files are removed.
- Data loss or corruption could occur across directories accessible to the process.
- Security controls or logs may be weakened if the process can remove related files.
- Follow-on compromise could become possible if deletion affects operational or startup files.
General mitigation guidance
Mitigation generally focuses on making deletion operations operate only within a narrowly defined storage boundary.
Common defensive patterns include:
- Accepting opaque template identifiers rather than caller-supplied filesystem paths.
- Resolving and canonicalizing paths before authorization checks.
- Enforcing an allowlisted template directory and rejecting absolute paths or traversal outside that boundary.
- Applying authorization checks to the resolved target, not only to the submitted string.
- Using narrowly scoped deletion operations instead of recursive removal where possible.
- Running the service with a dedicated, least-privileged operating-system account and minimizing writable directories.
- Preserving backups and recovery controls for important application data.
How teams detect issues like this
Organizations can assess for this class of issue through:
- Static analysis rules that identify user-controlled values flowing into file deletion APIs such as
os.RemoveAll. - Code review checks for filesystem operations that lack canonicalization, boundary validation, or authorization.
- API policy tests using absolute paths, traversal sequences, symlink scenarios, and paths outside the intended storage root.
- Runtime monitoring for unexpected recursive deletion activity or access to sensitive filesystem locations.
- Automated security review tools that flag path parameters reaching destructive filesystem functions.

