The vulnerability is a classic command injection flaw within the @serverless/mcp package, specifically in the list-projects tool. The root cause is the use of child_process.exec to run a find command on the filesystem, where the directory path is taken directly from user input without sanitization.
The execution flow starts at the listProjects function, which receives an array of workspaceRoots from the user. This input is passed to getServerlessProjectsInfo, which in turn calls findServerlessFrameworkProjects and other finders that use findYamlFiles. The findServerlessFrameworkProjects and findYamlFiles functions in packages/mcp/src/lib/project-finder.js are the core of the vulnerability. They concatenate the user-provided path into a shell command string, allowing an attacker to inject shell metacharacters (e.g., $(command)) and achieve remote code execution.
The provided patch confirms this analysis. It replaces all calls to child_process.exec with child_process.execFile, which safely passes the directory path as an argument instead of interpreting it as part of the command. Additionally, a new validateWorkspaceDir function was added to ensure the provided path is a valid directory, providing defense-in-depth.