Summary
SiYuan versions before 3.8.2 contain a path traversal vulnerability in the /api/riff/removeRiffDeck endpoint because the deckID parameter is not adequately validated. An authenticated administrator may use crafted path references to delete .deck and .cards files outside the intended workspace directory.
Affected context
The vulnerability occurs in SiYuan deployments that expose the Riff deck removal API and use user-controlled deckID values to construct filesystem paths. It becomes risky when an authenticated administrator can reach the endpoint and the application does not constrain resolved paths to the designated workspace or restrict deletion to expected file locations and extensions.
Exploit preconditions
- Attack surface: The
/api/riff/removeRiffDeckHTTP endpoint - Required access: An authenticated account with administrator-level permissions
- Trigger point: Processing the
deckIDparameter during Riff deck removal - Why exploitation is possible: The parameter is used without sufficient path canonicalization and boundary validation, allowing references to resolve outside the intended workspace and target supported file types.
Why this happens
The underlying bug is improper validation of a filesystem path derived from external input. When an application treats an identifier as a path component without canonicalizing it and verifying that the resulting path remains within an allowed directory, traversal sequences can escape the intended filesystem boundary. This behavior maps to CWE-73: External Control of File Name or Path, and can turn a logical deletion operation into arbitrary file deletion within the process's permissions.
Potential impact
- An attacker may delete
.deckfiles outside the intended workspace. - An attacker may remove
.cardsfiles used by other application workflows. - The application may experience data loss or degraded availability.
- Stored content, configuration, or operational data may be damaged if it is accessible through the affected deletion logic.
- Recovery efforts may require restoring affected files from trusted backups.
General mitigation guidance
Mitigation generally focuses on treating deck identifiers as opaque application identifiers rather than filesystem paths.
Common defensive patterns include:
- Canonicalizing candidate paths before any filesystem operation.
- Verifying that resolved paths remain beneath an explicitly allowed workspace directory.
- Allowing deletion only of files discovered through trusted server-side metadata.
- Enforcing strict identifier schemas and rejecting traversal characters or path separators.
- Applying least-privilege permissions to the application process and its workspace.
- Using narrowly scoped deletion APIs and maintaining reliable backups and recovery controls.
- Returning generic errors that do not disclose filesystem layout details.
How teams detect issues like this
Organizations can look for path traversal risks through:
- Static analysis rules that flag filesystem calls receiving request parameters.
- Code review checks for path joining without canonicalization and containment validation.
- Tests using traversal-like input variants to verify that operations remain inside approved directories.
- Runtime monitoring for unusual deletion activity, repeated failed path validations, or access attempts outside the workspace.
- API policy enforcement requiring administrator authorization and restricting destructive operations to approved resource identifiers.
- Automated security review tools that identify external input flowing into file deletion functions.

