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

推荐订阅源

J
Java Code Geeks
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
Cloudbric
Cloudbric
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
博客园_首页
The Cloudflare Blog
C
Cisco Blogs
AWS News Blog
AWS News Blog
IT之家
IT之家
Cyberwarzone
Cyberwarzone
罗磊的独立博客
美团技术团队
V
V2EX
Project Zero
Project Zero
A
Arctic Wolf
C
Cyber Attacks, Cyber Crime and Cyber Security
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
S
Schneier on Security
P
Privacy International News Feed
V
Visual Studio Blog
量子位
T
Tor Project blog
S
Securelist
腾讯CDC
A
About on SuperTechFans
T
Threat Research - Cisco Blogs
G
GRAHAM CLULEY
B
Blog RSS Feed
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
B
Blog
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
V
Vulnerabilities – Threatpost
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
L
LINUX DO - 热门话题
Recorded Future
Recorded Future

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 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
Node.js Security Best Practices
3. Follow authentication and authorization best practices · 2024-03-15 · via NodeJS Security & NodeJS Secure Coding's Blog

Building secure Node.js applications requires a multifaceted approach, encompassing various security best practices that safeguard your server-side code from vulnerabilities. This guide goes into these crucial practices, ranging from coding practices to general Node.js application security that will help empower you to develop robust and secure Node.js applications.

1. Node.js secure coding

The first step for a secure Node.js application is to write secure code. This includes following best practices for secure coding, such as input validation, output encoding, string parameterization and secure error handling.

Some of these security best practices might sound familiar, or even obvious but for example, most developers would consider mitigating command injection vulnerabilities using input sanitization and validation. However, these are helpful tactics, but other secure coding practices like string parameterization that splits a command from its command-line arguments, are de-facto the secure coding practice to follow.

I wrote two comprehensive books that teach developers how to follow secure coding conventions in Node.js in order to mitigate security vulnerabilities: path traversal and command injection.

2. Secure your dependencies

Maintain up-to-date dependencies is crucial in terms of overall Node.js application security as well as dependency health. Regularly update your application’s dependencies to benefit from security patches and bug fixes. Utilize tools like Snyk to identify vulnerabilities in your dependencies and address them promptly.

npm install url-parse serve @node-red/runtime

added 176 packages, and audited 177 packages in 16s

12 high severity vulnerabilities

You should also responsibly scrutinize third-party packages. Before introducing a new dependency, meticulously evaluate its reputation, maintenance status, and potential security risks.

Did you know that crypto-mining malware was found in a dependency that traced back to North-Korean hackers?. Keep a close eye on your dependencies.

Aim for robust and battle-tested authentication algorithms. Employ strong authentication mechanisms like password hashing with secure algorithms (e.g., bcrypt) and of course follow practices like implementing authentication layers via two-factor authentication (2FA) to enhance user account security.

What you need to know to avoid common security pitfalls when implementing authentication:

  • Do not store plain text passwords.
  • Do not use weak hashing algorithms. If you want to use modern secure hashing algorithms like scrypt or argon2, those are too, vetted securely to use.
  • Do not implement password limits like a maximum of 16 characters or requiring special characters. Instead, encourage the use of passphrases and lengthy generated passwords from password managers.

You can read more about secure Node.js authentication and cryptography for a comprehensive guide on this topic.

4. Secure sensitive data

With regards to encryption at rest, make sure to avoid leaking sensitive information. This includes using secure key management practices, including key rotation and proper key storage using dedicated key management systems. But really, at the first place, just avoid hard-coding sensitive data in your application source code or storing credentials in plain text configuration files or environment variables.

If you wonder what practices to avoid then you should read my guide on environment variables and security anti-patterns.

There’s another more in-depth concept to look into which is key management: most cloud vendors offer a key management service that can help you manage your keys securely. For example, AWS Key Management Service (KMS) or Google Cloud Key Management Service (KMS) are good examples. You can also use open-source solutions like HashiCorp Vault or the dotenv’s team dotenvx which builds on the practice of using .env files for configuration and secrets management.

5. Prioritize error handling and logging

Handle errors gracefully and securely. For example, if you’re using the Express web application and don’t start your Node.js servers with NODE_ENV=production then you might be leaking sensitive information to the client. This is because the default error handling middleware in Express will expose stack traces and other sensitive information to the client when errors are left unhandled and uncaught. This is because the default NODE_ENV is development and not production. Do you remember to set it to production in your CI or your Node.js deployment workflows?

Implement robust error handling to prevent sensitive information disclosure and application crashes in the event of unexpected errors. Avoid returning detailed error messages that might personally identify users or expose details that would be useful to attackers.

Follow secure logging practices, such as making sure to monitor application behavior and potential security incidents (using a tool like Sentry that captures error traces and could prove handy). Avoid logging sensitive information like passwords or personally identifiable information (PII).

Input validation and sanitization are helpful security practices. With that regard, utilize libraries like joi validator.js to validate user input and sanitize it to help mitigate malicious code injection attacks, regular expression denial of service, and other security vulnerabilities.

Don’t fall into the trap of attempting to sanitize input to mitigate code injection attacks like like XSS (Cross-Site Scripting) and SQL injection, because these require different mitigation strategies such as output encoding and query parameterization, applied respectively.

You’d probably want to also make use of a library like zod or ajv to specifically maintain your request/reply schema and validate it. This is a good practice to ensure that your application is not only secure but also robust and reliable.

6. Secure your Node.js runtime

A handful of practices fall into the category of securing your Node.js runtime. These include:

  • Minimize privileges: Run your Node.js application with the least privileged user account necessary to minimize the potential impact of security breaches.
  • Keep the Node.js runtime updated: Maintain the latest security updates for your operating system, as well as your Node.js version, and other server-side software to address known vulnerabilities. If you’re using containers to deploy your Node.js application, make sure to keep your container images updated.

Continued learning is essential to stay ahead of the curve. Stay informed about emerging security threats and vulnerabilities specific to Node.js development. Don’t blindly ignore security vulnerability results. They’re there for a reason, and yes it may be frustrating and daunting to find whether they are applicable or not, but there are frameworks, practices and technological solutions to help with that.

I also recommend participating in the Node.js ecosystem security working group and other friendly DevSecOps and secure coding communities to stay updated on the latest best practices.

What’s next?

If you’re keen to follow secure coding practices in Node.js, then you should consider reading my books on Node.js Secure Coding which teach you about insecure code patterns from real-world examples of vulnerable npm packages and how the security incidents unfolded for them.

By diligently adhering to these comprehensive best practices, you can significantly enhance the security posture of your Node.js applications and safeguard your users’ data and privacy. Remember that security is an ongoing process and it’s essential to continuously re-evaluate your security measures and adapt to the threats and vulnerabilities that emerge over time.