Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing NodeJS Security

jmortegac
November 18, 2016

Testing NodeJS Security

Testing NodeJS Security

jmortegac

November 18, 2016
Tweet

More Decks by jmortegac

Other Decks in Programming

Transcript

  1. nodeJS introduction  JavaScript in the backend  Built on

    Chrome´s Javascript runtime(V8)  NodeJs is based on event loop  Designed to be asynchronous  Single Thread  Concurrent requests.
  2. Npm security packages  Helmet  express-session / cookie-session 

    csurf  express-validator  bcrypt-node  express-enforces-ssl
  3. Helmet module  CSPContent-Security-Policy header  hidePoweredBydeletes X-Powered-by header 

    Hpkpprotection MITM  Hstsforces https connections  noCachedesactive client cache  Frameguardprotection clickjacking  xssFilterprotection XSS
  4. Delete cookies from cache browser // Set cache control header

    to eliminate cookies from cache app.use(function (req, res, next) { res.header('Cache-Control', 'no-cache="Set-Cookie, Set-Cookie2"'); next(); });
  5. XSS attacks  An attacker can exploit XSS vulnerability to:

     Steal session cookies/Sesion hijacking  Redirect user to malicious sites  Defacing and content manipulation  Cross Site Request forgery
  6. CSRF <form action="/process" method="POST"> <input type="hidden" name="_csrf" value="{{csrfToken}}"> <button type="submit">Submit</button>

    </form> app.use(function (request, response, next) { response.locals.csrftoken = request.csrfToken(); next(); });
  7. Filter/sanitize user input  Avoid XSS attacks  https://www.npmjs.com/package/sanitizer 

    Module express-validator  https://www.npmjs.com/package/express-validator
  8. NodeJS Crypto  http://nodejs.org/api/crypto.html  Use require(‘crypto’) to access this

    module  The crypto module requires OpenSSL require("crypto") .createHash("sha1") //algorithm .update(“cOdEmOtiOn") //text .digest("hex"); //hexadecimal result
  9. Building a secure HTTPS server var helmet = require("helmet"); var

    ms = require("ms"); app.use(helmet.hsts({ maxAge: ms("1 year"), includeSubdomains: true }));  Send hsts header for all requests
  10. Tools  NSP  Require Safe  David  KrakenJS

    / Lusca middleware  Retire  snyk.io