Summary
A path traversal vulnerability in the is_path_allowed function of server.py in filesystem-mcp-server 1.0.0 allows attackers to read from or write to files outside the intended directory.
When remote requests can influence file paths for the read/write tools, an attacker may escape the sandboxed root and access arbitrary locations on the host filesystem.
Affected context
This issue affects deployments using filesystem-mcp-server 1.0.0 where:
- The
read_file_tooland/orwrite_file_toolinserver.pyare exposed over a network API. - The server relies on
is_path_allowedto enforce which filesystem paths can be accessed. - Client-controlled input (e.g., request parameters or tool arguments) is used to build file paths.
In such environments, incomplete normalization or validation in is_path_allowed can allow directory traversal outside the intended base path.
Exploit preconditions
- Attack surface: Remote interface of the filesystem MCP server (e.g., HTTP, RPC, or tool protocol endpoint).
- Required access: Ability to invoke the read/write tools and supply arbitrary or partially controlled file paths.
- Trigger point: Calls to
read_file_toolorwrite_file_toolthat pass user-supplied paths throughis_path_allowed. - Why exploitation is possible: The path validation logic does not fully neutralize traversal sequences (such as
../) or alternate path encodings, allowing paths that resolve outside the restricted directory to be treated as allowed.
Why this happens
The root cause is insufficient path canonicalization and validation in the is_path_allowed function, which is responsible for checking whether a requested path is within an allowed directory.
Instead of validating against a fully normalized, absolute path and enforcing a strict directory boundary, the implementation likely relies on string operations or incomplete checks.
This maps directly to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where attackers can craft path values that escape the intended root and reach arbitrary filesystem locations.
Potential impact
- Read access to sensitive files on the server (e.g., configuration files, keys, logs, or user data).
- Unauthorized modification or deletion of files if the write tool is exposed and reachable.
- Indirect execution of code if an attacker can overwrite scripts, configuration, or data consumed by other processes.
- Expanded attack surface for further compromise by harvesting credentials or environment secrets stored on disk.
General mitigation guidance
Effective mitigation centers on strict path normalization and enforcement of directory boundaries:
- Resolve all user-supplied paths to absolute, canonical form before any access checks and file operations.
- Enforce that the canonical path is a descendant of an explicitly configured base directory (e.g., by comparing path prefixes using filesystem-aware APIs rather than string concatenation).
- Reject or sanitize inputs containing traversal patterns, ambiguous encodings, or disallowed characters.
- Limit the server process to least-privilege filesystem permissions so even successful traversal attempts are constrained.
- Consider implementing an explicit allowlist for accessible directories or file types, and deny all access by default.
How teams detect issues like this
Detection usually involves both code-focused and behavior-focused approaches:
- Static analysis: Scan for manual string-based path checks (e.g., naive
startswithon paths, direct concatenation of base path + user input) and missing canonicalization before access. - Code review: Look for functions like
is_path_allowedthat enforce sandbox boundaries and verify they use secure, canonical path comparison patterns and a well-defined base directory. - Runtime monitoring: Inspect server logs for suspicious paths containing
../, absolute paths where only relative paths are expected, or attempts to access system directories. - Automated testing: Add security test cases that attempt directory traversal with varying encodings and path tricks to validate that the sandbox cannot be escaped.

