Summary
A path traversal vulnerability in SiYuan's snippet-serving endpoint allows authenticated users to escape the intended snippets directory and access sensitive files.
By abusing double-encoded directory traversal sequences in snippet paths, an attacker can read workspace secrets and the underlying document database when the application handles the request.
Affected context
This vulnerability occurs in SiYuan deployments that expose the /snippets/*filepath HTTP route and rely on it to serve user snippets from a dedicated directory.
The issue manifests when request paths are decoded and then joined with the snippets directory without verifying that the resulting path remains inside the allowed subtree.
It is most relevant in environments where authenticated users have access to the snippets API and the application stores configuration, secrets, and document data in predictable subdirectories.
Exploit preconditions
- Attack surface: HTTP endpoint
/snippets/*filepathon the SiYuan server. - Required access: Valid authenticated user account capable of sending snippet requests.
- Trigger point: Supplying a crafted, encoded path (e.g.,
/%2e%2e/%2e%2e/conf/conf.json) that is decoded and joined with the snippets directory. - Why exploitation is possible: The server decodes the path once and performs a simple filesystem join without enforcing subpath containment or checking for traversal sequences, allowing access outside the intended snippets directory.
Why this happens
The underlying bug is a classic path traversal issue where user-supplied filesystem paths are trusted without proper normalization and containment checks.
In serveSnippets within kernel/server/serve.go, the application joins a single-decoded request path directly with the snippets directory and then serves the resulting file.
This pattern maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory and CWE-23: Relative Path Traversal, because user-controlled relative paths can escape the target directory and reach sensitive configuration and database files.
Potential impact
- An attacker may read configuration files containing workspace secrets or authentication tokens.
- An attacker could access the document database and extract private notes or knowledge base content.
- Sensitive system or application metadata can be disclosed, aiding further attacks.
- Compromised data may enable account takeover or unauthorized integration access, depending on stored secrets.
General mitigation guidance
Effective mitigation focuses on strictly constraining file access to the intended snippets directory and treating all request paths as untrusted.
Secure patterns include:
- Normalizing and canonicalizing requested paths, then verifying that the resolved path is a subpath of the snippets root before serving any file.
- Rejecting any path containing traversal segments such as
..after normalization, regardless of encoding. - Using higher-level file-serving utilities that enforce directory whitelisting and subpath containment by default.
- Separating storage locations for configuration, secrets, and databases from any web-accessible directories and ensuring snippet serving logic cannot traverse to those locations.
- Applying least-privilege file permissions so that web components cannot read unnecessary sensitive files even if traversal is attempted.
How teams detect issues like this
Organizations can detect similar path traversal weaknesses by:
- Applying static analysis rules that flag direct concatenation or joining of user-supplied paths with filesystem locations without containment checks.
- Reviewing route handlers for file-serving logic that lacks path normalization and directory whitelisting.
- Implementing security tests or fuzzing against file-serving endpoints using encoded
..segments and unexpected path patterns to confirm containment. - Enforcing application security policies that require canonical path checks and explicit directory scopes for any file access based on HTTP parameters.
- Using automated code review tools or SAST platforms configured with rules for CWE-22 and CWE-23 to catch risky filesystem access patterns during development.

