← 返回列表

A Directory Traversal Vulnerability I found in Mastra AI Frameworks MCP Server

单站 Node.js Security 发布 Mon, 29 Sep 2025 00:00:00 GMT 入库 2026-11-17T04:09:36

\~ 3 min read

A Directory Traversal Vulnerability I found in Mastra AI Frameworks MCP Server

MCP Servers are increasingly popular for AI-driven workflows. However, I discovered a directory traversal vulnerability in the Mastra AI Frameworks MCP Server that could expose sensitive information. This article explores the flaw, its exploitation, and mitigation strategies.

This is a write-up on a security advisory that I disclosed to the Mastra AI framework and their MCP Server that serves documentation and was found to be vulnerable to directory traversal vulnerability. The affected Mastra AI component is the MCP Server project available as an npm package: @mastra/mcp-docs-server.

The @mastra/mcp-docs-server package, a critical component for AI-driven documentation workflows, has been identified to contain a directory traversal vulnerability in versions 0.13.18 and below. This flaw allows unauthorized directory listing, potentially exposing sensitive information. This advisory details the vulnerability, its exploitation, impact, and recommended mitigations.

mastra ai framework cve information exposure and path traversal

Technical Root Cause

The vulnerability stems from a logical flaw in the execute function of the @mastra/mcp-docs-server package. Although the readMdxContent function includes a security check to prevent path traversal, this check is bypassed due to subsequent logic that attempts to find directory suggestions without proper validation.

Code Analysis

The readMdxContent function attempts to validate paths:

async function readMdxContent(docPath: string, queryKeywords: string[]): Promise<ReadMdxResult> { const fullPath = path.resolve(path.join(docsBaseDir, docPath)); if (!fullPath.startsWith(path.resolve(docsBaseDir))) { void logger.error(`Path traversal attempt detected`); return { found: false }; } // ...}
However, the execute function continues processing even when a path traversal is detected:

execute: async (args: DocsInput) => {  // ...  const result = await readMdxContent(path, queryKeywords);  if (result.found) {    return { /* ... */ };  }
  // VULNERABILITY: This code executes even after a path traversal attempt is detected  const directorySuggestions = await findNearestDirectory(path, availablePaths);  const contentBasedSuggestions = await getMatchingPaths(path, queryKeywords, docsBaseDir);  return {    path,    content: null,    error: [directorySuggestions, contentBasedSuggestions].join('\n\n'),  };}

This oversight allows the use of unvalidated paths for directory listing, effectively nullifying the initial security check.

Exploitation

An attacker can exploit this vulnerability through prompt injection in AI coding assistants like Cursor IDE. By crafting a prompt that instructs the AI agent to use a traversal path, the attacker can trick the tool into listing directories outside its intended scope.

Proof of Concept

  1. Configure Cursor IDE: Define the Mastra MCP server in the .cursor/mcp.json file:
  2. Enable the MCP server within the IDE.
  3. Initiate a new chat and use a malicious prompt to exploit the vulnerability.
  4. Observe the output, which will contain the directory listing from the root of the user’s home directory.

Following is a video demonstration of the exploitation process:

Recommendation

To mitigate this vulnerability, the following changes are recommended:

  1. Halt Execution on Failure: Modify the execute function to stop processing if a path traversal is detected:
  2. Defense-in-Depth: Apply path validation logic to the findNearestDirectory function to ensure it cannot operate outside the intended base directory.

CVE Details

Credit

This vulnerability was disclosed by Liran Tal, a recognized expert in application security and open-source tooling.

References

For further updates and security research, follow Liran Tal on Twitter and explore more on GitHub.

原文链接:https://www.nodejs-security.com/blog/directory-traversal-vulnerability-in-mastra-ai-frameworks-mcp-server/