SlideShare una empresa de Scribd logo
1 de 86
Maciej Lasyk, node.js security
Maciej Lasyk
SEConference
Kraków, 2014-05-09
node.js security
Sysadmin about node.js security?
- not only sysadmin ;)
- node needs thorough understanding of whole infra
- 14+ years of exp software dev. / sysop
- currently “noding” 4 prv & Fedora
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
JS security recap – evals & co
eval() like fncs takes string argument and
evalute those as source code
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
JS security recap – evals & co
eval() like fncs takes string argument and
evalute those as source code
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
srsly – who does that?
Maciej Lasyk, node.js security
JS security recap – evals & co
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var x = req.body.x;
var y = req.body.y;
var sum = eval(a + "+" + b);
Maciej Lasyk, node.js security
JS security recap – evals & co
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var x = req.body.x;
var y = req.body.y;
var sum = eval(a + "+" + b);
what if attacker fills 'x' with:
some.super.class.wipe.the.database('now');
LOL :)
Maciej Lasyk, node.js security
JS security recap – evals & co
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
not only evals:
setInterval(code,2)
setTimeout(code,2)
str = new Function(code)
Chrome CSP denies those also :)
Maciej Lasyk, node.js security
JS security recap – global namespace pollution
- node.js is single threaded
- all variable values are common
- one could thrtically change bhv of others reqs
- watch out for globals then!
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
JS security recap – global namespace pollution
some very awful example:
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var auth = false;
app.get('/auth', function(req, res) {
if(legit) { auth = true; res.send("success");
});
app.get('/payments-db', function(req, res) {
if (auth) res.send("legit to see all payments data");
else res.send("not logged in");
})
app.listen(8080);
Maciej Lasyk, node.js security
JS security recap – global namespace pollution
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
So now imagine..
global namespace pollution + evals & co
Maciej Lasyk, node.js security
JS security recap – global namespace pollution
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
So now imagine..
global namespace pollution + evals & co
Maciej Lasyk, node.js security
JS security recap – global namespace pollution
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
So now imagine..
global namespace pollution + evals & co
Watch out who you are hiring
Maciej Lasyk, node.js security
JS security recap – strict mode
- let's throw all errors!
- declare variables!
- global namespaces help
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
JS security recap – strict mode
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
"use strict";
function testFunction(){
var testvar = 4;
return testvar;
}
// This causes a syntax error.
testvar = 5;
Maciej Lasyk, node.js security
JS security recap – strict mode
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
// This causes a syntax error:
"use strict";
testvar = 5;
// This is ok:
"use strict";
var testvar = 0;
testvar = 5;
Maciej Lasyk, node.js security
JS security recap – strict mode
- evals & co are not that insecure now
- no access to caller and args props
- enable globally or for some scope
- what about strict mode in 3rd
party mods?
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
JS security recap – strict mode
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
"use strict";
function do_smt() {
do_smt.caller; // no way :)
do_smt.arguments; // no way :)
}
Maciej Lasyk, node.js security
JS security recap – strict mode
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
"use strict";
eval("var smt = 123");
console.log(smt); // sorry – ReferenceError
Maciej Lasyk, node.js security
JS security recap – strict mode
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
"use strict";
eval("var smt = 123");
console.log(smt); // sorry – ReferenceError
But watch out:
"use strict";
var smt = 0;
eval("smt = 123");
console.log(smt); // outputs “123” properly
Maciej Lasyk, node.js security
JS security recap – object properties
- writable: RO/RW
- enumerable: no loops enumeration
- configurable: deletion prohibited
- all default set to True so watch out
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
JS security recap – object properties
var obj = {}; obj.prop = "LOL";
// OR:
Object.defineProperty(obj, "prop", {
writable: true,
enumerable: true,
configurable: true,
value: "LOL"
})
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
JS security recap – object properties
// RO & immutable property def:
var obj = {};
Object.defineProperty(obj, "prop", {
value: "LOL"
});
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
JS security recap – static code analysis
- If not doing it already – just do
- Commit hooks in (D)VCSes
- JSHint / JSLint
- Create policy for static code analysis
- Update & check this policy regularly
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
about node.js: what's up?
- current stable version 0.10.28
- who is using node?
https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node
- Operating Node.js in production/Bryan Cantrill (Joyent)
- Bill Scott,“Clash of the Titans: Kraken | Node.js @ paypal”
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
about node.js: model
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
about node.js: concurrency
- node.js is single threaded (let's say)
- multi – core? child processes (cluster.fork)
- Linux containers ftw!
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
about node.js: SPA
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
(thx Sekurak.pl for this image)
Maciej Lasyk, node.js security
node.js sec: exploits anyone?
- http://seclists.org/bugtraq – 0 hits
- http://osvdb.org – 2 hits
- http://1337day.com, http://www.exploitdb.com – 1 hit
- http://nodesecurity.io/advisories – 4 hits
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js sec: exploits anyone?
- http://seclists.org/bugtraq – 0 hits
- http://osvdb.org – 2 hits
- http://1337day.com, http://www.exploitdb.com – 1 hit
- http://nodesecurity.io/advisories – 4 hits
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Such security big?
Maciej Lasyk, node.js security
node.js sec: exploits anyone?
- http://seclists.org/bugtraq – 0 hits
- http://osvdb.org – 2 hits
- http://1337day.com, http://www.exploitdb.com – 1 hit
- http://nodesecurity.io/advisories – 4 hits
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Such security big?
not exactly
Maciej Lasyk, node.js security
node.js sec: what's wrong?
node.js security is a blank page
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
http://www.slideshare.net/ASF-WS/asfws-2012-nodejs-security-old-vulnerabilities-in-new-dresses-par-sven-vetsch
Maciej Lasyk, node.js security
node.js sec: how does sec look like?
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js sec: how does sec look like?
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Such security..Such security..
Very fortress!!1Very fortress!!1
WOW :)WOW :)
Maciej Lasyk, node.js security
node.js sec: exceptions / callbacks
callbacks Error object – remember to handle those
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var fs = require("fs");
fs.readFile("/some/file", "utf8", function (err, contents) {
// err will be null if no error occured
// ... otherwise there will be info about error
});
forget about handling and die debugging
Maciej Lasyk, node.js security
node.js sec: exceptions / eventemitter
EventEmitter: emitting events 4 async actions
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var http = require("http");
http.get("http://nodejs.org/", function (res) {
res.on("data", function (chunk) {
do_something_with_chunk;
});
res.on("error", function (err) {
// listener handling error
});
});
Attach listeners to errors events or
welcome unhandled exception!
Maciej Lasyk, node.js security
node.js sec: uncaught exceptions
- by default node.js will print stack trace and terminate thread
- EventEmitter / process / uncaughtException
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
// it looks like this by default:
process.on("uncaughtException", function (err) {
console.error(err);
console.trace();
process.exit();
});
Maciej Lasyk, node.js security
node.js sec: uncaught exceptions
- by default node.js will print stack trace and terminate thread
- EventEmitter / process / uncaughtException
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
// it looks like this by default:
process.on("uncaughtException", function (err) {
console.error(err);
console.trace();
process.exit();
});
So do you really want to comment out the 'process.exit()' line?
Maciej Lasyk, node.js security
node.js sec: clusters
scaling within multi-core envs
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log(worker.process.pid + ' died');
});
} else {
http.createServer(function(req, res) {
res.writeHead(200);
res.end("hello worldn");
}).listen(8000);
}
Maciej Lasyk, node.js security
node.js sec: domains
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Handling multiple different IO operations as a single group
// don't do that:
var d = require('domain').create();
d.on('error', function(er) {
console.log('error, but oh well', er.message);
});
d.run(function() {
require('http').createServer(function(req, res) {
handleRequest(req, res);
}).listen(PORT);
});
Maciej Lasyk, node.js security
node.js sec: domains
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Rather use cluster & forks and exit gently..:
create_cluster;
fork_workers;
if(worker){
var domain = require('domain');
var server = require('http').createServer(function(req, res) {
var d = domain.create();
d.on('error', function(er) {
console.error('error', er.stack);
try {
// set timeout timer
// update master && print err msg
// close server
} catch (er2) { console.error('Error 500!', er2.stack); }
}
Maciej Lasyk, node.js security
node.js sec: domains
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Using Express take look at that:
https://github.com/brianc/node-domain-middleware
Assigning each Express request to a separate domain?
Maciej Lasyk, node.js security
node.js sec: npm modules
- npm install (-g)
- who creates modules?
- who verifies those?
- how to update?
- semantic versioning in package.json
- "connect":"~1.8.7" -> 1.8.7 - 1.9
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js sec: npm modules
--ignore-scripts
stop preinstall/prepublish scripts
- mods auditing: https://nodesecurity.io/
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js sec: npm modules
The scale of npm modules
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js sec: npm modules
Comparison to other langs (mods/day):
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js sec: npm modules
Remember:
- use strict?
- static analysis?
- does include some test suite?
- what is the dependency tree?
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.express: connect / express
Express – web dev framework
Built on top of connect
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.express: auth.basic_auth
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var express = require('express'),
app = express();
app.use(express.basicAuth("user", "pwd"));
app.get("/", function (req, res) {
res.send('Hello World');
});
app.listen(8080);
Plain text and simple auth issues
Maciej Lasyk, node.js security
node.js.express: auth.basic_auth
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var users = {
admin: "admin123",
user: "user456"
};
app.use(express.basicAuth(function (user, pass) {
return users.hasOwnProperty(user) && users[user]
=== pass;
}));
Maciej Lasyk, node.js security
node.js.express: auth.SSL
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var express = require('express'), routes = require('./routes'), fs = require('fs')
var opts = {
key: fs.readFileSync('ssl/server/keys/server.key'),
cert: fs.readFileSync('ssl/server/certificates/server.crt'),
ca: fs.readFileSync('ssl/ca/ca.crt'),
crl: fs.readFileSync('ssl/ca/ca.crl'),
requestCert: true,
rejectUnauthorized: true
passphrase: "pwd" // <<<< really here?
};
var app = module.exports = express.createServer(opts);
app.configure(function(){
app.set('views', __dirname + '/views');
...
});
app.get('/', routes.index);
app.listen(8443);
Maciej Lasyk, node.js security
node.js.express: passport.js
- provides API for authentication and authorization
- authentication:
- LocalStrategy
- OpenIDStrategy
- OAuth / FacebookStrategy
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.express: authorization
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var users = [
{ id: 1, name: "user1", role: "admin" },
{ id: 2, name: "user2", role: "common" },
];
function loadUser(req, res, next) {
req.userData = users[req.params.user];
return next();
}
function requireRole(role) {
return function (req, res, next) {
if (req.user.role === role) {
return next();
} else {
return next(new Error("Unauthorized"));
}
};}
Maciej Lasyk, node.js security
node.js.express: authorization
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
app.get("/users/:user", loadUser, function (req, res) {
res.send(req.user.name);
});
app.del("/users/:user", requireRole("admin"), loadUser,
function (req,res) {
res.send("User deleted");
});
Maciej Lasyk, node.js security
node.js.express: logging
OWASP will tell you what should be logged :)
https://www.owasp.org/index.php/Logging_Cheat_Sheet
- authentication & authorisation
- session management
- errors & weirdo events
- events (startups, shutdowns, slowdowns etc)
- high risk functionalities (payments, privileges, admins)
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.express: logging
Try Winston module (Github -> flatiron/winston)
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
- logging to console
- logging to file
- sending logs over HTTP
- CouchDB, Redis, MongoDB, Riak etc
Maciej Lasyk, node.js security
node.js.express: logging
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.File)({
filename: 'application.log' })
]
});
Maciej Lasyk, node.js security
node.js.express: sessions
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var express = require('express');
var app = express();
var RedisStore = require('connect-redis')(express);
app.use(express.cookieParser());
app.use(express.session({
store: new RedisStore({
host: '127.0.0.2',
port: 6379,
db: 3,
pass: 'pwd'
}),
secret: 'this-is-very-secret'
}));
app.get('/somewhere', function(req, res) {
res.send('In the middle of nowhere');
});
app.listen(process.env.PORT || 8080);
Maciej Lasyk, node.js security
node.js.express: sessions
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
app.use(express.session({
secret: “very-secret”,
key: “sessionId”,
cookie: {
httpOnly: true,
secure: true
}
}));
Maciej Lasyk, node.js security
node.js.CSI: CSRF
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var express = require("express"),
app = express();
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: "very-secret" }));
app.use(express.csrf());
Maciej Lasyk, node.js security
node.js.CSI: CSRF
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
app.get("/valid", function (req, res) {
<input type="hidden" name="_csrf" value="+req.CsrfToken()+">
res.send(output);
});
app.get("/invalid", function (req, res) {
no_csrf_token_field
res.send(output);
});
Express CSRF ignores CSRF on HTTP, GET, OPTIONS, HEAD reqs
Maciej Lasyk, node.js security
node.js.CSI: input.validation
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
var express = require("express"),
app = module.exports = express();
app.use(express.bodyParser());
app.use(require("express-validator")());
app.get("/", function (req, res) {
res.sendfile(__dirname + "/tpls/validate.html");
});
app.post("/", function (req, res, next) {
// validation
req.checkBody("name").notEmpty().is(/w+/);
// filtering
req.sanitize("name").trim();
...
}
Maciej Lasyk, node.js security
node.js.CSI: XSS
- XSS allows to access cookies, session tokens etc
- or even redirect user to malicious sites
- Myth: frameworks / tpls does the anti-XSS job
- always encode untrusted data for correct context
- OWASP ESAPI
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.CSI: DoS
- Error handling
- Use streams / chunking
- Use monitoring
- Use domains / clusters
- Don't be afraid of SlowLoris :)
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.CSI: ReDoS
- Regex could take exponential execution time
- Is regex executed in the event loop thread?
- Regex and user input?
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
https://speakerdeck.com/ckarande/top-overlooked-security-threats-to-node-dot-js-web-applications
Maciej Lasyk, node.js security
node.js.CSI: HPP
HTTP Parameter Pollution
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
// POST firstName=John&firstName=John
req.body.color
//=> [“John”, “John”]
Maciej Lasyk, node.js security
node.js.CSI: HPP
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Modify app behavior:
Maciej Lasyk, node.js security
node.js.CSI: HPP
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
- TypeErrors, uncaught errs->DoS,
- Check the expected type in the input validation
- Input fuzzing / test suites
- try/catch, domains, clusters
Maciej Lasyk, node.js security
node.js.CSI: HTTP_headers.CSP
Content Security Policy
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Content-Security-Policy:
script-src 'self';
frame-src 'none';
object-src 'none';
report-uri /my_csp_report_parser;
Maciej Lasyk, node.js security
node.js.CSI: HTTP_headers.CSP
Content Security Policy
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Content-Security-Policy:
script-src 'self';
frame-src 'none';
object-src 'none';
report-uri /my_csp_report_parser;
app.use(helmet.csp.policy({
defaultPolicy: {
"script-src": [ "'self'" ],
"img-src": [ "'self'", "http://example.com/" ]
}
}));
Maciej Lasyk, node.js security
node.js.CSI: HTTP_headers.HSTS
HTTP Strict Transport Security
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
app.use(helmet.hsts(X, true));
Strict-Transport-Security: max-age=X; includeSubdomains
Requires HTTPS also on subdomains,
respects configuration for X seconds
Maciej Lasyk, node.js security
node.js.CSI: HTTP_headers.X-Frame-Options
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
X-Frame-Options: DENY
helmet.xframe('sameorigin');
helmet.xframe('allow-from', 'http://example.com');
Maciej Lasyk, node.js security
node.js.CSI: HTTP_headers.others
- X-Content-Type-Options
- Cache-Control
- X-Powered-By
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
X-Content-Type-Options: nosniff
app.use(helmet.contentTypeOptions());
app.use(helmet.cacheControl());
app.disable(“x-powered-by”);
Maciej Lasyk, node.js security
node.js.CSI: request_size
Just set limits
use streams instead of buffering
And request size:
app.use(express.limit("5mb"));
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.CSI: environment.monitoring
- is app functional? :)
- is app overloaded?
- app should provide monitoring interface
- how many errors caught?
- are forks alive and OK?
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.CSI: environment.resources
- node.js will eat ;)
- use control groups || containers
- monitor resources usage
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.CSI: environment.sandboxing
- running node.js within shared env?
- selinux sandbox?
- libvirt sandbox?
- LXC / Docker?
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.CSI: environment.ACLs
Just...
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
node.js.CSI: environment.ACLs
Just...
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Don't run as `root`!!!
Maciej Lasyk, node.js security
node.js.CSI: environment.ACLs
Just...
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
Don't run as `root`!!!
And also maybe behind some LB?
Maciej Lasyk, node.js security
node.js.CSI: environment.tracing_execution
- SmartOS / Joyent: debugging
- Bunyan / Dtrace
- strace of course...
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.testing: testing
- maybe some interface for white-box pentests?
- unit-testing 4 the sake!
- OWASP Zed Attack Proxy
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
So what else?
sockets.io
node-webkit
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.learning
- Node Security Book
- OWASP Node Goat (top10)
- nodesecurity.io (Twitter, RSS)
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
node.js.hiring?
- does this guy contribute?
- NoSQL somehow?
- not only HTTP: socket.io?
- DevOps & infra?
- Security? :)
Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
Infosec && meet.js meetups
http://maciek.lasyk.info/sysop
maciek@lasyk.info
@docent-net
node.js security
Thank you :)
Maciej Lasyk, node.js security 1/25
Maciej Lasyk
SEConference
Kraków, 2014-05-09
Maciej Lasyk, node.js security

Más contenido relacionado

La actualidad más candente

Appsec DC - wXf -2010
Appsec DC - wXf  -2010Appsec DC - wXf  -2010
Appsec DC - wXf -2010Chris Gates
 
Hug #9 who's keeping your secrets
Hug #9 who's keeping your secretsHug #9 who's keeping your secrets
Hug #9 who's keeping your secretsCameron More
 
Kubernetes - Security Journey
Kubernetes - Security JourneyKubernetes - Security Journey
Kubernetes - Security JourneyJerry Jalava
 
Kubernetes - security you need to know about it
Kubernetes - security you need to know about itKubernetes - security you need to know about it
Kubernetes - security you need to know about itHaydn Johnson
 
[Wroclaw #7] Why So Serial?
[Wroclaw #7] Why So Serial?[Wroclaw #7] Why So Serial?
[Wroclaw #7] Why So Serial?OWASP
 
Lock That Shit Down! Auth Security Patterns for Apps, APIs, and Infra - Sprin...
Lock That Shit Down! Auth Security Patterns for Apps, APIs, and Infra - Sprin...Lock That Shit Down! Auth Security Patterns for Apps, APIs, and Infra - Sprin...
Lock That Shit Down! Auth Security Patterns for Apps, APIs, and Infra - Sprin...Matt Raible
 
Chris Rutter: Avoiding The Security Brick
Chris Rutter: Avoiding The Security BrickChris Rutter: Avoiding The Security Brick
Chris Rutter: Avoiding The Security BrickMichael Man
 
Cloud Compliance with Open Policy Agent
Cloud Compliance with Open Policy AgentCloud Compliance with Open Policy Agent
Cloud Compliance with Open Policy AgentQAware GmbH
 
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015Chris Gates
 
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...Michael Man
 
Giles sirett welcome and cloud stack news
Giles sirett   welcome and cloud stack newsGiles sirett   welcome and cloud stack news
Giles sirett welcome and cloud stack newsShapeBlue
 
LasCon 2014 DevOoops
LasCon 2014 DevOoops LasCon 2014 DevOoops
LasCon 2014 DevOoops Chris Gates
 
Open Source in the Era of 5G
Open Source in the Era of 5GOpen Source in the Era of 5G
Open Source in the Era of 5GAll Things Open
 
ASFWS 2012 - Node.js Security – Old vulnerabilities in new dresses par Sven V...
ASFWS 2012 - Node.js Security – Old vulnerabilities in new dresses par Sven V...ASFWS 2012 - Node.js Security – Old vulnerabilities in new dresses par Sven V...
ASFWS 2012 - Node.js Security – Old vulnerabilities in new dresses par Sven V...Cyber Security Alliance
 
What is Google Cloud Good For at DevFestInspire 2021
What is Google Cloud Good For at DevFestInspire 2021What is Google Cloud Good For at DevFestInspire 2021
What is Google Cloud Good For at DevFestInspire 2021Robert John
 
[Wroclaw #7] Security test automation
[Wroclaw #7] Security test automation[Wroclaw #7] Security test automation
[Wroclaw #7] Security test automationOWASP
 

La actualidad más candente (20)

Appsec DC - wXf -2010
Appsec DC - wXf  -2010Appsec DC - wXf  -2010
Appsec DC - wXf -2010
 
Hug #9 who's keeping your secrets
Hug #9 who's keeping your secretsHug #9 who's keeping your secrets
Hug #9 who's keeping your secrets
 
Kubernetes - Security Journey
Kubernetes - Security JourneyKubernetes - Security Journey
Kubernetes - Security Journey
 
Kubernetes - security you need to know about it
Kubernetes - security you need to know about itKubernetes - security you need to know about it
Kubernetes - security you need to know about it
 
[Wroclaw #7] Why So Serial?
[Wroclaw #7] Why So Serial?[Wroclaw #7] Why So Serial?
[Wroclaw #7] Why So Serial?
 
Lock That Shit Down! Auth Security Patterns for Apps, APIs, and Infra - Sprin...
Lock That Shit Down! Auth Security Patterns for Apps, APIs, and Infra - Sprin...Lock That Shit Down! Auth Security Patterns for Apps, APIs, and Infra - Sprin...
Lock That Shit Down! Auth Security Patterns for Apps, APIs, and Infra - Sprin...
 
Kubernetes security
Kubernetes securityKubernetes security
Kubernetes security
 
Wireguard VPN
Wireguard VPNWireguard VPN
Wireguard VPN
 
Chris Rutter: Avoiding The Security Brick
Chris Rutter: Avoiding The Security BrickChris Rutter: Avoiding The Security Brick
Chris Rutter: Avoiding The Security Brick
 
JEE on DC/OS
JEE on DC/OSJEE on DC/OS
JEE on DC/OS
 
London HUG 19/5 - Kubernetes and vault
London HUG 19/5 - Kubernetes and vaultLondon HUG 19/5 - Kubernetes and vault
London HUG 19/5 - Kubernetes and vault
 
Cloud Compliance with Open Policy Agent
Cloud Compliance with Open Policy AgentCloud Compliance with Open Policy Agent
Cloud Compliance with Open Policy Agent
 
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
 
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...
 
Giles sirett welcome and cloud stack news
Giles sirett   welcome and cloud stack newsGiles sirett   welcome and cloud stack news
Giles sirett welcome and cloud stack news
 
LasCon 2014 DevOoops
LasCon 2014 DevOoops LasCon 2014 DevOoops
LasCon 2014 DevOoops
 
Open Source in the Era of 5G
Open Source in the Era of 5GOpen Source in the Era of 5G
Open Source in the Era of 5G
 
ASFWS 2012 - Node.js Security – Old vulnerabilities in new dresses par Sven V...
ASFWS 2012 - Node.js Security – Old vulnerabilities in new dresses par Sven V...ASFWS 2012 - Node.js Security – Old vulnerabilities in new dresses par Sven V...
ASFWS 2012 - Node.js Security – Old vulnerabilities in new dresses par Sven V...
 
What is Google Cloud Good For at DevFestInspire 2021
What is Google Cloud Good For at DevFestInspire 2021What is Google Cloud Good For at DevFestInspire 2021
What is Google Cloud Good For at DevFestInspire 2021
 
[Wroclaw #7] Security test automation
[Wroclaw #7] Security test automation[Wroclaw #7] Security test automation
[Wroclaw #7] Security test automation
 

Similar a Node.js security

JavaScriptを使って学ぶEnd-to-Endセキュリティ 第3回
JavaScriptを使って学ぶEnd-to-Endセキュリティ 第3回JavaScriptを使って学ぶEnd-to-Endセキュリティ 第3回
JavaScriptを使って学ぶEnd-to-Endセキュリティ 第3回Jun Kurihara
 
Hacking Lab con ProxMox e Metasploitable
Hacking Lab con ProxMox e MetasploitableHacking Lab con ProxMox e Metasploitable
Hacking Lab con ProxMox e MetasploitableAndrea Draghetti
 
Policy as code what helm developers need to know about security
Policy as code  what helm developers need to know about securityPolicy as code  what helm developers need to know about security
Policy as code what helm developers need to know about securityLibbySchulze
 
Positive Technologies - S4 - Scada under x-rays
Positive Technologies - S4 - Scada under x-raysPositive Technologies - S4 - Scada under x-rays
Positive Technologies - S4 - Scada under x-raysqqlan
 
Kharkivpy#3: Javascript and Python backend
Kharkivpy#3: Javascript and Python backendKharkivpy#3: Javascript and Python backend
Kharkivpy#3: Javascript and Python backendMax Klymyshyn
 
"Black Clouds and Silver Linings in Node.js Security" Liran Tal
"Black Clouds and Silver Linings in Node.js Security" Liran Tal"Black Clouds and Silver Linings in Node.js Security" Liran Tal
"Black Clouds and Silver Linings in Node.js Security" Liran TalJulia Cherniak
 
DescampsGE_DesignFactory_ISQED03_06
DescampsGE_DesignFactory_ISQED03_06DescampsGE_DesignFactory_ISQED03_06
DescampsGE_DesignFactory_ISQED03_06Gilles-Eric Descamps
 
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016Amazon Web Services Korea
 
Webpack packing it all
Webpack packing it allWebpack packing it all
Webpack packing it allCriciúma Dev
 
Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowPacking it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowDerek Willian Stavis
 
Rolling Up Your Sleeves
Rolling Up Your SleevesRolling Up Your Sleeves
Rolling Up Your Sleevesdjjackj
 
Practical Approaches to Cloud Native Security
Practical Approaches to Cloud Native SecurityPractical Approaches to Cloud Native Security
Practical Approaches to Cloud Native SecurityKarthik Gaekwad
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceBo-Yi Wu
 
DevOOPS: Attacks and Defenses for DevOps Toolchains
DevOOPS: Attacks and Defenses for DevOps ToolchainsDevOOPS: Attacks and Defenses for DevOps Toolchains
DevOOPS: Attacks and Defenses for DevOps ToolchainsChris Gates
 
Securing Prometheus. Lessons Learned from OpenShift.pdf
Securing Prometheus. Lessons Learned from OpenShift.pdfSecuring Prometheus. Lessons Learned from OpenShift.pdf
Securing Prometheus. Lessons Learned from OpenShift.pdfJesús Ángel Samitier
 
RSA Conference 2010 San Francisco
RSA Conference 2010 San FranciscoRSA Conference 2010 San Francisco
RSA Conference 2010 San FranciscoAditya K Sood
 
My SQL Portal Database (Cluster)
My SQL Portal Database (Cluster)My SQL Portal Database (Cluster)
My SQL Portal Database (Cluster)Nicholas Adu Gyamfi
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrationstakezoe
 

Similar a Node.js security (20)

JavaScriptを使って学ぶEnd-to-Endセキュリティ 第3回
JavaScriptを使って学ぶEnd-to-Endセキュリティ 第3回JavaScriptを使って学ぶEnd-to-Endセキュリティ 第3回
JavaScriptを使って学ぶEnd-to-Endセキュリティ 第3回
 
Hacking Lab con ProxMox e Metasploitable
Hacking Lab con ProxMox e MetasploitableHacking Lab con ProxMox e Metasploitable
Hacking Lab con ProxMox e Metasploitable
 
Policy as code what helm developers need to know about security
Policy as code  what helm developers need to know about securityPolicy as code  what helm developers need to know about security
Policy as code what helm developers need to know about security
 
Positive Technologies - S4 - Scada under x-rays
Positive Technologies - S4 - Scada under x-raysPositive Technologies - S4 - Scada under x-rays
Positive Technologies - S4 - Scada under x-rays
 
Kharkivpy#3: Javascript and Python backend
Kharkivpy#3: Javascript and Python backendKharkivpy#3: Javascript and Python backend
Kharkivpy#3: Javascript and Python backend
 
"Black Clouds and Silver Linings in Node.js Security" Liran Tal
"Black Clouds and Silver Linings in Node.js Security" Liran Tal"Black Clouds and Silver Linings in Node.js Security" Liran Tal
"Black Clouds and Silver Linings in Node.js Security" Liran Tal
 
DescampsGE_DesignFactory_ISQED03_06
DescampsGE_DesignFactory_ISQED03_06DescampsGE_DesignFactory_ISQED03_06
DescampsGE_DesignFactory_ISQED03_06
 
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
 
Webpack packing it all
Webpack packing it allWebpack packing it all
Webpack packing it all
 
Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowPacking it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to now
 
Rolling Up Your Sleeves
Rolling Up Your SleevesRolling Up Your Sleeves
Rolling Up Your Sleeves
 
Testing NodeJS Security
Testing NodeJS SecurityTesting NodeJS Security
Testing NodeJS Security
 
Practical Approaches to Cloud Native Security
Practical Approaches to Cloud Native SecurityPractical Approaches to Cloud Native Security
Practical Approaches to Cloud Native Security
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
 
DevOOPS: Attacks and Defenses for DevOps Toolchains
DevOOPS: Attacks and Defenses for DevOps ToolchainsDevOOPS: Attacks and Defenses for DevOps Toolchains
DevOOPS: Attacks and Defenses for DevOps Toolchains
 
Securing Prometheus. Lessons Learned from OpenShift.pdf
Securing Prometheus. Lessons Learned from OpenShift.pdfSecuring Prometheus. Lessons Learned from OpenShift.pdf
Securing Prometheus. Lessons Learned from OpenShift.pdf
 
RSA Conference 2010 San Francisco
RSA Conference 2010 San FranciscoRSA Conference 2010 San Francisco
RSA Conference 2010 San Francisco
 
My SQL Portal Database (Cluster)
My SQL Portal Database (Cluster)My SQL Portal Database (Cluster)
My SQL Portal Database (Cluster)
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrations
 
Galera Cluster 3.0 Features
Galera Cluster 3.0 FeaturesGalera Cluster 3.0 Features
Galera Cluster 3.0 Features
 

Más de Maciej Lasyk

Programowanie AWSa z CLI, boto, Ansiblem i libcloudem
Programowanie AWSa z CLI, boto, Ansiblem i libcloudemProgramowanie AWSa z CLI, boto, Ansiblem i libcloudem
Programowanie AWSa z CLI, boto, Ansiblem i libcloudemMaciej Lasyk
 
Co powinieneś wiedzieć na temat devops?f
Co powinieneś wiedzieć na temat devops?f Co powinieneś wiedzieć na temat devops?f
Co powinieneś wiedzieć na temat devops?f Maciej Lasyk
 
"Containers do not contain"
"Containers do not contain""Containers do not contain"
"Containers do not contain"Maciej Lasyk
 
Linux containers & Devops
Linux containers & DevopsLinux containers & Devops
Linux containers & DevopsMaciej Lasyk
 
Under the Dome (of failure driven pipeline)
Under the Dome (of failure driven pipeline)Under the Dome (of failure driven pipeline)
Under the Dome (of failure driven pipeline)Maciej Lasyk
 
Continuous Security in DevOps
Continuous Security in DevOpsContinuous Security in DevOps
Continuous Security in DevOpsMaciej Lasyk
 
About cultural change w/Devops
About cultural change w/DevopsAbout cultural change w/Devops
About cultural change w/DevopsMaciej Lasyk
 
Orchestrating docker containers at scale (#DockerKRK edition)
Orchestrating docker containers at scale (#DockerKRK edition)Orchestrating docker containers at scale (#DockerKRK edition)
Orchestrating docker containers at scale (#DockerKRK edition)Maciej Lasyk
 
Orchestrating docker containers at scale (PJUG edition)
Orchestrating docker containers at scale (PJUG edition)Orchestrating docker containers at scale (PJUG edition)
Orchestrating docker containers at scale (PJUG edition)Maciej Lasyk
 
Orchestrating Docker containers at scale
Orchestrating Docker containers at scaleOrchestrating Docker containers at scale
Orchestrating Docker containers at scaleMaciej Lasyk
 
Ghost in the shell
Ghost in the shellGhost in the shell
Ghost in the shellMaciej Lasyk
 
High Availability (HA) Explained - second edition
High Availability (HA) Explained - second editionHigh Availability (HA) Explained - second edition
High Availability (HA) Explained - second editionMaciej Lasyk
 
Monitoring with Nagios and Ganglia
Monitoring with Nagios and GangliaMonitoring with Nagios and Ganglia
Monitoring with Nagios and GangliaMaciej Lasyk
 
RHEL/Fedora + Docker (and SELinux)
RHEL/Fedora + Docker (and SELinux)RHEL/Fedora + Docker (and SELinux)
RHEL/Fedora + Docker (and SELinux)Maciej Lasyk
 
High Availability (HA) Explained
High Availability (HA) ExplainedHigh Availability (HA) Explained
High Availability (HA) ExplainedMaciej Lasyk
 
Shall we play a game? PL version
Shall we play a game? PL versionShall we play a game? PL version
Shall we play a game? PL versionMaciej Lasyk
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?Maciej Lasyk
 

Más de Maciej Lasyk (20)

Rundeck & Ansible
Rundeck & AnsibleRundeck & Ansible
Rundeck & Ansible
 
Docker 1.11
Docker 1.11Docker 1.11
Docker 1.11
 
Programowanie AWSa z CLI, boto, Ansiblem i libcloudem
Programowanie AWSa z CLI, boto, Ansiblem i libcloudemProgramowanie AWSa z CLI, boto, Ansiblem i libcloudem
Programowanie AWSa z CLI, boto, Ansiblem i libcloudem
 
Co powinieneś wiedzieć na temat devops?f
Co powinieneś wiedzieć na temat devops?f Co powinieneś wiedzieć na temat devops?f
Co powinieneś wiedzieć na temat devops?f
 
"Containers do not contain"
"Containers do not contain""Containers do not contain"
"Containers do not contain"
 
Git Submodules
Git SubmodulesGit Submodules
Git Submodules
 
Linux containers & Devops
Linux containers & DevopsLinux containers & Devops
Linux containers & Devops
 
Under the Dome (of failure driven pipeline)
Under the Dome (of failure driven pipeline)Under the Dome (of failure driven pipeline)
Under the Dome (of failure driven pipeline)
 
Continuous Security in DevOps
Continuous Security in DevOpsContinuous Security in DevOps
Continuous Security in DevOps
 
About cultural change w/Devops
About cultural change w/DevopsAbout cultural change w/Devops
About cultural change w/Devops
 
Orchestrating docker containers at scale (#DockerKRK edition)
Orchestrating docker containers at scale (#DockerKRK edition)Orchestrating docker containers at scale (#DockerKRK edition)
Orchestrating docker containers at scale (#DockerKRK edition)
 
Orchestrating docker containers at scale (PJUG edition)
Orchestrating docker containers at scale (PJUG edition)Orchestrating docker containers at scale (PJUG edition)
Orchestrating docker containers at scale (PJUG edition)
 
Orchestrating Docker containers at scale
Orchestrating Docker containers at scaleOrchestrating Docker containers at scale
Orchestrating Docker containers at scale
 
Ghost in the shell
Ghost in the shellGhost in the shell
Ghost in the shell
 
High Availability (HA) Explained - second edition
High Availability (HA) Explained - second editionHigh Availability (HA) Explained - second edition
High Availability (HA) Explained - second edition
 
Monitoring with Nagios and Ganglia
Monitoring with Nagios and GangliaMonitoring with Nagios and Ganglia
Monitoring with Nagios and Ganglia
 
RHEL/Fedora + Docker (and SELinux)
RHEL/Fedora + Docker (and SELinux)RHEL/Fedora + Docker (and SELinux)
RHEL/Fedora + Docker (and SELinux)
 
High Availability (HA) Explained
High Availability (HA) ExplainedHigh Availability (HA) Explained
High Availability (HA) Explained
 
Shall we play a game? PL version
Shall we play a game? PL versionShall we play a game? PL version
Shall we play a game? PL version
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 

Último

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Node.js security

  • 1. Maciej Lasyk, node.js security Maciej Lasyk SEConference Kraków, 2014-05-09 node.js security
  • 2. Sysadmin about node.js security? - not only sysadmin ;) - node needs thorough understanding of whole infra - 14+ years of exp software dev. / sysop - currently “noding” 4 prv & Fedora Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 3. JS security recap – evals & co eval() like fncs takes string argument and evalute those as source code Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 4. JS security recap – evals & co eval() like fncs takes string argument and evalute those as source code Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 srsly – who does that? Maciej Lasyk, node.js security
  • 5. JS security recap – evals & co Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var x = req.body.x; var y = req.body.y; var sum = eval(a + "+" + b); Maciej Lasyk, node.js security
  • 6. JS security recap – evals & co Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var x = req.body.x; var y = req.body.y; var sum = eval(a + "+" + b); what if attacker fills 'x' with: some.super.class.wipe.the.database('now'); LOL :) Maciej Lasyk, node.js security
  • 7. JS security recap – evals & co Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 not only evals: setInterval(code,2) setTimeout(code,2) str = new Function(code) Chrome CSP denies those also :) Maciej Lasyk, node.js security
  • 8. JS security recap – global namespace pollution - node.js is single threaded - all variable values are common - one could thrtically change bhv of others reqs - watch out for globals then! Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 9. JS security recap – global namespace pollution some very awful example: Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var auth = false; app.get('/auth', function(req, res) { if(legit) { auth = true; res.send("success"); }); app.get('/payments-db', function(req, res) { if (auth) res.send("legit to see all payments data"); else res.send("not logged in"); }) app.listen(8080); Maciej Lasyk, node.js security
  • 10. JS security recap – global namespace pollution Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 So now imagine.. global namespace pollution + evals & co Maciej Lasyk, node.js security
  • 11. JS security recap – global namespace pollution Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 So now imagine.. global namespace pollution + evals & co Maciej Lasyk, node.js security
  • 12. JS security recap – global namespace pollution Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 So now imagine.. global namespace pollution + evals & co Watch out who you are hiring Maciej Lasyk, node.js security
  • 13. JS security recap – strict mode - let's throw all errors! - declare variables! - global namespaces help Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 14. JS security recap – strict mode Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 "use strict"; function testFunction(){ var testvar = 4; return testvar; } // This causes a syntax error. testvar = 5; Maciej Lasyk, node.js security
  • 15. JS security recap – strict mode Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 // This causes a syntax error: "use strict"; testvar = 5; // This is ok: "use strict"; var testvar = 0; testvar = 5; Maciej Lasyk, node.js security
  • 16. JS security recap – strict mode - evals & co are not that insecure now - no access to caller and args props - enable globally or for some scope - what about strict mode in 3rd party mods? Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 17. JS security recap – strict mode Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 "use strict"; function do_smt() { do_smt.caller; // no way :) do_smt.arguments; // no way :) } Maciej Lasyk, node.js security
  • 18. JS security recap – strict mode Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 "use strict"; eval("var smt = 123"); console.log(smt); // sorry – ReferenceError Maciej Lasyk, node.js security
  • 19. JS security recap – strict mode Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 "use strict"; eval("var smt = 123"); console.log(smt); // sorry – ReferenceError But watch out: "use strict"; var smt = 0; eval("smt = 123"); console.log(smt); // outputs “123” properly Maciej Lasyk, node.js security
  • 20. JS security recap – object properties - writable: RO/RW - enumerable: no loops enumeration - configurable: deletion prohibited - all default set to True so watch out Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 21. JS security recap – object properties var obj = {}; obj.prop = "LOL"; // OR: Object.defineProperty(obj, "prop", { writable: true, enumerable: true, configurable: true, value: "LOL" }) Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 22. JS security recap – object properties // RO & immutable property def: var obj = {}; Object.defineProperty(obj, "prop", { value: "LOL" }); Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 23. JS security recap – static code analysis - If not doing it already – just do - Commit hooks in (D)VCSes - JSHint / JSLint - Create policy for static code analysis - Update & check this policy regularly Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 24. about node.js: what's up? - current stable version 0.10.28 - who is using node? https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node - Operating Node.js in production/Bryan Cantrill (Joyent) - Bill Scott,“Clash of the Titans: Kraken | Node.js @ paypal” Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
  • 25. about node.js: model Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 26. about node.js: concurrency - node.js is single threaded (let's say) - multi – core? child processes (cluster.fork) - Linux containers ftw! Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 27. about node.js: SPA Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 (thx Sekurak.pl for this image) Maciej Lasyk, node.js security
  • 28. node.js sec: exploits anyone? - http://seclists.org/bugtraq – 0 hits - http://osvdb.org – 2 hits - http://1337day.com, http://www.exploitdb.com – 1 hit - http://nodesecurity.io/advisories – 4 hits Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 29. node.js sec: exploits anyone? - http://seclists.org/bugtraq – 0 hits - http://osvdb.org – 2 hits - http://1337day.com, http://www.exploitdb.com – 1 hit - http://nodesecurity.io/advisories – 4 hits Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Such security big? Maciej Lasyk, node.js security
  • 30. node.js sec: exploits anyone? - http://seclists.org/bugtraq – 0 hits - http://osvdb.org – 2 hits - http://1337day.com, http://www.exploitdb.com – 1 hit - http://nodesecurity.io/advisories – 4 hits Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Such security big? not exactly Maciej Lasyk, node.js security
  • 31. node.js sec: what's wrong? node.js security is a blank page Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 http://www.slideshare.net/ASF-WS/asfws-2012-nodejs-security-old-vulnerabilities-in-new-dresses-par-sven-vetsch Maciej Lasyk, node.js security
  • 32. node.js sec: how does sec look like? Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 33. node.js sec: how does sec look like? Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Such security..Such security.. Very fortress!!1Very fortress!!1 WOW :)WOW :) Maciej Lasyk, node.js security
  • 34. node.js sec: exceptions / callbacks callbacks Error object – remember to handle those Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var fs = require("fs"); fs.readFile("/some/file", "utf8", function (err, contents) { // err will be null if no error occured // ... otherwise there will be info about error }); forget about handling and die debugging Maciej Lasyk, node.js security
  • 35. node.js sec: exceptions / eventemitter EventEmitter: emitting events 4 async actions Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var http = require("http"); http.get("http://nodejs.org/", function (res) { res.on("data", function (chunk) { do_something_with_chunk; }); res.on("error", function (err) { // listener handling error }); }); Attach listeners to errors events or welcome unhandled exception! Maciej Lasyk, node.js security
  • 36. node.js sec: uncaught exceptions - by default node.js will print stack trace and terminate thread - EventEmitter / process / uncaughtException Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 // it looks like this by default: process.on("uncaughtException", function (err) { console.error(err); console.trace(); process.exit(); }); Maciej Lasyk, node.js security
  • 37. node.js sec: uncaught exceptions - by default node.js will print stack trace and terminate thread - EventEmitter / process / uncaughtException Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 // it looks like this by default: process.on("uncaughtException", function (err) { console.error(err); console.trace(); process.exit(); }); So do you really want to comment out the 'process.exit()' line? Maciej Lasyk, node.js security
  • 38. node.js sec: clusters scaling within multi-core envs Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var cluster = require('cluster'); var http = require('http'); var numCPUs = require('os').cpus().length; if (cluster.isMaster) { for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('exit', function(worker, code, signal) { console.log(worker.process.pid + ' died'); }); } else { http.createServer(function(req, res) { res.writeHead(200); res.end("hello worldn"); }).listen(8000); } Maciej Lasyk, node.js security
  • 39. node.js sec: domains Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Handling multiple different IO operations as a single group // don't do that: var d = require('domain').create(); d.on('error', function(er) { console.log('error, but oh well', er.message); }); d.run(function() { require('http').createServer(function(req, res) { handleRequest(req, res); }).listen(PORT); }); Maciej Lasyk, node.js security
  • 40. node.js sec: domains Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Rather use cluster & forks and exit gently..: create_cluster; fork_workers; if(worker){ var domain = require('domain'); var server = require('http').createServer(function(req, res) { var d = domain.create(); d.on('error', function(er) { console.error('error', er.stack); try { // set timeout timer // update master && print err msg // close server } catch (er2) { console.error('Error 500!', er2.stack); } } Maciej Lasyk, node.js security
  • 41. node.js sec: domains Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Using Express take look at that: https://github.com/brianc/node-domain-middleware Assigning each Express request to a separate domain? Maciej Lasyk, node.js security
  • 42. node.js sec: npm modules - npm install (-g) - who creates modules? - who verifies those? - how to update? - semantic versioning in package.json - "connect":"~1.8.7" -> 1.8.7 - 1.9 Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 43. node.js sec: npm modules --ignore-scripts stop preinstall/prepublish scripts - mods auditing: https://nodesecurity.io/ Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 44. node.js sec: npm modules The scale of npm modules Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 45. node.js sec: npm modules Comparison to other langs (mods/day): Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 46. node.js sec: npm modules Remember: - use strict? - static analysis? - does include some test suite? - what is the dependency tree? Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 47. node.js.express: connect / express Express – web dev framework Built on top of connect Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 48. node.js.express: auth.basic_auth Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var express = require('express'), app = express(); app.use(express.basicAuth("user", "pwd")); app.get("/", function (req, res) { res.send('Hello World'); }); app.listen(8080); Plain text and simple auth issues Maciej Lasyk, node.js security
  • 49. node.js.express: auth.basic_auth Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var users = { admin: "admin123", user: "user456" }; app.use(express.basicAuth(function (user, pass) { return users.hasOwnProperty(user) && users[user] === pass; })); Maciej Lasyk, node.js security
  • 50. node.js.express: auth.SSL Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var express = require('express'), routes = require('./routes'), fs = require('fs') var opts = { key: fs.readFileSync('ssl/server/keys/server.key'), cert: fs.readFileSync('ssl/server/certificates/server.crt'), ca: fs.readFileSync('ssl/ca/ca.crt'), crl: fs.readFileSync('ssl/ca/ca.crl'), requestCert: true, rejectUnauthorized: true passphrase: "pwd" // <<<< really here? }; var app = module.exports = express.createServer(opts); app.configure(function(){ app.set('views', __dirname + '/views'); ... }); app.get('/', routes.index); app.listen(8443); Maciej Lasyk, node.js security
  • 51. node.js.express: passport.js - provides API for authentication and authorization - authentication: - LocalStrategy - OpenIDStrategy - OAuth / FacebookStrategy Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 52. node.js.express: authorization Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var users = [ { id: 1, name: "user1", role: "admin" }, { id: 2, name: "user2", role: "common" }, ]; function loadUser(req, res, next) { req.userData = users[req.params.user]; return next(); } function requireRole(role) { return function (req, res, next) { if (req.user.role === role) { return next(); } else { return next(new Error("Unauthorized")); } };} Maciej Lasyk, node.js security
  • 53. node.js.express: authorization Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 app.get("/users/:user", loadUser, function (req, res) { res.send(req.user.name); }); app.del("/users/:user", requireRole("admin"), loadUser, function (req,res) { res.send("User deleted"); }); Maciej Lasyk, node.js security
  • 54. node.js.express: logging OWASP will tell you what should be logged :) https://www.owasp.org/index.php/Logging_Cheat_Sheet - authentication & authorisation - session management - errors & weirdo events - events (startups, shutdowns, slowdowns etc) - high risk functionalities (payments, privileges, admins) Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 55. node.js.express: logging Try Winston module (Github -> flatiron/winston) Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 - logging to console - logging to file - sending logs over HTTP - CouchDB, Redis, MongoDB, Riak etc Maciej Lasyk, node.js security
  • 56. node.js.express: logging Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var winston = require('winston'); var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)(), new (winston.transports.File)({ filename: 'application.log' }) ] }); Maciej Lasyk, node.js security
  • 57. node.js.express: sessions Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var express = require('express'); var app = express(); var RedisStore = require('connect-redis')(express); app.use(express.cookieParser()); app.use(express.session({ store: new RedisStore({ host: '127.0.0.2', port: 6379, db: 3, pass: 'pwd' }), secret: 'this-is-very-secret' })); app.get('/somewhere', function(req, res) { res.send('In the middle of nowhere'); }); app.listen(process.env.PORT || 8080); Maciej Lasyk, node.js security
  • 58. node.js.express: sessions Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 app.use(express.session({ secret: “very-secret”, key: “sessionId”, cookie: { httpOnly: true, secure: true } })); Maciej Lasyk, node.js security
  • 59. node.js.CSI: CSRF Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var express = require("express"), app = express(); app.use(express.cookieParser()); app.use(express.bodyParser()); app.use(express.session({ secret: "very-secret" })); app.use(express.csrf()); Maciej Lasyk, node.js security
  • 60. node.js.CSI: CSRF Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 app.get("/valid", function (req, res) { <input type="hidden" name="_csrf" value="+req.CsrfToken()+"> res.send(output); }); app.get("/invalid", function (req, res) { no_csrf_token_field res.send(output); }); Express CSRF ignores CSRF on HTTP, GET, OPTIONS, HEAD reqs Maciej Lasyk, node.js security
  • 61. node.js.CSI: input.validation Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 var express = require("express"), app = module.exports = express(); app.use(express.bodyParser()); app.use(require("express-validator")()); app.get("/", function (req, res) { res.sendfile(__dirname + "/tpls/validate.html"); }); app.post("/", function (req, res, next) { // validation req.checkBody("name").notEmpty().is(/w+/); // filtering req.sanitize("name").trim(); ... } Maciej Lasyk, node.js security
  • 62. node.js.CSI: XSS - XSS allows to access cookies, session tokens etc - or even redirect user to malicious sites - Myth: frameworks / tpls does the anti-XSS job - always encode untrusted data for correct context - OWASP ESAPI Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 63. node.js.CSI: DoS - Error handling - Use streams / chunking - Use monitoring - Use domains / clusters - Don't be afraid of SlowLoris :) Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 64. node.js.CSI: ReDoS - Regex could take exponential execution time - Is regex executed in the event loop thread? - Regex and user input? Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 https://speakerdeck.com/ckarande/top-overlooked-security-threats-to-node-dot-js-web-applications Maciej Lasyk, node.js security
  • 65. node.js.CSI: HPP HTTP Parameter Pollution Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 // POST firstName=John&firstName=John req.body.color //=> [“John”, “John”] Maciej Lasyk, node.js security
  • 66. node.js.CSI: HPP Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Modify app behavior: Maciej Lasyk, node.js security
  • 67. node.js.CSI: HPP Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 - TypeErrors, uncaught errs->DoS, - Check the expected type in the input validation - Input fuzzing / test suites - try/catch, domains, clusters Maciej Lasyk, node.js security
  • 68. node.js.CSI: HTTP_headers.CSP Content Security Policy Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Content-Security-Policy: script-src 'self'; frame-src 'none'; object-src 'none'; report-uri /my_csp_report_parser; Maciej Lasyk, node.js security
  • 69. node.js.CSI: HTTP_headers.CSP Content Security Policy Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Content-Security-Policy: script-src 'self'; frame-src 'none'; object-src 'none'; report-uri /my_csp_report_parser; app.use(helmet.csp.policy({ defaultPolicy: { "script-src": [ "'self'" ], "img-src": [ "'self'", "http://example.com/" ] } })); Maciej Lasyk, node.js security
  • 70. node.js.CSI: HTTP_headers.HSTS HTTP Strict Transport Security Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 app.use(helmet.hsts(X, true)); Strict-Transport-Security: max-age=X; includeSubdomains Requires HTTPS also on subdomains, respects configuration for X seconds Maciej Lasyk, node.js security
  • 71. node.js.CSI: HTTP_headers.X-Frame-Options Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 X-Frame-Options: DENY helmet.xframe('sameorigin'); helmet.xframe('allow-from', 'http://example.com'); Maciej Lasyk, node.js security
  • 72. node.js.CSI: HTTP_headers.others - X-Content-Type-Options - Cache-Control - X-Powered-By Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 X-Content-Type-Options: nosniff app.use(helmet.contentTypeOptions()); app.use(helmet.cacheControl()); app.disable(“x-powered-by”); Maciej Lasyk, node.js security
  • 73. node.js.CSI: request_size Just set limits use streams instead of buffering And request size: app.use(express.limit("5mb")); Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 74. node.js.CSI: environment.monitoring - is app functional? :) - is app overloaded? - app should provide monitoring interface - how many errors caught? - are forks alive and OK? Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 75. node.js.CSI: environment.resources - node.js will eat ;) - use control groups || containers - monitor resources usage Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 76. node.js.CSI: environment.sandboxing - running node.js within shared env? - selinux sandbox? - libvirt sandbox? - LXC / Docker? Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 77. node.js.CSI: environment.ACLs Just... Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25
  • 78. node.js.CSI: environment.ACLs Just... Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Don't run as `root`!!! Maciej Lasyk, node.js security
  • 79. node.js.CSI: environment.ACLs Just... Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25 Don't run as `root`!!! And also maybe behind some LB? Maciej Lasyk, node.js security
  • 80. node.js.CSI: environment.tracing_execution - SmartOS / Joyent: debugging - Bunyan / Dtrace - strace of course... Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 81. node.js.testing: testing - maybe some interface for white-box pentests? - unit-testing 4 the sake! - OWASP Zed Attack Proxy Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 82. So what else? sockets.io node-webkit Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 83. node.js.learning - Node Security Book - OWASP Node Goat (top10) - nodesecurity.io (Twitter, RSS) Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 84. node.js.hiring? - does this guy contribute? - NoSQL somehow? - not only HTTP: socket.io? - DevOps & infra? - Security? :) Maciej Lasyk, Ganglia & Nagios 3/25Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security
  • 85. Maciej Lasyk, node.js security 1/25Maciej Lasyk, node.js security Infosec && meet.js meetups
  • 86. http://maciek.lasyk.info/sysop maciek@lasyk.info @docent-net node.js security Thank you :) Maciej Lasyk, node.js security 1/25 Maciej Lasyk SEConference Kraków, 2014-05-09 Maciej Lasyk, node.js security