惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
L
LangChain Blog
Jina AI
Jina AI
博客园 - 叶小钗
B
Blog RSS Feed
Recent Announcements
Recent Announcements
H
Help Net Security
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
B
Blog
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客

NodeJS Security & NodeJS Secure Coding's Blog

Hardening Your npm and pnpm Configs in the Age of Shai-Hulud Argument Injection vulnerability in git-blame@1.4.0 Argument Injection vulnerability in `gits@0.1.8` Command Injection vulnerability in `@fab1o/git@1.4.0` Command Injection vulnerability in `git-contributors` via unsanitized CLI arguments Command Injection vulnerability in `git-q@0.0.3` Command injection vulnerability via unsanitized CLI arguments in touxing/fast-git-clone Command Injection vulnerability in `willitmerge@0.2.1` Mastering NPX: A Cheatsheet for npm and Node.js Power Users Mitigate Supply Chain Security with DevContainers and 1Password for Node.js Local Development The Tale of the Vulnerable MCP Database Server Bad Security Defaults in Mastra AI Frameworks Templates SQL Injection and Bypassing "Read-Only" Mode in Xata's MCP Server Security Advisory for qix npm supply-chain compromise affecting debug and billions of weekly download users How to Mitigate SQL Bypass in MCP Servers Enhancing MCP Server Security: A Guide to Using execFile Argument Injection Vulnerability in ggit How to Bypass Access Control in PostgreSQL in Simple PSQL MCP Server for SQL Injection Command Injection Flaws in ggit: Unveiling a Vulnerability Command Injection Vulnerability in Create MCP Server STDIO Tool Exposes System Monitoring Functions GitHub Kanban MCP Server Command Injection Vulnerability Threatens Developer Workflows Critical Command Injection Flaw in iOS Simulator MCP Server Exposes Development Environments Command Injection Vulnerability Discovered in Codehooks MCP Server: A Critical Security Analysis SSRF Shenanigans in safe-axios: Redirects Open the Backdoor SSRF Vulnerability in safe-axios: Unintended Public Address Classification Bypassing SSRF Safeguards in ssrfcheck: A Case of Incomplete Denylists Don't Be Fooled by Multicast, SSRF Bypass in private-ip Node.js Authentication from Lucia to Better Auth Bypassing SSRF Protection in nossrf: When Your Safeguards Become Loopholes Vue CLI Security Fix to Mitigate NPM Binary Planting
A Directory Traversal Vulnerability I found in Mastra AI ...
2025-09-29 · via NodeJS Security & NodeJS Secure Coding's Blog

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:

    {

    "mcpServers": {

    "mastra": {

    "command": "npx",

    "args": ["-y", "@mastra/mcp-docs-server"]

    }

    }

    }

  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:

    const result = await readMdxContent(path, queryKeywords);

    if (!result.found) {

    return {

    path,

    content: null,

    error: "Path not found or access denied.",

    };

    }

  2. Defense-in-Depth: Apply path validation logic to the findNearestDirectory function to ensure it cannot operate outside the intended base directory.

CVE Details

  • Recommended CWE: CWE-548: Exposure of Information Through Directory Listing, resulting from an incomplete fix for CWE-22: Improper Limitation of a Pathname to a Restricted Directory (‘Path Traversal’).
  • Recommended CVSS: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N

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.