NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · Other MCP servers and tools

CVE-2025-54994: @akoskm/create-mcp-server-stdio is vulnerable to MCP Server Command Injection through `exec` API

criticalCVSS 4.0 9.3GHSA-3ch2-jxxc-v4xf

The which-app-on-port tool in @akoskm/create-mcp-server-stdio before 0.0.13 builds shell commands with Node.js exec and the port argument. A prompt-injected AI client could run extra shell commands on the host. The fix, in 0.0.13, switches to execFile with argument arrays.

Published Sep 8, 2025 · Updated Sep 10, 2025 · Analysis Nov 1, 2026

What an attacker can do

The tool runs lsof -t -i tcp:${port} and then ps -p ${pid} -o comm= through child_process.exec, which hands the whole string to a shell. If the value carries shell characters such as a semicolon, the shell runs whatever follows. The advisory example payload is ; rm -rf /tmp;#.

The attacker is not the person at the keyboard. The advisory describes an LLM tricked by prompt injection into calling the tool with hostile input, for example through a web page, document or issue text that the agent reads. The server then runs the commands with the developer permissions on the machine hosting it: files, tokens and SSH keys are in reach.

One detail to know: the tool schema in the shown code declares port as a z.number(), which should reject text values in a validating client or server. The advisory still rates the flaw Critical and describes it as exploitable through the tool, so treat it as real until you run the fixed version. The code is a starter template, so projects generated from it may carry the same pattern.

Who is affected

Affected: @akoskm/create-mcp-server-stdio below 0.0.13, and any server you created from this template that still has the exec-based which-app-on-port tool. Check the package:

npm ls @akoskm/create-mcp-server-stdio

Then search your own code for the pattern:

grep -rn "lsof -t -i tcp" src

@akoskm/create-mcp-server-stdio

Ecosystem
npm
Affected
< 0.0.13
Fixed in
0.0.13
Check
npm ls @akoskm/create-mcp-server-stdio

How to fix it

Upgrade to @akoskm/create-mcp-server-stdio 0.0.13.

npm install @akoskm/[email protected]

The fix commit replaces both exec calls with execFile, passing lsof and ps their arguments as arrays, so the shell never parses them. The advisory recommends execFile over exec, and the -- separator when the input is not a flag. For servers you built from the template, make the same change by hand.

How to tell if you were hit

Check shell history and process logs on the host for lsof or ps child processes of the MCP server that are followed by other commands, and for files deleted or created under /tmp. Review the MCP tool call log for which-app-on-port calls with a port value that contains non-digit characters. Beam records MCP tool calls and agent shell commands, and its rules flag risky ones, so you can see what an agent asked this tool to run.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Command Injection in MCP Server

The MCP Server at https://github.com/akoskm/create-mcp-server-stdio is written in a way that is vulnerable to command injection vulnerability attacks as part of some of its MCP Server tool definition and implementation.

Vulnerable tool

The MCP Server exposes the tool which-app-on-port which relies on Node.js child process API exec which is an unsafe and vulnerable API if concatenated with untrusted user input.

Vulnerable line of code: https://github.com/akoskm/create-mcp-server-stdio/blob/main/src/index.ts#L24-L40

server.tool("which-app-on-port", { port: z.number() }, async ({ port }) => {
  const result = await new Promise<ProcessInfo>((resolve, reject) => {
    exec(`lsof -t -i tcp:${port}`, (error, pidStdout) => {
      if (error) {
        reject(error);
        return;
      }
      const pid = pidStdout.trim();
      exec(`ps -p ${pid} -o comm=`, (error, stdout) => {
        if (error) {
          reject(error);
          return;
        }
        resolve({ command: stdout.trim(), pid });
      });
    });
  });

Exploitation

When LLMs are tricked through prompt injection (and other techniques and attack vectors) to call the tool with input that uses special shell characters such as ; rm -rf /tmp;# (be careful actually executing this payload) and other payload variations, the full command-line text will be interepted by the shell and result in other commands except of ps executing on the host running the MCP Server.

Reference example from prior security research on this topic:

Cursor defined MCP Server vulnerable to command injection

Impact

User initiated and remote command injection on a running MCP Server.

Recommendation

  • Don't use exec. Use execFile instead, which pins the command and provides the arguments as array elements.
  • If the user input is not a command-line flag, use the -- notation to terminate command and command-line flag, and indicate that the text after the -- double dash notation is benign value.

References and Prior work

  1. Exploiting MCP Servers Vulnerable to Command Injection
  2. Liran's Node.js Secure Coding: Defending Against Command Injection Vulnerabilities

##

Disclosed by Liran Tal

Credited to lirantal.

Questions

Who is the attacker here?

Someone who can get text in front of the AI client, for example a web page, a document or an issue. The text makes the model call which-app-on-port with a shell payload.

What fixes CVE-2025-54994?

Version 0.0.13 of @akoskm/create-mcp-server-stdio, which uses execFile with argument arrays instead of exec with a command string.

Should I check servers built from this template?

Yes. If your server copied the exec-based which-app-on-port code, it has the same flaw and needs the same change to execFile.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More Other MCP servers and tools vulnerabilities

All Other MCP servers and tools entries