Node Security 
By 
Rejah Rehim
Know what you require (); 
NPM has ~75000 modules
Use good Security Defaults 
Node is a set of barebons modules 
Express is a barebons framework
Lusca 
App security module for express 
var express = require('express'), 
app = express(), 
lusca = require('lusca');
With Express Middleware 
● app.use(lusca.csrf()); 
● app.use(lusca.csp({ /* ... */})); 
● app.use(lusca.xframe('SAMEORIGIN')); 
● app.use(lusca.p3p('ABCDEF')); 
● app.use(lusca.hsts({ maxAge: 31536000 })); 
● app.use(lusca.xssProtection(true));
CSRF 
Trick victim's browser into making malicious requests
Node.JS security
Node.JS security
Lusca.csrf() 
Uses Token Synchronizer pattern 
1) Create a random token on serverside 
2) Add token to res.local 
3) Dump that token in app page 
4) Sends with every PUT DELETE POST request 
5) Verify token is correct, Else return 403
CSP 
● Content Security Policy 
● Basically a white listing
Node.JS security
Node.JS security
Lusca.csp() 
app.use(lusca.csp({ 
policy: { 
'default-src': 'none', 
'script-src': ''self' https://apis.google.com' 
}, 
reportUri: '/report-violation' 
}));
Lusca.hsts() 
● Ensures HTTPS traffic 
● Prevent MITM
Lusca.xframe() 
● Prevent Others from loading your app in Iframe
HTTPOnly Cookies 
● Prevent Session Hijacking 
app.use(express.session({ 
secret: 'My super session secret', 
cookie: { 
httpOnly: true, 
secure: true 
} 
}));
Eval is evil
Node Security Project 
● Audit all modules in NPM 
● Contribute patches 
● Educate others
Scan For vulnerable modules 
npm install grunt-nsp-package --save-dev 
grunt validate-package
Update your dependency
Clientside modules
Escape everithing 
● Not just user inputs Backend bata as well
Underscore templates 
<% %> - to execute some code 
<%= %> - to print some value in template 
<%- %> - to print some values with HTML escaped
Know your templating library 
● Use it properly
Update your front-end dependencies 
● Retire.js 
npm install grunt-retire --save-dev 
grunt retire
Let's Recap 
● Know what you're require()'ing 
● Node is stil a Javascript 
● Use good security defaults 
● Update your dependencies – use automation
Thanks

More Related Content

PDF
Node Day - Node.js Security in the Enterprise
PPTX
Nodejs Security
PDF
Nodevember 2015
PPTX
Javascript Security - Three main methods of defending your MEAN stack
PDF
Understanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
PDF
How to secure web applications
PPTX
Mod security
PDF
Horizontally Scaling Node.js and WebSockets
Node Day - Node.js Security in the Enterprise
Nodejs Security
Nodevember 2015
Javascript Security - Three main methods of defending your MEAN stack
Understanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
How to secure web applications
Mod security
Horizontally Scaling Node.js and WebSockets

What's hot (20)

PDF
Tale of Forgotten Disclosure and Lesson learned
PPTX
Apache Struts2 CVE-2017-5638
PDF
Node.js in Production
PDF
The Real World - Plugging the Enterprise Into It (nodejs)
PDF
Перевірка роботи McAfee ENS. MVISION Insights SUNBURST.
PPTX
Web Application firewall-Mod security
PPTX
[Wroclaw #2] Web Application Security Headers
PDF
Breaking The Framework's Core #PHPKonf 2016
PDF
SSL Pinning and Bypasses: Android and iOS
PDF
OSCP Preparation Guide @ Infosectrain
PPTX
Client-side JavaScript Vulnerabilities
PDF
WordPress security 101 - WP Jyväskylä Meetup 21.3.2017
PPTX
Jon Stace Web Cryptography API
PDF
SBA Live Academy - Secure Containers for Developer by Mathias Tausig
PDF
Find WordPress performance bottlenecks with XDebug PHP profiling
PPTX
Server-side template injection- Slides
PDF
Make CSRF Again
ODP
PDF
Build your first DApp using Substrate Framework - Part I
PPTX
Javascript Security
Tale of Forgotten Disclosure and Lesson learned
Apache Struts2 CVE-2017-5638
Node.js in Production
The Real World - Plugging the Enterprise Into It (nodejs)
Перевірка роботи McAfee ENS. MVISION Insights SUNBURST.
Web Application firewall-Mod security
[Wroclaw #2] Web Application Security Headers
Breaking The Framework's Core #PHPKonf 2016
SSL Pinning and Bypasses: Android and iOS
OSCP Preparation Guide @ Infosectrain
Client-side JavaScript Vulnerabilities
WordPress security 101 - WP Jyväskylä Meetup 21.3.2017
Jon Stace Web Cryptography API
SBA Live Academy - Secure Containers for Developer by Mathias Tausig
Find WordPress performance bottlenecks with XDebug PHP profiling
Server-side template injection- Slides
Make CSRF Again
Build your first DApp using Substrate Framework - Part I
Javascript Security
Ad

Similar to Node.JS security (20)

PDF
Serverless Security Guy Podjarny Liran Tal
PDF
Security in Node.JS and Express:
PDF
How to Make Your NodeJS Application Secure (24 Best Security Tips )
PDF
The Ultimate Node.js Resource Cheat Sheet 📝: Learn Everything Free
PDF
Testing NodeJS Security
KEY
nodecalgary1
PDF
FITC - Node.js 101
PDF
Kickstarter Your Node.JS Application
PDF
Node.JS Workshop
PDF
Hello world - intro to node js
PDF
Node.js security tour
PDF
Introduction to node js - From "hello world" to deploying on azure
PPTX
Enterprise Node - Securing Your Environment
PPTX
Nodejs web service for starters
PDF
A Complete Guide to Node.js Authentication and Security
PDF
Basic API Creation with Node.JS
PPTX
Node js Introduction
PDF
Node.js 101 with Rami Sayar
PPTX
MSWD:MERN STACK WEB DEVELOPMENT COURSE CODE
PDF
Building Scalable Apps With Redis And Nodejs Joshua Johanan
Serverless Security Guy Podjarny Liran Tal
Security in Node.JS and Express:
How to Make Your NodeJS Application Secure (24 Best Security Tips )
The Ultimate Node.js Resource Cheat Sheet 📝: Learn Everything Free
Testing NodeJS Security
nodecalgary1
FITC - Node.js 101
Kickstarter Your Node.JS Application
Node.JS Workshop
Hello world - intro to node js
Node.js security tour
Introduction to node js - From "hello world" to deploying on azure
Enterprise Node - Securing Your Environment
Nodejs web service for starters
A Complete Guide to Node.js Authentication and Security
Basic API Creation with Node.JS
Node js Introduction
Node.js 101 with Rami Sayar
MSWD:MERN STACK WEB DEVELOPMENT COURSE CODE
Building Scalable Apps With Redis And Nodejs Joshua Johanan
Ad

More from Deepu S Nath (20)

PPTX
Design Thinking, Critical Thinking & Innovation Design
PDF
GTECH ATFG µLearn Framework Intro
PPTX
Future of learning - Technology Disruption
PDF
Decentralized Applications using Ethereum
PDF
How machines can take decisions
PDF
Artificial Intelligence: An Introduction
PPTX
FAYA PORT 80 Introduction
PDF
How machines can take decisions
PDF
Simplified Introduction to AI
PPTX
Mining Opportunities of Block Chain and BitCoin
PPTX
Introduction to DevOps
PPT
Coffee@DBG - TechBites March 2016
PPTX
REACT.JS : Rethinking UI Development Using JavaScript
PPT
SEO For Developers
PDF
Life Cycle of an App - From Idea to Monetization
PPT
Uncommon Python - What is special in Python
PPT
Coffee@DBG - TechBites Sept 2015
PPT
Techbites July 2015
PPT
Apple Watch - Start Your Developer Engine
PPTX
Greetings & Response - English Communication Training
Design Thinking, Critical Thinking & Innovation Design
GTECH ATFG µLearn Framework Intro
Future of learning - Technology Disruption
Decentralized Applications using Ethereum
How machines can take decisions
Artificial Intelligence: An Introduction
FAYA PORT 80 Introduction
How machines can take decisions
Simplified Introduction to AI
Mining Opportunities of Block Chain and BitCoin
Introduction to DevOps
Coffee@DBG - TechBites March 2016
REACT.JS : Rethinking UI Development Using JavaScript
SEO For Developers
Life Cycle of an App - From Idea to Monetization
Uncommon Python - What is special in Python
Coffee@DBG - TechBites Sept 2015
Techbites July 2015
Apple Watch - Start Your Developer Engine
Greetings & Response - English Communication Training

Recently uploaded (20)

PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
STKI Israel Market Study 2025 version august
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Getting Started with Data Integration: FME Form 101
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Architecture types and enterprise applications.pdf
PDF
Hybrid model detection and classification of lung cancer
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
STKI Israel Market Study 2025 version august
Assigned Numbers - 2025 - Bluetooth® Document
sustainability-14-14877-v2.pddhzftheheeeee
O2C Customer Invoices to Receipt V15A.pptx
Zenith AI: Advanced Artificial Intelligence
Benefits of Physical activity for teenagers.pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions
A contest of sentiment analysis: k-nearest neighbor versus neural network
Getting Started with Data Integration: FME Form 101
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Final SEM Unit 1 for mit wpu at pune .pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
DP Operators-handbook-extract for the Mautical Institute
Architecture types and enterprise applications.pdf
Hybrid model detection and classification of lung cancer

Node.JS security