Summary
A path traversal vulnerability in the read_content tool of @sylphxltd/filesystem-mcp v0.5.8 allows attackers to bypass directory restrictions by abusing symbolic links inside otherwise permitted directories.
Because path validation occurs before symlink resolution, while file reads follow symlinks, an attacker who can influence filesystem layout can access files outside the intended operational scope.
Affected context
This vulnerability affects environments where @sylphxltd/filesystem-mcp v0.5.8 is used to provide controlled file-reading capabilities under a specified base directory.
It manifests when:
- The server trusts a root or base directory constraint for access control
- Users or other components can create or influence files and symlinks within that directory
- The read_content tool relies on a pre-access path validation step that does not account for symlink resolution
In such setups, the protection boundary built around the "allowed directory" can be silently bypassed by symlinks pointing elsewhere on the filesystem.
Exploit preconditions
- Attack surface: The read_content tool endpoint or interface exposed by the filesystem MCP server.
- Required access: Ability to invoke read_content with controllable paths inside the allowed directory; practical exploitation is easier if the attacker can create or modify files or symlinks within that directory.
- Trigger point: Supplying a path that appears valid during initial path checks but includes or targets a symlink that ultimately resolves outside the allowed directory when fs.readFile is executed.
- Why exploitation is possible: The resolvePath function validates the requested path before symlinks are resolved, while the underlying filesystem operations automatically follow symlinks at read time, breaking the assumption that "validated paths" remain confined to the approved directory tree.
Why this happens
The core issue is a mismatch between logical path validation and actual filesystem resolution semantics.
The resolvePath function enforces a directory boundary check on the raw or partially normalized path but does so without resolving symbolic links.
When fs.readFile is later called, the operating system transparently follows any symlinks, potentially leading to a final path outside the intended base directory.
This pattern maps to CWE-23: Relative Path Traversal, where user-influenced paths (including symlink chains) are insufficiently constrained, allowing traversal outside an intended directory sandbox.
Conceptually, the bug is a trust error in path normalization logic: the application assumes that a pre-validated path remains within a safe area, while the actual filesystem behavior can redirect access through symlinks.
Potential impact
- Unauthorized reading of sensitive files outside the configured base directory (e.g., configuration files, secrets, logs).
- Exposure of system-level information that can aid further attacks (user data, environment details, application internals).
- Bypass of logical sandbox or tenant-isolation boundaries implemented via directory restrictions.
- Potential privacy or compliance violations if protected data becomes accessible through the MCP interface.
General mitigation guidance
Effective mitigation focuses on aligning path validation with actual filesystem resolution and treating all user-influenced paths as untrusted:
- Resolve symlinks before enforcing directory constraints by using canonical/real paths (e.g., realpath-like behavior) for validations.
- Enforce that the fully resolved path is still a descendant of the configured base directory, rejecting any request that escapes this root.
- Consider disallowing or restricting symlink usage within the allowed directory when it is used as a security boundary.
- Treat the filesystem sandbox as a privilege boundary and apply least-privilege principles to what the MCP server user account can read at the OS level.
- Centralize path handling logic in a small, well-reviewed utility instead of scattering path checks across the codebase, ensuring consistent, secure-by-default behavior.
How teams detect issues like this
Organizations can identify this class of issue by:
- Static analysis and code scanning:
- Flagging custom path-validation helpers that do not incorporate symlink resolution.
- Searching for combinations of manual path checks (string prefix checks, naive joins) followed by filesystem APIs that automatically resolve symlinks.
- Code review practices:
- Reviewing any code that implements "allowed directory" or sandbox constraints around file operations.
- Verifying that path validation uses canonical paths and that post-resolution paths are checked against the base directory.
- Treating the presence of symlink handling logic (or lack thereof) as a red flag around security-sensitive file access.
- Policy and tooling:
- Enforcing secure path-handling patterns through internal libraries and linting rules.
- Using automated review tools or SAST engines configured with rules for directory traversal and symlink misuse.

