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

推荐订阅源

T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
雷峰网
雷峰网
量子位
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
博客园 - Franky
罗磊的独立博客
宝玉的分享
宝玉的分享
博客园_首页
腾讯CDC
The GitHub Blog
The GitHub Blog
D
DataBreaches.Net
IT之家
IT之家
D
Docker
Microsoft Security Blog
Microsoft Security Blog
博客园 - 司徒正美
V
V2EX
月光博客
月光博客
N
Netflix TechBlog - Medium
爱范儿
爱范儿
I
InfoQ
P
Proofpoint News Feed

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
Secure Coding Practices in Node.js Against Path Traversal...
2024-05-23 · via NodeJS Security & NodeJS Secure Coding's Blog

Path traversal vulnerabilities can grant attackers unauthorized access to your file system, potentially leading to data exfiltration, code execution, or server compromise.

In this article I want to mention secure coding practices to prevent these vulnerabilities and analyze real-world examples (CVE-2024-29180, CVE-2024-26150) to illustrate the impact and mitigation strategies.

Real-World Examples of Path Traversal Vulnerabilities

1. CVE-2024-29180: webpack-dev-middleware

This vulnerability resides in the webpack-dev-middleware package. Due to insufficient validation of user-supplied URLs, an attacker can exploit path traversal to access arbitrary files on the developer’s machine.

The following versions of webpack-dev-middleware are affected: version < 5.3.4, >= 6.0.0 < 6.1.2, >= 7.0.0 < 7.1.0

The impact is potential exfiltration of sensitive data (source code, configuration files), and server compromise if critical system files are accessed.

Here’s a Proof-of-Concept (POC) demonstrating the vulnerability:

// Vulnerable webpack configuration (writeToDisk: true)

module.exports = {

devServer: {

devMiddleware: {

writeToDisk: true,

},

},

};

// Malicious request to access /etc/passwd

curl localhost:8080/public/..%2f..%2f..%2f..%2f../etc/passwd

The vulnerable code snippet from the webpack-dev-middleware package:

// (webpack-dev-middleware source code)

getFilenameFromUrl(url) {

const publicPath = ...; // Public path configuration

const filePath = url.replace(publicPath, '');

return path.join(outputPath, filePath);

}

The fix is to upgrade to webpack-dev-middleware version 5.3.4 or later, which addresses this vulnerability.

2. CVE-2024-26150: @backstage/backend-common

This vulnerability affects the @backstage/backend-common package. Flawed symlink checks in the resolveSafeChildPath function allow path traversal attacks.

The backstage/backend-common affected version range is: < 0.19.10, >= 0.20.0-next.0 < 0.20.2, >= 0.21.0-next.0 < 0.21.1.

The impact on vulnerable backstage package verssions is unauthorized access to files outside the intended directory.

The following is the vulnerable code snippet from the @backstage/backend-common package:

const targetPath = resolvePath(base, path);

if (!isChildPath(resolveRealPath(base), resolveRealPath(targetPath))) {

throw new NotAllowedError(

'Relative path is not allowed to refer to a directory outside its parent',

);

}

Here too, the fix is to upgrade to @backstage/backend-common version 0.19.10 or later, which includes a fix for this vulnerability.

JavaScript Secure Coding Principles

By adhering to secure coding practices and staying updated on vulnerable package versions, you can significantly reduce the risk of path traversal vulnerabilities in your Node.js applications.

Remember, a layered defense approach that combines secure coding, regular dependency updates, and vulnerability scanning is crucial for maintaining a secure development environment.

Consider the following secure coding principles to protect your Node.js applications against path traversal vulnerabilities:

  • Avoid User-Supplied Path Concatenation: Never directly concatenate user-supplied paths to existing paths before passing them to path.join or path.resolve. This allows attackers to inject malicious path manipulations using sequences like ../.

  • Sanitization is Not Enough: path.normalize is not a standalone security solution. It may remove some redundant path elements but doesn’t prevent traversal attacks. Sanitizing specific characters like .. is also ineffective as attackers can use URL encoding techniques to bypass such filters.

  • Decode User Input Before Resolution: Apply URL decoding functions like decodeURI and decodeURIComponent on user-supplied paths before resolving them. This helps mitigate attempts to exploit encoded path traversal characters.