Severity:

HIGH RISK

(7.3)

Path Traversal in code-mcp MCP File Handler is_safe_path

CVE-2026-7811

Deferred

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File System Access

Severity:

HIGH RISK

(7.3)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A path traversal vulnerability in the is_safe_path function of the MCP File Handler component in 54yyyu code-mcp allows attackers to bypass directory restrictions and access arbitrary filesystem locations.

When the server processes crafted file-related requests, an attacker can leverage weak path validation to read or potentially manipulate files outside the intended root, over a remote interface.

Affected context

The issue occurs in deployments of the code-mcp server that expose the MCP File Handler over a network and rely on is_safe_path to enforce which files or directories can be accessed.

The vulnerability is present when the application:

  • Accepts user-controlled paths (e.g., file open, save, list operations) via a remote endpoint or protocol, and
  • Uses is_safe_path to decide whether a given path is within an allowed directory, and
  • Does not apply additional sandboxing or OS-level confinement around the file operations.

In such setups, path normalization or validation inside is_safe_path is insufficient to prevent traversal via sequences like parent directory references or equivalent encodings.

Exploit preconditions

  • Attack surface: Remote, via the MCP File Handler API or any endpoint that routes file operations through is_safe_path.
  • Required access: Ability to send crafted requests to the code-mcp server (typically network access to the service; authentication requirements depend on the deployment).
  • Trigger point: Any operation that:
  • Accepts a file path from the client, and
  • Calls is_safe_path to determine if the path is allowed, and
  • Proceeds to access the filesystem based on the result.
  • Why exploitation is possible: The is_safe_path implementation does not robustly canonicalize and constrain paths against a designated root directory. As a result, attackers can inject traversal sequences (such as parent directory references or encoded equivalents) that are incorrectly treated as safe, allowing access outside the intended sandbox.

Why this happens

This vulnerability is rooted in insufficient path validation logic, as described by CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

The is_safe_path function likely performs naive checks—such as string prefix comparison, incomplete normalization, or assumptions about path separators—without fully resolving the input path to its canonical absolute form and strictly enforcing that it remains under an allowed base directory.

When user-supplied paths are trusted based on these incomplete checks, directory traversal tokens (e.g., .. components, symbolic links, encoded separators) can be used to escape the intended directory and target arbitrary files, while still passing the flawed "safe path" test.

Potential impact

  • Unauthorized reading of sensitive files that the service account can access (e.g., configuration files, logs, environment files).
  • Exposure of credentials, API keys, or secrets stored on the filesystem.
  • Overwriting or deletion of files, if the affected operations support write or delete actions.
  • Collection of internal source code, data, or other intellectual property from the host.
  • Potential pivoting into further compromise if sensitive configuration or authentication data is disclosed.

General mitigation guidance

Effective mitigation revolves around strong path canonicalization, strict root enforcement, and defense-in-depth controls:

  • Resolve all user-supplied paths to their absolute, canonical form (resolving .., symbolic links, and redundant separators) before validation.
  • Enforce that the canonical path is strictly within a predefined root directory (e.g., checking via robust path APIs rather than string prefix checks).
  • Avoid building paths via direct string concatenation; instead, use platform-aware path utilities that help normalize input.
  • Restrict the runtime account of the service to the minimum required filesystem privileges, reducing the blast radius if traversal occurs.
  • Segregate sensitive files and secrets outside any directories that the MCP File Handler can access.
  • Consider application-level allowlists—limiting access to specific subdirectories or file types rather than arbitrary paths under a root.

How teams detect issues like this

Detecting this class of vulnerability typically combines code-centric review with behavioral monitoring:

  • Static analysis / code scanning:
  • Search for custom "safe path" validators (is_safe_path-style functions) that:
  • Use naive string checks (e.g., startswith, direct substring checks) to validate paths.
  • Do not call canonicalization utilities before enforcement.
  • Flag any file open/read/write/delete calls that accept user-influenced paths without strict rooting.
  • Code review heuristics:
  • Examine route handlers or RPC methods that pass request parameters directly into open, os.remove, directory listing, or similar APIs.
  • Look for use of .. filtering or simple blacklist approaches instead of canonical path comparison.
  • Runtime / operational monitoring:
  • Log file access paths for MCP File Handler operations and look for unexpected patterns, such as access outside the intended working directory or unusual traversal sequences.
  • Use host-level monitoring or EDR solutions to detect the service accessing sensitive system files (e.g., /etc/*, SSH keys, application secrets) that are not part of normal operation.
  • Automated security tools integrated into CI/CD pipelines can be configured with rules specifically targeting path traversal patterns and unsafe path manipulation.

Sources

SourceLink
github.comgithub.com/54yyyu/code-mcp/
github.comgithub.com/54yyyu/code-mcp/issues/4
vuldb.comvuldb.com/submit/807751
vuldb.comvuldb.com/vuln/361071
vuldb.comvuldb.com/vuln/361071/cti

Frequently asked

questions

Exploitability depends on where and how the MCP File Handler is exposed. If the code-mcp server is reachable over a network and handles file operations based on user-supplied paths, a remote attacker may exploit the flaw. Deployments that restrict access to trusted networks or require strong authentication reduce exposure but do not remove the underlying weakness.

No. The vulnerability is described as remotely exploitable. The attacker typically only needs the ability to send crafted requests to the endpoint that uses is_safe_path, subject to whatever authentication and network controls are in place.

Use a canonicalization-and-compare approach:

  • Convert incoming paths to absolute, canonical paths (resolving .., symlinks, and encodings).
  • Verify that the resulting path is a descendant of a designated root directory using robust path APIs, not string prefix checks.
  • Reject or sanitize any path that does not strictly remain under the allowed root before performing any filesystem operation.

Design file-handling interfaces around constrained operations rather than arbitrary paths:

  • Use stable identifiers or keys mapped to known filesystem locations, instead of raw paths from clients.
  • Apply strict allowlists for directories and file types.
  • Centralize path validation into well-tested utility functions and enforce their use via code review and linting rules.
  • Combine application-level validation with OS-level sandboxing and least-privilege accounts to limit damage even if a validation error slips through.
Find out what's already
exploitable in your codebase.