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

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
W
WeLiveSecurity
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
A
Arctic Wolf
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
G
GRAHAM CLULEY
O
OpenAI News
S
Schneier on Security
Google Online Security Blog
Google Online Security Blog
Vercel News
Vercel News
宝玉的分享
宝玉的分享
Attack and Defense Labs
Attack and Defense Labs
T
The Blog of Author Tim Ferriss
量子位
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
P
Privacy & Cybersecurity Law Blog
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 热门话题
博客园_首页
F
Full Disclosure
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Docker
U
Unit 42
A
About on SuperTechFans
博客园 - 司徒正美
Hacker News - Newest:
Hacker News - Newest: "LLM"
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
Scott Helme
Scott Helme
TaoSecurity Blog
TaoSecurity Blog

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 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
Common Node.js Security Issues and How to Mitigate Them
2024-04-21 · via NodeJS Security & NodeJS Secure Coding's Blog

Node.js is a popular runtime environment for building server-side applications. However, like any other technology, Node.js security issues can result in vulnerabilities that expose your applications to potential threats.

In this blog post, I’ll review some common Node.js security issues and how to mitigate them. Hopefully these insights will help you secure your Node.js applications and write secure code.

Node.js Security Issue: Denial-of-Service (DoS) Attacks

The security threat is that malicious actors or even misconfigured clients can overload a Node.js server with HTTP requests, rendering it unavailable to legitimate users. One example of prior art is the Slowloris attack, which sends partial HTTP requests to keep connections open indefinitely.

Key takeaways:

  • Handle Socket Errors: Implement proper error handling for sockets to prevent crashes from bad requests.
  • Set Timeouts: Configure timeouts in your HTTP server (e.g., headersTimeout, requestTimeout) to drop idle or slow connections.
  • Limit Connections: Use http.Server properties like agent.maxSockets to restrict the number of open connections per host or total.
  • Consider a Reverse Proxy: Explore using a reverse proxy for caching, load balancing, and IP blacklisting to mitigate DoS attacks.

Node.js Security Issue: DNS Rebinding Attack

The threat with DNS rebinding is attackers exploiting a running debugging inspector with DNS rebinding to gain unauthorized access to your application.

This in fact was a real-world attack on the Node.js debugging inspector in 2018, where an attacker could execute arbitrary code on the server by sending a malicious HTTP request. It resulted in a CVE-2018-12120 security advisory in which All versions prior to Node.js 6.15.0: Debugger port 5858 listens on any interface by default.

Key takeaways:

  • Disable Inspector in Production: Never run the debugging inspector (--inspect) in production environments.
  • Handle SIGUSR1 Signal: Implement a process.on('SIGUSR1', ...) listener to disable the inspector on the SIGUSR1 signal.

Node.js Security Issue: Unintended Package Publication

Imagine the threat of publishing sensitive information accidentally when publishing your Node.js package. This could include private keys, passwords, or other confidential data that you as a developer often keep around in your project files.

No doubt you probably have worked before with .env, config.json or other configuration files that contain sensitive information. If you accidentally publish these files as part of your npm package then you could expose this information on the public npm registry.

Key takeaways:

  • Use npm publish --dry-run: Before publishing, test with npm publish --dry-run to verify the list of files being published.
  • Maintain Ignore Files: Create and maintain .gitignore and .npmignore files to exclude sensitive files from publication.
  • Review package.json: Review the files property in package.json to ensure it only lists intended files.
  • React to Exposures: If sensitive information is published, you should unpublish the package immediately, but more importantly, you have to rotate the exposed credentials (which means you also need to have proper secret management in place).

Node.js Security Issue: Information Exposure via Timing Attacks (CWE-208)

The threat here is that attackers can potentially steal sensitive information (like passwords) by analyzing your application’s response times.

Key takeaways:

  • Use Constant-Time Comparisons: For comparing sensitive data (e.g., passwords), use crypto.timingSafeEqual to ensure a constant execution time regardless of the value.
  • Leverage scrypt for Passwords: Utilize the built-in scrypt function for secure password comparisons (it’s available as part of the Node.js crypto built-in core module).
  • Avoid Variable-Time Operations: Refrain from using secrets in operations with variable execution time (e.g., conditional branching based on secrets).

Node.js Security Issue: Lack of Secure Coding - Command Injection Vulnerabilities

Command injection vulnerabilities remain a significant threat in Node.js applications due to insecure coding practices. These vulnerabilities arise when user input or untrusted data is directly used to construct system commands.

The threat revolves around attackers who exploit command injection vulnerabilities to execute arbitrary commands on your server. This can lead to severe consequences and past analysis of real-world command injection examples show the consequences are severe and include data exfiltration, file system manipulation and other system disruptions.

A common culprit for command injection vulnerabilities is the child_process.exec API. This function executes a shell command and returns the output as a buffer. However, using it without proper sanitization poses a security risk.

For example, consider:

const command = `cat /etc/passwd | grep ${username}`;

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

// ... process output

});

In this example, the username variable could be controlled by an attacker. If the attacker provides a specially crafted username containing malicious commands, those commands could be executed on the server.

Here’s how to prevent command injection vulnerabilities:

  • Input Validation and Sanitization: Validate and sanitize all user input before using it to construct commands. Remove potentially harmful characters or commands from the input.

  • Alternatives to child_process.exec: Consider safer alternatives like child_process.spawn with proper argument escaping or dedicated libraries for specific tasks.

Example (using a secure API):

const username = sanitizeUserInput(username);

const command = `cat /etc/passwd`;

const args = ['grep', username];

child_process.spawn(command, args, (error, stdout, stderr) => {

// ... process output

});

Command injection vulnerabilities remain a significant threat in Node.js applications and CLI tools, as evident by npm packages like blamer which demonstrated the secure coding complexity when two hyphens caused an argument injection vulnerability.