Severity:

HIGH RISK

(7.3)

Path Traversal in matlab-mcp-server MCP Interface Code

CVE-2026-7272

Deferred

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Access and Potential Remote Code Execution

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

matlab-mcp-server contains a path traversal vulnerability in the MCP Interface functions generate_matlab_code / execute_matlab_code, where the scriptPath argument is insufficiently validated.

By manipulating scriptPath, a remote attacker may traverse directories on the server and access or execute files outside the intended workspace, especially when the application builds or runs MATLAB scripts based on this path.

Affected context

This vulnerability occurs in the MCP Interface of matlab-mcp-server, specifically in src/index.ts within the generate_matlab_code and execute_matlab_code functions.

It is relevant when:

  • The server accepts a scriptPath value from a remote client or integration,
  • The value is used to build filesystem paths for reading, writing, or executing MATLAB scripts,
  • And there is no robust normalization, canonicalization, or restriction to a trusted base directory.

In such deployments, directory traversal sequences (such as parent-directory references) may allow access to files outside the expected MATLAB project or workspace.

Exploit preconditions

  • Attack surface: Network-exposed MCP Interface endpoints that accept scriptPath as an argument.
  • Required access: Ability to send requests to the matlab-mcp-server instance (remote client or integrated tool with network connectivity).
  • Trigger point: Any call path that passes attacker-controlled scriptPath into generate_matlab_code or execute_matlab_code, leading to filesystem operations.
  • Why exploitation is possible:
  • The implementation trusts the scriptPath value and combines it with filesystem locations without enforcing a strict root or performing security-focused path normalization.
  • As a result, directory traversal tokens (e.g., ../) can escape the intended directory and point to arbitrary locations on the server.

Why this happens

The underlying flaw aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

The MCP Interface functions generate_matlab_code and execute_matlab_code appear to:

  • Accept a user-controllable scriptPath,
  • Concatenate or otherwise incorporate it directly into a filesystem path,
  • And then read, write, or execute files based on that resulting path.

Without enforcing that scriptPath resolves within a specific base directory or validating against directory traversal patterns on a canonicalized path, the code effectively delegates directory selection to the client.

This pattern allows an attacker to reference files outside the intended MATLAB scripts directory, and in some configurations, to influence what code is generated or executed.

Potential impact

  • Access to files outside the intended MATLAB project or workspace directory.
  • Reading sensitive files that the server process can access (e.g., configuration files, credentials, logs).
  • Overwriting or creating files in directories reachable by the server process, potentially leading to data corruption.
  • Indirect remote code execution if the attacker can cause untrusted MATLAB or script content to be written and then executed.
  • Escalation of impact when combined with other vulnerabilities or insecure deployment practices (e.g., writable directories on the executable search path).

General mitigation guidance

Effective mitigation focuses on constraining how paths derived from client input are used and reducing trust in remote-controlled path parameters:

  • Enforce a fixed base directory: Resolve all script operations relative to a single, predefined root directory for MATLAB scripts; reject any path that attempts to escape it.
  • Canonicalize paths before validation: Use a secure, platform-aware method to normalize and resolve scriptPath to an absolute path, then verify that it remains under the allowed base directory.
  • Reject unsafe patterns: As a defense-in-depth measure, block obvious traversal tokens (e.g., ../, absolute paths, drive letters) and disallow null bytes or other control characters in path values.
  • Use whitelisting or resource identifiers: Where possible, reference scripts by logical IDs or known filenames rather than accepting arbitrary filesystem paths from the client.
  • Run with least privilege: Configure the matlab-mcp-server process to run under an account and with filesystem permissions that restrict which directories it can read or write, limiting damage if a path traversal occurs.
  • Isolate execution environments: Use sandboxing or isolated working directories for code generation and execution, to keep sensitive system and application files out of reach.

How teams detect issues like this

Detection can combine code-level analysis with operational monitoring:

  • Static analysis patterns:
  • Search for uses of scriptPath in path-building code (e.g., path.join, string concatenation with / or \) without subsequent checks against a base directory.
  • Flag any filesystem operations (readFile, writeFile, exec or MATLAB invocation routines) that accept variables sourced directly from network input or request parameters.
  • Add custom rules to static analysis tools to detect user-controlled input flowing into path operations without canonicalization and boundary checks.
  • Code review signals:
  • Paths constructed from request properties or parameters in src/index.ts and related modules.
  • Absence of centralized helper functions for safe path resolution.
  • Any conditional checks that only filter substrings but do not operate on canonical paths.
  • Runtime and log monitoring:
  • Monitor logs for requests containing suspicious path sequences (e.g., ../, ..\\, URL-encoded traversal).
  • Enable application logging around path resolution logic to capture abnormal or cross-directory access attempts.
  • Security testing and policies:
  • Include directory traversal test cases in automated API security tests against the MCP Interface.
  • Use automated review tools or CI checks to enforce use of safe path utility functions and disallow direct concatenation of filesystem paths from user input.

Sources

SourceLink
github.comgithub.com/BruceJqs/public_exp/issues/18
github.comgithub.com/WilliamCloudQi/matlab-mcp-server/
github.comgithub.com/WilliamCloudQi/matlab-mcp-server/issues/8
vuldb.comvuldb.com/submit/802911
vuldb.comvuldb.com/vuln/359927
vuldb.comvuldb.com/vuln/359927/cti

Frequently asked

questions

Yes. The description indicates that the attack can be executed remotely when a client can reach the MCP Interface and supply a crafted scriptPath argument in API calls.

An attacker needs network-level access to the matlab-mcp-server instance or any upstream service that forwards requests to its MCP Interface endpoints. No local shell access is required, but any application-level authentication or authorization implemented by the deployment must be bypassed or legitimately obtained.

The safest pattern is to resolve all script operations against a fixed, known base directory, canonicalize the requested path, and then verify that the result remains within that directory before any filesystem access or execution occurs. Ideally, replace free-form path parameters with controlled identifiers or a whitelist of allowed script locations.

Treat all path components from clients as untrusted, enforce centralized safe path-handling utilities, and integrate static analysis and security review specifically targeting path construction and file access layers. Combine this with least-privilege filesystem permissions and regular security testing for directory traversal in all file-handling endpoints.

Find out what's already
exploitable in your codebase.