SlideShare a Scribd company logo
Tim Messerschmidt
Head of Developer Relations, International
Braintree
@Braintree_Dev / @SeraAndroid
Node.js Authentication
and Data Security
#HTML5DevConf
Node.js Authentication and Data Security
3
That’s me
Node.js Authentication and Data Security
@Braintree_Dev / @SeraAndroid#HTML5DevConf
+ Braintree
since 2013
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. Introduction_
2. Well-known security threats
3. Data Encryption
4. Hardening Express
5. Authentication middleware
6. Great resources
Content
Node.js Authentication and Data Security
@Braintree_Dev / @SeraAndroid#HTML5DevConf
The Human Element
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. 12345
2. password
3. 12345
4. 12345678
5. qwerty
bit.ly/1xTwYiA
Top 10 Passwords 2014
6. 123456789
7. 1234
8. baseball
9. dragon
10.football
@Braintree_Dev / @SeraAndroid#HTML5DevConf
superman
batman
Honorary Mention
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Authentication
& Authorization
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. Introduction
2. Well-known security threats_
3. Data Encryption
4. Hardening Express
5. Authentication middleware
6. Great resources
Content
@Braintree_Dev / @SeraAndroid#HTML5DevConf
OWASP Top 10bit.ly/1a3Ytvg
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. Injection
@Braintree_Dev / @SeraAndroid#HTML5DevConf
2. Broken Authentication
@Braintree_Dev / @SeraAndroid#HTML5DevConf
3. Cross-Site Scripting
XSS
@Braintree_Dev / @SeraAndroid#HTML5DevConf
4. Direct Object References
@Braintree_Dev / @SeraAndroid#HTML5DevConf
5. Application Misconfigured
@Braintree_Dev / @SeraAndroid#HTML5DevConf
6. Sensitive Data Exposed
@Braintree_Dev / @SeraAndroid#HTML5DevConf
7. Access Level Control
@Braintree_Dev / @SeraAndroid#HTML5DevConf
8. Cross-site Request Forgery
CSRF / XSRF
@Braintree_Dev / @SeraAndroid#HTML5DevConf
9. Vulnerable Code
@Braintree_Dev / @SeraAndroid#HTML5DevConf
10. REDIRECTS / FORWARDS
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. Introduction
2. Well-known security threats
3. Data Encryption_
4. Hardening Express
5. Authentication middleware
6. Great resources
Content
@Braintree_Dev / @SeraAndroid#HTML5DevConf
HashingMD5, SHA-1, SHA-2, SHA-3
http://arstechnica.com/security/2015/09/once-seen-as-bulletproof-11-million-ashley-madison-passwords-already-cracked/
@Braintree_Dev / @SeraAndroid#HTML5DevConf
ishouldnotbedoingthis
arstechnica.com/security/2015/09/ashley-madison-passwords-like-
thisiswrong-tap-cheaters-guilt-and-denial
@Braintree_Dev / @SeraAndroid#HTML5DevConf
ishouldnotbedoingthis
whyareyoudoingthis
arstechnica.com/security/2015/09/ashley-madison-passwords-like-
thisiswrong-tap-cheaters-guilt-and-denial
@Braintree_Dev / @SeraAndroid#HTML5DevConf
ishouldnotbedoingthis
whyareyoudoingthis
justtryingthisout
arstechnica.com/security/2015/09/ashley-madison-passwords-like-
thisiswrong-tap-cheaters-guilt-and-denial
@Braintree_Dev / @SeraAndroid#HTML5DevConf
ishouldnotbedoingthis
whyareyoudoingthis
justtryingthisout
thebestpasswordever
arstechnica.com/security/2015/09/ashley-madison-passwords-like-
thisiswrong-tap-cheaters-guilt-and-denial
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Efficient Hashingcrypt, scrypt, bcrypt, PBKDF2
@Braintree_Dev / @SeraAndroid#HTML5DevConf
10.000 iterations user system total
MD5 0.07 0.0 0.07
bcrypt 22.23 0.08 22.31
md5 vs bcrypt
github.com/codahale/bcrypt-ruby
abstrusegoose.com/296
http://abstrusegoose.com/296
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Salted Hashingalgorithm(data + salt) = hash
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. Introduction
2. Well-known security threats
3. Data Encryption
4. Hardening Express_
5. Authentication middleware
6. Great resources
Content
@Braintree_Dev / @SeraAndroid#HTML5DevConf
use strict
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Regexowasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
@Braintree_Dev / @SeraAndroid#HTML5DevConf
X-Powered-By
@Braintree_Dev / @SeraAndroid#HTML5DevConf
NODE-UUIDgithub.com/broofa/node-uuid
@Braintree_Dev / @SeraAndroid#HTML5DevConf
GET /pay?amount=20&currency=EUR&amount=1
HTTP Parameter Pollution
req.query.amount = ['20', '1'];
POST amount=20&currency=EUR&amount=1
req.body.amount = ['20', '1'];
@Braintree_Dev / @SeraAndroid#HTML5DevConf
bcryptgithub.com/ncb000gt/node.bcrypt.js
@Braintree_Dev / @SeraAndroid#HTML5DevConf
A bcrypt generated Hash
$2a$12$YKCxqK/QRgVfIIFeUtcPSOqyVGSorr1pHy5cZKsZuuc2g97bXgotS
@Braintree_Dev / @SeraAndroid#HTML5DevConf
bcrypt.hash('cronut', 12, function(err, hash) {
// store hash
});
bcrypt.compare('cronut', hash, function(err, res) {
if (res === true) {
// password matches
}
});
Generating a Hash using bcrypt
@Braintree_Dev / @SeraAndroid#HTML5DevConf
CSURFgithub.com/expressjs/csurf
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Using Csurf as middleware
var csrf = require('csurf');
var csrfProtection = csrf({ cookie: false });
app.get('/form', csrfProtection, function(req, res) {
res.render('form', { csrfToken: req.csrfToken() });
});
app.post('/login', csrfProtection, function(req, res) {
// safe to continue
});
@Braintree_Dev / @SeraAndroid#HTML5DevConf
extends layout
block content
h1 CSRF protection using csurf
form(action="/login" method="POST")
input(type="text", name="username=", value="Username")
input(type="password", name="password", value="Password")
input(type="hidden", name="_csrf", value="#{csrfToken}")
button(type="submit") Submit
Using the token in your template
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Helmetgithub.com/HelmetJS/Helmet
@Braintree_Dev / @SeraAndroid#HTML5DevConf
var helmet = require(‘helmet’);
app.use(helmet.noCache());
app.use(helmet.frameguard());
app.use(helmet.xssFilter());
…
// .. or use the default initialization
app.use(helmet());
Using Helmet with default options
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Helmet for Koagithub.com/venables/koa-helmet
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Luscagithub.com/krakenjs/lusca
@Braintree_Dev / @SeraAndroid#HTML5DevConf
var lusca = require('lusca');
app.use(lusca({
csrf: true,
csp: { /* ... */},
xframe: 'SAMEORIGIN',
p3p: 'ABCDEF',
xssProtection: true
}));
Applying Lusca as middleware
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Lusca for Koagithub.com/koajs/koa-lusca
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. Introduction
2. Well-known security threats
3. Data Encryption
4. Hardening Express
5. Authentication middleware_
6. Great resources
Content
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. Application-level
2. Route-level
3. Error-handling
Types of Express Middleware
@Braintree_Dev / @SeraAndroid#HTML5DevConf
var authenticate = function(req, res, next) {
// check the request and modify response
};
app.get('/form', authenticate, function(req, res) {
// assume that the user is authenticated
}
// … or use the middleware for certain routes
app.use('/admin', authenticate);
Writing Custom Middleware
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Passportgithub.com/jaredhanson/passport
@Braintree_Dev / @SeraAndroid#HTML5DevConf
passport.use(new LocalStrategy(function(username, password, done) {
User.findOne({ username: username }, function (err, user) {
if (err) { return done(err); }
if (!user) {
return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(password)) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
}));
Setting up a passport strategy
@Braintree_Dev / @SeraAndroid#HTML5DevConf
// Simple authentication
app.post('/login', passport.authenticate(‘local'), function(req, res) {
// req.user contains the authenticated user
res.redirect('/user/' + req.user.username);
});
// Using redirects
app.post('/login', passport.authenticate('local', {
successRedirect: ‘/',
failureRedirect: ‘/login’,
failureFlash: true
}));
Using Passport Strategies for Authentication
@Braintree_Dev / @SeraAndroid#HTML5DevConf
NSPnodesecurity.io/tools
Node.js Authentication and Data Security
@Braintree_Dev / @SeraAndroid#HTML5DevConf
1. Introduction
2. Well-known security threats
3. Data Encryption
4. Hardening Express
5. Authentication middleware
6. Great resources_
Content
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Passwordless Authmedium.com/@ninjudd/passwords-are-obsolete-9ed56d483eb
@Braintree_Dev / @SeraAndroid#HTML5DevConf
OWASP Node Goatgithub.com/OWASP/NodeGoat
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Node Securitynodesecurity.io/resources
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Fast Identity Onlinefidoalliance.org
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Security Beyond Current Mechanisms
1. Something you have
2. Something you know
3. Something you are
@Braintree_Dev / @SeraAndroid#HTML5DevConf
Favor security too much over the
experience and you’ll make the
website a pain to use.
smashingmagazine.com/2012/10/26/password-masking-hurt-signup-form
@SeraAndroid
tim@getbraintree.com
slideshare.com/paypal
braintreepayments.com/developers
Thank You!

More Related Content

PPTX
Authentication in Node.js
PDF
JSConf Asia: Node.js Authentication and Data Security
PPTX
High Performance JavaScript (CapitolJS 2011)
PDF
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
PDF
Building an HTML5 Video Player
PDF
BDD - Writing better scenario
PDF
Ajax Security
PDF
What the Heck is OAuth and OpenID Connect - RWX 2017
Authentication in Node.js
JSConf Asia: Node.js Authentication and Data Security
High Performance JavaScript (CapitolJS 2011)
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Building an HTML5 Video Player
BDD - Writing better scenario
Ajax Security
What the Heck is OAuth and OpenID Connect - RWX 2017

What's hot (20)

PDF
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
PDF
Apache Roller, Acegi Security and Single Sign-on
PDF
Front End Development for Back End Java Developers - NYJavaSIG 2019
PDF
A Gentle Introduction to Angular Schematics - Angular SF 2019
PDF
Keypoints html5
PDF
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
PDF
Front End Development for Back End Developers - Denver Startup Week 2017
PDF
Vaadin Components @ Angular U
PDF
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
PDF
Vaadin Components
PDF
Java REST API Framework Comparison - PWX 2021
PPTX
What is HTML 5?
PDF
Aleksey Bogachuk - "Offline Second"
PDF
Front End Development for Back End Developers - vJUG24 2017
PPTX
Client-side JavaScript Vulnerabilities
PPT
GWT
PDF
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
PDF
State of the resource timing api
PDF
Web Components for Java Developers
PDF
JAX-RS JavaOne Hyderabad, India 2011
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
Apache Roller, Acegi Security and Single Sign-on
Front End Development for Back End Java Developers - NYJavaSIG 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019
Keypoints html5
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
Front End Development for Back End Developers - Denver Startup Week 2017
Vaadin Components @ Angular U
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
Vaadin Components
Java REST API Framework Comparison - PWX 2021
What is HTML 5?
Aleksey Bogachuk - "Offline Second"
Front End Development for Back End Developers - vJUG24 2017
Client-side JavaScript Vulnerabilities
GWT
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
State of the resource timing api
Web Components for Java Developers
JAX-RS JavaOne Hyderabad, India 2011
Ad

Viewers also liked (18)

PDF
Node.js Authentication & Data Security
PDF
[HTML5DevConf SF] Hardware Hacking for Javascript Developers
PDF
Hoffmeyer - PayPal Case Study - BL S2 2016
PPTX
Mobile device security using transient authentication
PDF
CIS 2015 Mobile Security, Identity & Authentication: Reasons for Optimism - R...
PDF
Monetate Implementation Cheat Sheet
PDF
DWS Mobile Payments Workshop
PDF
Certificate in Quantity Surveying
PPTX
Expanding Your Network Adoption Program Globally
PDF
Biggest News from Mobile World Congress 2014
PDF
Silabo Historia de la Arquitectura III 2016-I
DOCX
Reactivos completamiento
PDF
Top 5 payment mistakes made by startups
PPTX
Ácidos binarios
PDF
New Trends in Mobile Authentication
PPT
Technet System Center Mobile Device Manager Presentation
PDF
FT Partners Research: PayPal Spin-off Overview
PDF
Silabo Taller de Diseño 1 2016-I
Node.js Authentication & Data Security
[HTML5DevConf SF] Hardware Hacking for Javascript Developers
Hoffmeyer - PayPal Case Study - BL S2 2016
Mobile device security using transient authentication
CIS 2015 Mobile Security, Identity & Authentication: Reasons for Optimism - R...
Monetate Implementation Cheat Sheet
DWS Mobile Payments Workshop
Certificate in Quantity Surveying
Expanding Your Network Adoption Program Globally
Biggest News from Mobile World Congress 2014
Silabo Historia de la Arquitectura III 2016-I
Reactivos completamiento
Top 5 payment mistakes made by startups
Ácidos binarios
New Trends in Mobile Authentication
Technet System Center Mobile Device Manager Presentation
FT Partners Research: PayPal Spin-off Overview
Silabo Taller de Diseño 1 2016-I
Ad

Similar to Node.js Authentication and Data Security (20)

PPTX
Expanding APIs beyond the Web
PPS
Hacking Client Side Insecurities
PDF
OWASP SF - Reviewing Modern JavaScript Applications
ODP
Scout xss csrf_security_presentation_chicago
ODP
MiTM Attacks in Android Apps - TDC 2014
PPTX
Micro frontends
PDF
#MBLTdev: Современная аутентификация (PayPal)
PDF
Intro to Php Security
DOCX
PDF
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
PPT
Open Source Web Technologies
PDF
Firefox OS, HTML5 pour le mobile - Code(love) Hackathon - 2014-05-28
PDF
Repaso rápido a los nuevos estándares web
KEY
Application Security for RIAs
PDF
PhoneGap, Backbone & Javascript
PDF
HTML for the Mobile Web, Firefox OS
PPTX
Introduction to html5
PPTX
CodeOne SF 2018 "Are you deploying and operating with security in mind?"
PDF
Prakash kadam CV
PDF
From Idea to App (or “How we roll at Small Town Heroes”)
Expanding APIs beyond the Web
Hacking Client Side Insecurities
OWASP SF - Reviewing Modern JavaScript Applications
Scout xss csrf_security_presentation_chicago
MiTM Attacks in Android Apps - TDC 2014
Micro frontends
#MBLTdev: Современная аутентификация (PayPal)
Intro to Php Security
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
Open Source Web Technologies
Firefox OS, HTML5 pour le mobile - Code(love) Hackathon - 2014-05-28
Repaso rápido a los nuevos estándares web
Application Security for RIAs
PhoneGap, Backbone & Javascript
HTML for the Mobile Web, Firefox OS
Introduction to html5
CodeOne SF 2018 "Are you deploying and operating with security in mind?"
Prakash kadam CV
From Idea to App (or “How we roll at Small Town Heroes”)

More from Tim Messerschmidt (8)

PDF
Building a Mobile Location Aware System with Beacons
PDF
HackconEU: Hackathons are for Hackers
PDF
The Anatomy of Invisible Apps
PDF
Death to Passwords SXSW 15
PPTX
Future Of Payments
PDF
Death To Passwords
PDF
Kraken at DevCon TLV
PDF
SETapp Präsentation
Building a Mobile Location Aware System with Beacons
HackconEU: Hackathons are for Hackers
The Anatomy of Invisible Apps
Death to Passwords SXSW 15
Future Of Payments
Death To Passwords
Kraken at DevCon TLV
SETapp Präsentation

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Safe Confined Space Entry Monitoring_ Singapore Experts.pptx
PPTX
Mini project ppt template for panimalar Engineering college
PPT
Introduction Database Management System for Course Database
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PPTX
Transform Your Business with a Software ERP System
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PPT
JAVA ppt tutorial basics to learn java programming
DOCX
The Five Best AI Cover Tools in 2025.docx
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Online Work Permit System for Fast Permit Processing
PDF
top salesforce developer skills in 2025.pdf
PDF
System and Network Administraation Chapter 3
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
ai tools demonstartion for schools and inter college
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Safe Confined Space Entry Monitoring_ Singapore Experts.pptx
Mini project ppt template for panimalar Engineering college
Introduction Database Management System for Course Database
Upgrade and Innovation Strategies for SAP ERP Customers
Materi-Enum-and-Record-Data-Type (1).pptx
Transform Your Business with a Software ERP System
VVF-Customer-Presentation2025-Ver1.9.pptx
Materi_Pemrograman_Komputer-Looping.pptx
JAVA ppt tutorial basics to learn java programming
The Five Best AI Cover Tools in 2025.docx
Essential Infomation Tech presentation.pptx
Online Work Permit System for Fast Permit Processing
top salesforce developer skills in 2025.pdf
System and Network Administraation Chapter 3
PTS Company Brochure 2025 (1).pdf.......
ai tools demonstartion for schools and inter college
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
ManageIQ - Sprint 268 Review - Slide Deck
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf

Node.js Authentication and Data Security