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

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
Security Latest
Security Latest
NISL@THU
NISL@THU
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
W
WeLiveSecurity
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
T
Tor Project blog
H
Heimdal Security Blog
Microsoft Security Blog
Microsoft Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
L
LINUX DO - 热门话题
The GitHub Blog
The GitHub Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
P
Privacy & Cybersecurity Law Blog
F
Full Disclosure
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
B
Blog RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
K
Kaspersky official blog
Attack and Defense Labs
Attack and Defense Labs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
Hacker News - Newest:
Hacker News - Newest: "LLM"
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
博客园 - 【当耐特】
S
Security Affairs
The Cloudflare Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
News and Events Feed by Topic
AI
AI
H
Help Net Security
美团技术团队
T
Threatpost
Project Zero
Project Zero

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 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
Protecting Against Common Node.js Vulnerabilities
2024-03-01 · via NodeJS Security & NodeJS Secure Coding's Blog

As a Node.js developer, keeping your applications secure is crucial. Node applications can be vulnerable to issues like command injection, path traversal, and insecure APIs. In this post, we’ll explore some common Node.js security pitfalls and how to avoid them.

Defending Against Command Injection

Command injection is one of the most common and dangerous vulnerabilities in Node. A key way this happens is by concatenating unsanitized user input into commands executed by a child process. For example:

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

const userInput = process.argv[2];

exec(`git checkout ${userInput}`);

If a malicious user provides input like ; rm -rf /, it could delete critical files. Instead, avoid concatenating user input into commands. Consider using the execFile API which only allows specifying arguments, not arbitrary commands.

The Fastify framework provides some built-in security controls like request and response schema validation that will be helpful to mitigate malicious input. That said, always be careful what input you pass directly to the OS. A schema validation is not enough to prevent command injection.

Defending Against Path Traversal

Another common issue is path traversal attacks, where a user can access files outside an expected directory.

Her’s an example of a more classic use-case of an API endpoint for serving PDF files from disk:

const express = require('express');

const fs = require('fs');

const app = express();

app.get('/users/:userId/files/:fileId', (req, res) => {

const userId = req.params.userId;

const fileId = req.params.fileId;

// In real scenario, look up file path for given user and file ID combo

const filePath = `/users/${userId}/files/${fileId}.pdf`;

fs.readFile(filePath, (err, fileContents) => {

if (err) {

return res.status(400).send('Error reading file');

}

res.contentType('application/pdf');

res.send(fileContents);

});

});

app.listen(3000);

Conducting Secure Code Reviews

Many vulnerabilities can be caught early by conducting peer code reviews before releasing software. When reviewing code, watch for areas where user input is incorporated without sanitization.

Analyze all external data entry points like APIs, CLI arguments, uploaded files, etc. I recommend following these 10 best practices for secure code review of Node.js code to help you get started.

Also carefully review uses of privileges like executing commands, writing files, accessing APIs, etc. Ask questions any time elevated privileges are used. Could this area be exploited? What’s the worst possible input? Code reviews catch issues proactively while code is still easy to change.

Assessing Your Node.js Security Knowledge

Continuously assess your own knowledge of Node.js application security. Do a regular security self-assessment to identify gaps in your understanding. Check that you understand all aspects of the Node.js security model like scope, sandboxing, input validation, secure API usage, etc.

For example, can you find the security issue in this code?

const fastify = require('fastify')();

fastify.get('/downloads', (req, res) => {

const userFile = req.query.file;

if (userFile.includes('..') || userFile.includes('/')) {

return res.status(400).send({error: 'Illegal directory traversal attempt'});

}

const fileAbsolutePath = decodeURIComponent(`/downloads/files/${userFile}`);

fs.readFile(fileAbsolutePath, (err, data) => {

if (err) {

return res.status(500).send('Error accessing file');

}

res.type('application/octet-stream');

res.send(data);

});

});

fastify.listen(3000);

If you aren’t sure about the issue or how to fix it, you want to take a look at my book Node.js Secure Coding: Prevention and Exploitation of Path Traversal Vulnerabilities.

Key Vulnerable Node.js APIs to Avoid

Some Node.js APIs have security issues if used improperly. Be cautious with APIs like vm.runInContext, child_process.exec, path.join() and others. Similarly, calling OS commands, writing files, and accessing sensitive environment variables can lead to vulnerabilities if not handled carefully. Consider more secure alternatives like execFile and access controls around privileged operations.

Security must be every Node.js developer’s priority. Follow best practices around input validation, access controls, and peer code reviews. Continuously build your Node.js security knowledge through hands-on training. Making security a habit will help protect both your applications and your users.