nodejs security

22
Node.js Security …trolololol

Upload: jason-ross

Post on 15-Feb-2017

69 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Nodejs Security

Node.jsSecurity

…trolololol

Page 2: Nodejs Security

about.me

• break things for fun and profit

• sometimes I talk about stuff

• involved in various groups

• <3 ROC hacker community

Page 3: Nodejs Security

most importantly

Page 4: Nodejs Security

node.js

• a JavaScript runtime built on Google’s V8 JavaScript engine

• uses an event-driven, non-blocking I/O model

• npm package repo claims to be the largest ecosystem of open source libraries in the world

Page 5: Nodejs Security

V8 engine runtime

• written in C++

• implements ECMA script standard ECMA-262

• same engine the chrome browser uses for JavaScript processing

Page 6: Nodejs Security

installation

• don’t apt-get install

• download the tarball

• untar it $someplace

• add $someplace/<nodedir>/bin to your path

Page 7: Nodejs Security

starting a project

• npm init<demo>

• or don’t

Page 8: Nodejs Security

things to know

• node.js is NOT a web framework.

• It’s an application server• think Tomcat or Zend• not rails or Django

• you know that, devops don’t care

Page 9: Nodejs Security

express.js web framework

• modeled after the ruby ‘Sinatra’ project

• most widely used node framework

• easy to work with, lots of examples

• creating servers is easy

Page 10: Nodejs Security

sample hello

var express = require('express');var app = express();

app.get('/', function (req, res) { res.send('Hello World!');});

var server = app.listen(3000, function () { console.log('app listening on port 3000’);});

Page 11: Nodejs Security

other frameworks?

• koaonly framework that embraces ES6 fullyless robust than express, and not as tested

• hapibuilt for complex apps, has big.corp support (walmart)less mature than express, heavier dev investment requirements

Page 12: Nodejs Security

what about $myFavorite.js?

• express / koa / hapi server sidedesigned to manage the application engine

• angular / ember / backbone / omgsomany

client-side JavaScript frameworksimplement MVC or PAC methods

Page 13: Nodejs Security

moar demo

Page 14: Nodejs Security

security risks

• npm makes it easy to add thingstough to track dependenciesrepo is open, anyone can add modulesvulns in vendor libs == app.pwnd

• package.json may get staleas libs are updated, version info may not changelib patches that you ignore == app.pwnd

Page 15: Nodejs Security

OMG! XSS! ONTHASERVER!

• we can inject commands & stuff right?

• not really a concern, because this is server-side

• client input isn’t parsed in the server code• not shelling out to command line

• options that get parsed come from:• env vars• config files• sometimes eval() but that’s very uncommon

Page 16: Nodejs Security

node security tools

• helmet.jsframework makes it easy to remove common vectors like XSS, CSRF, cache snarfing, and clickjacking

helmet = require(‘helmet’);app.use(helmet.xssFilter());app.use(helmet.noCache());app.use(helmet.xssnoSniff());app.use(helmet.xssframeguard());app.use(helmet.xsshidePoweredBy());

Page 17: Nodejs Security

helmet makes us safer

Page 18: Nodejs Security

nodesecurity.io

• flags included packages with known vulnerabilities

• can be used automagically with grunt

grunt.loadNpmTasks('grunt-nsp-package');grunt.loadNpmTasks('grunt-nsp-shrinkwrap');

grunt.registerTask('nsp-package', 'Validates package.json with nodesecurity.io','validate-package');

grunt.registerTask('nsp-shrinkwrap','Validates shrinkwrap.json with

nodesecurity.io','validate-shrinkwrap');

Page 19: Nodejs Security

nsp-package example

Page 20: Nodejs Security

NodeJs Scan

• python tool to scan node.js static code

• problem: node is JavaScript, and is dynamic

• that makes it tough to analyze code

• still does a decent job of trying

Page 21: Nodejs Security

demo++;

Page 22: Nodejs Security

preso.quit();