Summary
SiYuan's database_clean MCP tool does not adequately validate its id parameter before using it to construct a filesystem path. An authenticated MCP client may exploit path traversal sequences to copy an arbitrary file readable by the kernel into the history directory and delete the original file.
Affected context
The vulnerability occurs in SiYuan kernel deployments where the database_clean MCP tool is enabled and accepts requests from authenticated MCP clients. The MCP path does not sufficiently enforce SiYuan's node-ID format before RemoveUnusedAttributeView builds a filesystem path, allowing specially crafted identifiers to influence filesystem locations.
Exploit preconditions
- Attack surface: The SiYuan MCP interface and its
database_cleantool - Required access: An authenticated MCP client with permission to invoke the tool
- Trigger point: Processing of the
idparameter byRemoveUnusedAttributeView - Why exploitation is possible: The parameter is checked only for emptiness and is not constrained to a valid node-ID format before being passed to filesystem path construction
Why this happens
The underlying flaw is insufficient validation of a user-controlled path component. The tool treats the id value as a trusted identifier after only checking whether it is empty, while filepath.Join can resolve traversal components into locations outside the intended directory. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because attacker-influenced input can escape the expected filesystem boundary and affect arbitrary process-readable paths.
Potential impact
- An attacker may read files accessible to the SiYuan process
- An attacker may cause readable files to be copied into SiYuan's history directory
- An attacker may delete original files that the process can modify
- Sensitive application, configuration, or credential data could be exposed
- Data integrity and service availability could be affected
General mitigation guidance
Mitigation generally focuses on treating MCP parameters as untrusted input and enforcing filesystem boundaries before any file operation occurs.
Common defensive patterns include:
- Accepting only identifiers that match a strict node-ID schema rather than permitting arbitrary path text
- Rejecting traversal markers, absolute paths, separators, and other unexpected path syntax
- Resolving candidate paths and verifying that they remain within the intended base directory
- Applying the same validation and boundary checks consistently across HTTP and MCP callers
- Running the kernel with the least filesystem privileges needed for its workload
- Restricting MCP tool exposure and using narrowly scoped authentication and authorization
- Avoiding deletion or copying when validation, canonicalization, or authorization checks fail
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules identifying user-controlled values passed to path-joining, file-copy, or file-deletion APIs
- Code review checks for empty-string-only validation of path-like identifiers
- Tests using traversal sequences, absolute paths, encoded separators, and platform-specific path syntax
- Runtime monitoring for unusual MCP calls, unexpected history-directory contents, and file operations outside approved roots
- Policy enforcement requiring canonical-path containment checks and authorization before filesystem mutation
Automated security review tools may help identify unsafe data flows from MCP parameters to filesystem APIs.

