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

推荐订阅源

量子位
Vercel News
Vercel News
Google DeepMind News
Google DeepMind News
罗磊的独立博客
WordPress大学
WordPress大学
The Cloudflare Blog
GbyAI
GbyAI
The Register - Security
The Register - Security
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog
A
About on SuperTechFans
U
Unit 42
T
The Blog of Author Tim Ferriss
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
Blog — PlanetScale
Blog — PlanetScale
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
T
The Exploit Database - CXSecurity.com
T
Tor Project blog
A
Arctic Wolf
H
Hacker News: Front Page
NISL@THU
NISL@THU
F
Full Disclosure
雷峰网
雷峰网
L
LINUX DO - 热门话题
Recent Announcements
Recent Announcements
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
Google Online Security Blog
Google Online Security Blog
I
InfoQ
Webroot Blog
Webroot Blog
S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
博客园 - Franky
V
Vulnerabilities – Threatpost
博客园 - 【当耐特】
Latest news
Latest news

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 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 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 An Introduction to Command Injection Vulnerabilities in Node.js and JavaScript
Securing Your Node.js Apps by Analyzing Real-World Command Injection Examples
2023-09-15 · via NodeJS Security & NodeJS Secure Coding's Blog

In the vast digital landscape of web applications and online services, security is paramount. Developers and organizations invest significant resources to safeguard their systems from potential threats, but the ever-evolving nature of cyber attacks poses a constant challenge. One particularly dangerous and repeated vulnerability that has garnered many CVEs disclosed for npm packages in the Node.js ecosystem in recent years is that of Command Injection.

Command Injection Vulnerabilities: A Lurking Threat

Command injection vulnerabilities are not an abstract concept but a real and prevalent threat in the Node.js ecosystem.

What is seemingly an obvious security risk such as demonstrated in this code:

var exec = require('child_process').execSync;

var platform = require('os').platform();

module.exports = function () {

var commands = Array.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.apply(arguments);

var command = null;

commands.some(function (c) {

if (isExec(findCommand(c))) {

command = c;

return true;

}

});

return command;

};

function isExec(command) {

try {

exec(command, { stdio: 'ignore' });

return true;

} catch (_e) {

return false;

}

}

function findCommand(command) {

if (/^win/.test(platform)) {

return 'where ' + command;

} else {

return 'command -v ' + command;

}

}

Is actually an often overlooked coding practice by JavaScript developers day to day.

The above command injection vulnerability was found in the find-exec npm package with as many as over 2,000 weekly downloads. Not too many, but enough to put some users at risk. The consequences of command injection vulnerabilities can be devastating, ranging from data breaches to complete system compromise.

What Is Command Injection? In short, at its core, command injection occurs when an application allows unsanitized user input to be executed as system commands. These commands can manipulate the underlying system, potentially leading to unauthorized access, data breaches, or even complete system compromise.

Real-world Examples of Command Injection Vulnerabilities

To truly understand the severity of command injection vulnerabilities and the urgency of addressing them, we must examine real-world examples. While theoretical discussions and abstract concepts are valuable, nothing drives the point home like concrete instances where open-source npm packages were found vulnerable to command injection due to insecure coding.

1. The Equifax Data Breach (2017)

Affected Application: Apache Struts2 framework used by Equifax Attack Vector: Command injection via unpatched vulnerability Outcome: One of the most significant data breaches in history, exposing sensitive personal and financial data of nearly 147 million people.

Details: The Equifax breach serves as a sobering reminder of the potential impact of command injection vulnerabilities. Attackers exploited a known vulnerability in Apache Struts2 to execute arbitrary commands on Equifax’s servers. This breach had far-reaching consequences, resulting in legal repercussions and widespread public concern.

Guy Podjarny, Snyk’s Co-founder and president wrote an analysis on how open source vulnerabilities tripped Equifax and suggesting the adoption of Software Composition Analysis (SCA) tools such as Snyk to mitigate risks of vulnerable open-source dependencies, that may introduce command injection vulnerabilities. A year later, Simon Maple, heading up the AI Advocacy at Snyk, wrote a follow-up article on how Equifax could have prevented the breach.

2. Shellshock Vulnerability (2014)

Affected Application: GNU Bash (a common Unix shell) Attack Vector: Command injection via environment variables Outcome: Widespread vulnerability impacting millions of Unix-based servers and systems.

Details: The Shellshock vulnerability showcased the global reach of command injection. Attackers exploited flaws in the way Bash processed environment variables to execute arbitrary code. This incident underscored the importance of timely software updates and patch management.

Joey Holliday’s write-up on the Shellshock vulnerability in his shellshock GitHub repository is a recommended step-by-step breakdown of the vulnerability and its impact.

3. Yahoo Data Breach (2013-2014)

Affected Application: Yahoo Mail Attack Vector: Command injection via specially crafted email attachments Outcome: Massive data breach involving the compromise of over three billion Yahoo accounts.

Details: Yahoo’s data breach was a result of command injection vulnerabilities introduced through malicious email attachments. The breach’s scale and severity highlight the need for robust input validation and secure email handling.

4. ImageTragick: The ImageMagick Vulnerability (2016)

Affected Application: ImageMagick, a popular image processing library Attack Vector: Command injection via specially crafted image files Outcome: Potential system compromise of websites and servers using ImageMagick for image processing.

Details: A command injection vulnerability, known as ImageTragick in allowed attackers to execute arbitrary code by manipulating image files. This incident serves as a reminder that vulnerabilities can lurk in unexpected places, emphasizing the need for thorough code audits.

5. Cisco ASA Vulnerability (2018)

Affected Application: Cisco Adaptive Security Appliance (ASA) Attack Vector: Command injection via VPN login fields Outcome: Exposure of sensitive VPN configuration data.

Details: A command injection vulnerability in Cisco ASA devices allowed attackers to execute commands through the VPN login page. This incident highlights the critical importance of securing network infrastructure against command injection threats.

These real-world examples underscore the severity and ubiquity of command injection vulnerabilities. By studying cases of vulnerable npm packages, Node.js developers can better grasp the implications of insecure coding practices and implement measures to protect their applications. For that end, Liran Tal authored the book that follows those exact practical hands-on secure coding practices: Node.js Secure Coding: Defending Against Command Injection Vulnerabilities.

Case Study - fs-git Command Injection Vulnerability

Let’s dive into a detailed analysis of a real-world command injection vulnerability that affected the fs-git npm package, version 1.0.1. This case study sheds light on how a seemingly innocuous module can become a critical security risk when command injection vulnerabilities are present. We will explore the background of the application, delve into the specifics of the vulnerability, and examine the consequences it wrought.

fs-git is an npm package for Node.js designed to provide a file system-like API for Git repositories. It aims to make interacting with Git repositories more intuitive and accessible for developers. As a module intended to simplify Git-related tasks, it garnered a user base that included a wide range of developers and projects.

The vulnerability we’re investigating here is identified as CVE-2017-1000451 and was discovered in the fs-git module, version 1.0.1. This module relies on the child_process.exec function to execute system commands. However, the buildCommand method used to construct the exec strings lacked proper data sanitization, making it vulnerable to command injection.

Snippet of the vulnerable code in fs-git:

showRef(): Promise<RefInfo[]> {

let command = this._buildCommand("show-ref");

return new Promise((resolve: (value: RefInfo[]) => void, reject: (error: any) => void) => {

child_process.exec(command, { maxBuffer: maxBuffer }, (error, stdout, stderr) => {

if (error) {

reject(error);

} else {

let list = stdout.toString("utf8").split("\n").filter(line => !!line);

let resultList: RefInfo[] = list.map(str=> {

let columns = str.split(" ", 2);

return {

gitDir: this.path,

ref: columns[0],

name: columns[1]

};

});

resolve(resultList);

Eventually, the code would also call the _buildCommand function with string concatenation mixed with user-provided data:

_buildCommand(...args: string[]): string {

return `git --git-dir=${this.path} ${args.join(" ") }`;

The attack unfolded when an attacker manipulated data passed to the fs-git module to craft malicious inputs that exploited the command injection vulnerability. By providing carefully crafted inputs, the attacker was able to inject arbitrary commands into the system. This allowed them to execute unauthorized commands with the privileges of the running process, potentially compromising the host system.

The consequences of this vulnerability were far-reaching. Attackers could execute arbitrary commands, which might include actions like exfiltrating sensitive data, modifying files, or even disrupting the normal operation of the system. For projects and applications relying on fs-git, this vulnerability posed a significant security risk.

The fs-git case study highlights the critical importance of input validation and data sanitization in preventing command injection vulnerabilities. Even seemingly innocuous modules can introduce severe security risks if they do not follow secure coding practices. Developers and maintainers must exercise caution when dealing with user-provided data and always employ best practices for data validation and sanitization.

Additional Resources to Command Injection Vulnerabilities

In this blog post, we set out to explore the ins and outs of command injection vulnerabilities in Node.js applications. We dissected real-world examples, delved into the intricacies of how these vulnerabilities occur, and analyzed the devastating consequences they can unleash.

Now, as you grasp the significance of securing your Node.js applications against command injection, it’s time to take action. The world of application security is ever-evolving, and it demands vigilance and expertise to safeguard your projects.

For those of you who are eager to dive deeper into the realm of secure coding and fortify your Node.js applications, I have an invaluable resource to offer:

Introducing Node.js Secure Coding: Defending Against Command Injection Vulnerabilities 🦄

My book provides a comprehensive guide to understanding, identifying, and mitigating command injection vulnerabilities in Node.js. With practical insights, real-world examples of vulnerable npm packages, and expert guidance, this book equips you with the knowledge and skills needed to bolster your application’s security.

Don’t leave your Node.js applications vulnerable to attacks. Gain the expertise you need to protect your projects and your users. Get your copy of “Node.js Secure Coding: Defending Against Command Injection Vulnerabilities” today by visiting https://www.nodejs-security.com.

With the knowledge you acquire from this book, you’ll not only enhance your development skills but also contribute to a more secure and resilient software landscape. Thank you for joining us on this journey, and I look forward to seeing you in the world of secure coding.