Summary
xiaomusic v0.5.7 exposes an unauthenticated path traversal flaw in the GET /music/{file_path:path} endpoint, caused by an incomplete path prefix check that omits a trailing separator.
By crafting traversal sequences and exploiting directories whose names share the configured music_path prefix, an attacker can bypass the intended restriction and read arbitrary files outside the music directory.
Affected context
This vulnerability appears in xiaomusic instances that serve media files via the /music/{file_path:path} HTTP endpoint and use a simple prefix-based comparison to constrain file access to a configured music directory.
It arises when the code checks that the resolved path starts with music_path but does not ensure a directory boundary (for example, missing a trailing slash or separator), allowing sibling directories sharing the same prefix to be treated as valid.
Deployments that expose this endpoint over a network without additional authentication or reverse proxy filtering are particularly exposed.
Exploit preconditions
- Attack surface: Public or internal HTTP interface exposing GET /music/{file_path:path}
- Required access: No authentication required; any network client that can issue HTTP requests can attempt exploitation
- Trigger point: File retrieval logic that joins user-controlled file_path with the base music_path and performs an incomplete prefix check without enforcing directory boundaries
- Why exploitation is possible: The path validation relies solely on string prefix matching without normalizing, canonicalizing, and strictly re-validating the resulting path, enabling traversal sequences to escape the intended directory and reach sibling paths.
Why this happens
The core issue is a classic path traversal condition where user-supplied path segments are insufficiently constrained before being used in filesystem access.
Instead of resolving the requested file path to its canonical form and verifying that it resides strictly within the configured music directory, the implementation performs a simple string prefix check that does not account for trailing separators or directory boundaries.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where a resource access control intends to restrict file reads but uses fragile string-based logic allowing crafted paths to reference unintended locations.
Potential impact
- Reading sensitive configuration files that may contain credentials or tokens
- Accessing application logs that could reveal internal paths, queries, or user-related information
- Exposing private user data stored on the same host, depending on file system layout and permissions
- Gathering information useful for further attacks, such as identifying software versions, directory structures, or other services
General mitigation guidance
Effective mitigation typically focuses on enforcing robust filesystem boundaries and minimizing trust in user-supplied paths.
Common defensive patterns include:
- Resolving requested paths to canonical/absolute paths and verifying they remain strictly under the intended base directory using filesystem-aware checks rather than string prefix comparisons.
- Rejecting any request containing traversal sequences (such as parent directory references) after normalization, or mapping only whitelisted logical identifiers to physical paths.
- Serving media files through higher-level abstractions (e.g., IDs, database references, or content hashes) instead of exposing raw filesystem paths.
- Running the file-serving component under an account with least-privilege access limited to the intended media directory, reducing the impact of any path validation failures.
How teams detect issues like this
Detection often combines code-level and operational approaches:
- Static analysis: Configure rules to flag direct concatenation of user-provided path segments with filesystem paths, as well as naive prefix or substring checks used for directory confinement.
- Code review: Look for implementations that rely on startswith-like checks to enforce directory boundaries and confirm that path normalization and boundary checks are performed using filesystem APIs.
- Security testing: Incorporate automated and manual tests that attempt path traversal payloads against file-serving endpoints, monitoring for unexpected file disclosures.
- Logging and monitoring: Enable detailed access logging for file endpoints, and alert on unusual patterns such as repeated use of traversal sequences or requests targeting unexpected directories.

