The Security Toolbox For Node

Rate this content
Bookmark

Do you have a way to quickly check all of your repos for any vulnerabilities to various attacks? Do you know which attacks you should be preparing your applications for? In this talk, we will cover the top 10 attacks on Node applications and how to handle all of them. Multiple tools will be covered, all of which have been used in production across different back-end architectures.

A few of the areas that will be covered include securing dependencies, securing data, and securing your server. By the end of this talk, attendees should have a full security toolbox and they will know how to implement it quickly. This will help with production applications because you will still get through your sprints on time and you will be able to rest knowing you have security measures in place.

This talk has been presented at Node Congress 2021, check out the latest edition of this Tech Conference.

FAQ

Conducto is a tool designed to help developers debug pipelines and deploy applications more easily.

Milesha McGregor is a developer advocate at Conducto.

The OWASP Top 10 is a list of the most critical web application security vulnerabilities, covering issues such as cross-site scripting, SQL injection, and denial of service attacks.

Cross-site scripting (XSS) is a vulnerability where attackers inject malicious JavaScript into a web application, potentially redirecting users, stealing cookies, or executing unauthorized actions.

To prevent cross-site scripting, validate all inputs, ensure numeric fields receive numbers, enforce password security requirements, and encode data sent to users.

A denial of service (DoS) attack occurs when a malicious party overwhelms a server with requests, causing it to become unavailable to legitimate users.

To prevent DoS attacks, implement rate limiting, validate inputs, and prevent infinite data creation loops.

Server-side injection is a vulnerability where attackers inject malicious data into a query, potentially causing unauthorized actions like dropping a database.

Run commands like npm audit and npm audit fix to identify and fix vulnerabilities in npm packages. Use two-factor authentication and read-only tokens for npm package access.

Some tools to protect your Node.js server include Helmet.js for security headers, Crypto.js for data encryption, and express-rate-limit for rate limiting.

Milecia McGregor
Milecia McGregor
29 min
24 Jun, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The Talk focuses on Node application security, covering topics such as OWASP top 10 vulnerabilities, handling packages, managing data, and protecting servers. Best practices include password security, input validation, and data encryption. The importance of securing access to packages and managing data is emphasized. Encrypting data for secure communication is discussed, along with protecting servers using HTTPS and rate limiting. The challenges of security implementation and resources for learning are mentioned, as well as the use of attacker tools. Docker security and preventing IP attacks are also touched upon.

1. Introduction to Node Application Security

Short description:

My name is Milesha McGregor, a developer advocate at Conducto, and today I'm going to talk about a security toolbox for node applications. We'll cover the OWASP top 10 vulnerabilities, handling packages, managing data, and protecting servers from attacks like cross-site scripting. Validate all inputs, especially numeric fields.

Alright, hey, everybody. My name is Milesha McGregor, and I'm a developer advocate at Conducto. So we make this really cool tool where you can debug your pipelines and do your deploys easier and all that good stuff. So make sure you check me and us out on Twitter. But today, I'm going to talk to you about a security toolbox you can build for all of your node applications. So since we've been virtual for so long, I always like to give an overview. That way, you know where you can kind of, you know, tune in, tune out, fast forward through the video later when you're going back through it.

But to get started, I'm going to jump off with just the OWASP top 10 vulnerabilities. We'll cover pretty much all of them and some of the packages and other tools and strategies you can use to secure your Node apps from these kinds of attacks. And then we'll talk about how you can handle your packages because as every JavaScript engineer knows, we use a package for just about everything. So you want to make sure that you're taking care of those. And we'll also talk a bit about managing your data. So we all know on the back end that we don't want other people or people that shouldn't have access to the data to actually be able to access the data. So we're going to talk about some different strategies that we can use to just make sure that, you know, nobody that got fired three months ago is going to come back and drop all the databases. And we'll talk some more about protecting your server from different attacks, like the ones that just shut down your server. I know the word for this, but I'm going to remember it much later than I should. And then we'll wrap up with just a few key takeaways and some things I hope you can just go back to work and implement as soon as you can.

So to get started, we're going to just jump into the OWASP top 10 vulnerabilities. So there's this node goat app that is just in existence and it'll walk you through all 10 of the vulnerabilities using this cool little node application. So if you want to see some live examples that have been developed by just some of the top security people in the world, go ahead and check out this node goat app. But one thing that you want to keep in mind with this OWASP top 10, these 10 vulnerabilities are present on, I believe it was 85% of all web apps online right now. So almost the whole internet is just vulnerable to some kind of attack. And that is the reason why I want to give you just some tools and stuff you can use to make sure you don't have one of those apps or that when you do encounter one you can clean it up and just make sure that it becomes less attack-friendly. So the first thing we're going to talk about is cross-site scripting. This is basically when somebody injects JavaScript into your app, and it makes the app redirect users to some other place, it steals cookies so that they can authenticate themselves as other users, or basically anywhere there is some kind of input field that they can type text into, they're able to execute some kind of JavaScript statement. So we want to make sure that some random person on the Internet isn't injecting or cross-site scripting something really crazy into our app, so we're going to prevent that. And to do that, start by validating all of your inputs. I know we already do that because form validation is everybody's favorite thing. But I just want to make sure that we're really all doing it. So validate those inputs, make sure any numeric fields are actually receiving numbers.

2. Best Practices for Node Application Security

Short description:

Make sure passwords have their certain security requirements, validate user inputs, and encrypt all data sent to users. Prevent denial of service attacks by implementing checks to prevent looping and data creation. Validate all inputs, both on the front-end and back-end, to prevent server-side injection attacks.

Make sure passwords have their certain security requirements, whether that's lowercase and capital letters, numbers, special characters, whatever you want it to be. But have some validation around these inputs to where a user cannot submit a form if it's not in the right format.

And then something else you can do to just help with that whole session hijacking thing with the cross-site scripting, encode all of the data that you send to your users. So we know that we need to encode data that they send to us, just so people on the Wi-Fi in the airport or Windows were a thing. But when you're on an open network, you know that you always encrypt data going to the server so that prying eyes don't get access to it. Make sure you're doing the same thing when you're sending data. So go ahead and encrypt everything.

Now we'll talk about the denial of service attacks. So this is that thing that I could not say in the intro for some reason. But a denial of service attack is pretty much when some malicious party gets access to your server and they send so many requests that it brings down the server for all of your actual users. This means that someone is sending enough requests that they are using up all of your cloud resources or all of your on-prem resources to the point where your app is basically unavailable. So you don't want the denial of service attacks to happen, especially when your app is something very critical to your users. So to prevent those, we really want to put checks in place to prevent looping and data creation. You don't want somebody to be able to submit a query to your back-end that infinitely adds fake users to your database. That's one of the ways that a denial of service attack can bring your entire application down. And again, validate all of those inputs. There's forums on pretty much every site nowadays, whether it's just getting your email or somehow convincing you to sign in with Google. Validate those inputs. They're around, so make sure you're doing that on the front-end and the back-end.

Now let's talk a little bit about the server-side injection attack. This is when an outside party can inject data as part of just a simple query. This happens when you're able to submit bad queries in forums. So basically, what's happening is somebody's typing in a SQL query where they should be typing in a new username. And now you have your database dropped and nobody knows why. Just because someone was able to actually submit this request to the backend and there weren't any type of checks in place to prevent that from happening. So to prevent that, one thing that you'll want to do is parse any user input. You know what kind of data you're expecting from the front end. You know what values should be stored in the database. You have a whole schema for this. So when you're getting this user input, just go ahead and parse it down into what actually needs to be present.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Node Congress 2022Node Congress 2022
26 min
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Top Content
The talk discusses the importance of supply chain security in the open source ecosystem, highlighting the risks of relying on open source code without proper code review. It explores the trend of supply chain attacks and the need for a new approach to detect and block malicious dependencies. The talk also introduces Socket, a tool that assesses the security of packages and provides automation and analysis to protect against malware and supply chain attacks. It emphasizes the need to prioritize security in software development and offers insights into potential solutions such as realms and Deno's command line flags.
Towards a Standard Library for JavaScript Runtimes
Node Congress 2022Node Congress 2022
34 min
Towards a Standard Library for JavaScript Runtimes
Top Content
There is a need for a standard library of APIs for JavaScript runtimes, as there are currently multiple ways to perform fundamental tasks like base64 encoding. JavaScript runtimes have historically lacked a standard library, causing friction and difficulty for developers. The idea of a small core has both benefits and drawbacks, with some runtimes abusing it to limit innovation. There is a misalignment between Node and web browsers in terms of functionality and API standards. The proposal is to involve browser developers in conversations about API standardization and to create a common standard library for JavaScript runtimes.
ESM Loaders: Enhancing Module Loading in Node.js
JSNation 2023JSNation 2023
22 min
ESM Loaders: Enhancing Module Loading in Node.js
ESM Loaders enhance module loading in Node.js by resolving URLs and reading files from the disk. Module loaders can override modules and change how they are found. Enhancing the loading phase involves loading directly from HTTP and loading TypeScript code without building it. The loader in the module URL handles URL resolution and uses fetch to fetch the source code. Loaders can be chained together to load from different sources, transform source code, and resolve URLs differently. The future of module loading enhancements is promising and simple to use.
Out of the Box Node.js Diagnostics
Node Congress 2022Node Congress 2022
34 min
Out of the Box Node.js Diagnostics
This talk covers various techniques for getting diagnostics information out of Node.js, including debugging with environment variables, handling warnings and deprecations, tracing uncaught exceptions and process exit, using the v8 inspector and dev tools, and generating diagnostic reports. The speaker also mentions areas for improvement in Node.js diagnostics and provides resources for learning and contributing. Additionally, the responsibilities of the Technical Steering Committee in the TS community are discussed.
The State of Passwordless Auth on the Web
JSNation 2023JSNation 2023
30 min
The State of Passwordless Auth on the Web
Passwords are terrible and easily hacked, with most people not using password managers. The credential management API and autocomplete attribute can improve user experience and security. Two-factor authentication enhances security but regresses user experience. Passkeys offer a seamless and secure login experience, but browser support may be limited. Recommendations include detecting Passkey support and offering fallbacks to passwords and two-factor authentication.
Node.js Compatibility in Deno
Node Congress 2022Node Congress 2022
34 min
Node.js Compatibility in Deno
Deno aims to provide Node.js compatibility to make migration smoother and easier. While Deno can run apps and libraries offered for Node.js, not all are supported yet. There are trade-offs to consider, such as incompatible APIs and a less ideal developer experience. Deno is working on improving compatibility and the transition process. Efforts include porting Node.js modules, exploring a superset approach, and transparent package installation from npm.

Workshops on related topic

Node.js Masterclass
Node Congress 2023Node Congress 2023
109 min
Node.js Masterclass
Top Content
Workshop
Matteo Collina
Matteo Collina
Have you ever struggled with designing and structuring your Node.js applications? Building applications that are well organised, testable and extendable is not always easy. It can often turn out to be a lot more complicated than you expect it to be. In this live event Matteo will show you how he builds Node.js applications from scratch. You’ll learn how he approaches application design, and the philosophies that he applies to create modular, maintainable and effective applications.

Level: intermediate
Build and Deploy a Backend With Fastify & Platformatic
JSNation 2023JSNation 2023
104 min
Build and Deploy a Backend With Fastify & Platformatic
WorkshopFree
Matteo Collina
Matteo Collina
Platformatic allows you to rapidly develop GraphQL and REST APIs with minimal effort. The best part is that it also allows you to unleash the full potential of Node.js and Fastify whenever you need to. You can fully customise a Platformatic application by writing your own additional features and plugins. In the workshop, we’ll cover both our Open Source modules and our Cloud offering:- Platformatic OSS (open-source software) — Tools and libraries for rapidly building robust applications with Node.js (https://oss.platformatic.dev/).- Platformatic Cloud (currently in beta) — Our hosting platform that includes features such as preview apps, built-in metrics and integration with your Git flow (https://platformatic.dev/). 
In this workshop you'll learn how to develop APIs with Fastify and deploy them to the Platformatic Cloud.
0 to Auth in an hour with ReactJS
React Summit 2023React Summit 2023
56 min
0 to Auth in an hour with ReactJS
WorkshopFree
Kevin Gao
Kevin Gao
Passwordless authentication may seem complex, but it is simple to add it to any app using the right tool. There are multiple alternatives that are much better than passwords to identify and authenticate your users - including SSO, SAML, OAuth, Magic Links, One-Time Passwords, and Authenticator Apps.
While addressing security aspects and avoiding common pitfalls, we will enhance a full-stack JS application (Node.js backend + React frontend) to authenticate users with OAuth (social login) and One Time Passwords (email), including:- User authentication - Managing user interactions, returning session / refresh JWTs- Session management and validation - Storing the session securely for subsequent client requests, validating / refreshing sessions- Basic Authorization - extracting and validating claims from the session token JWT and handling authorization in backend flows
At the end of the workshop, we will also touch other approaches of authentication implementation with Descope - using frontend or backend SDKs.
Building a Hyper Fast Web Server with Deno
JSNation Live 2021JSNation Live 2021
156 min
Building a Hyper Fast Web Server with Deno
WorkshopFree
Matt Landers
Will Johnston
2 authors
Deno 1.9 introduced a new web server API that takes advantage of Hyper, a fast and correct HTTP implementation for Rust. Using this API instead of the std/http implementation increases performance and provides support for HTTP2. In this workshop, learn how to create a web server utilizing Hyper under the hood and boost the performance for your web apps.
0 to Auth in an Hour Using NodeJS SDK
Node Congress 2023Node Congress 2023
63 min
0 to Auth in an Hour Using NodeJS SDK
WorkshopFree
Asaf Shen
Asaf Shen
Passwordless authentication may seem complex, but it is simple to add it to any app using the right tool.
We will enhance a full-stack JS application (Node.JS backend + React frontend) to authenticate users with OAuth (social login) and One Time Passwords (email), including:- User authentication - Managing user interactions, returning session / refresh JWTs- Session management and validation - Storing the session for subsequent client requests, validating / refreshing sessions
At the end of the workshop, we will also touch on another approach to code authentication using frontend Descope Flows (drag-and-drop workflows), while keeping only session validation in the backend. With this, we will also show how easy it is to enable biometrics and other passwordless authentication methods.
Table of contents- A quick intro to core authentication concepts- Coding- Why passwordless matters
Prerequisites- IDE for your choice- Node 18 or higher
GraphQL - From Zero to Hero in 3 hours
React Summit 2022React Summit 2022
164 min
GraphQL - From Zero to Hero in 3 hours
Workshop
Pawel Sawicki
Pawel Sawicki
How to build a fullstack GraphQL application (Postgres + NestJs + React) in the shortest time possible.
All beginnings are hard. Even harder than choosing the technology is often developing a suitable architecture. Especially when it comes to GraphQL.
In this workshop, you will get a variety of best practices that you would normally have to work through over a number of projects - all in just three hours.
If you've always wanted to participate in a hackathon to get something up and running in the shortest amount of time - then take an active part in this workshop, and participate in the thought processes of the trainer.