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

enterJS 2014 - Securing your Node.js & Single Page Apps

enterJS 2014 - Securing your Node.js & Single Page Apps

Securing your Node.js & Single Page Apps

Mark Stuart

July 01, 2014
Tweet

More Decks by Mark Stuart

Other Decks in Programming

Transcript

  1. Steal SSH keys or configs Read/write files Execute binaries Cause

    server to hang Tamper with routes Inject XSS Steal session data Crash server
  2. Steal SSH keys or configs Read/write files Execute binaries Cause

    server to hang Tamper with routes Inject XSS Steal session data Crash server
  3. Steal SSH keys or configs Read/write files Execute binaries Cause

    server to hang Tamper with routes Inject XSS Steal session data Crash server
  4. Steal SSH keys or configs Read/write files Execute binaries Cause

    server to hang Tamper with routes Inject XSS Steal session data Crash server
  5. Steal SSH keys or configs Read/write files Execute binaries Cause

    server to hang Tamper with routes Inject XSS Steal session data Crash server
  6. Steal SSH keys or configs Read/write files Execute binaries Cause

    server to hang Tamper with routes Inject XSS Steal session data Crash server
  7. Steal SSH keys or configs Read/write files Execute binaries Cause

    server to hang Tamper with routes Inject XSS Steal session data Crash server
  8. Steal SSH keys or configs Read/write files Execute binaries Cause

    server to hang Tamper with routes Inject XSS Steal session data Crash server
  9. app.use(lusca.csrf()); app.use(lusca.csp({ /* ... */ })); app.use(lusca.hsts({ maxAge: 31536000 });

    app.use(lusca.xframe('SAMEORIGIN')); app.use(lusca.p3p('ABCDEF')); app.use(lusca.xssProtection(true);
  10. CSRF <form name=“someHiddenForm” action=“http://yoursite.com/webapps/ transferFunds”> <input type=“hidden” name=“amount” value=“500.00” />

    <input type=“hidden” name=“recipient” value=“[email protected]” /> </form> ! <script>document.forms.someHiddenForm.submit();</script>
  11. CSP

  12. Content-Security-Policy: default-src 'self' https://*.your-cdn.com; script-src 'self' https://*.your-cdn.com; img-src https://*.your-cdn.com data:;

    object-src 'self'; font-src 'self' https://*.googlefonts.com; connect-src … frame-src … style-src … media-src …
  13. app.use(lusca.csrf()); app.use(lusca.csp({ /* ... */ })); app.use(lusca.hsts({ maxAge: 31536000 });

    app.use(lusca.xframe('SAMEORIGIN')); app.use(lusca.p3p('ABCDEF')); app.use(lusca.xssProtection(true);
  14. ! Wed, 21 May 2014 18:49:00 GMT ! uncaughtException Object

    #<Object> has no method ‘forEach'! ! TypeError: Object #<Object> has no method 'forEach'! at module.exports.fetchSettings (/Users/marstuart/oddjob/helpers.js:174:18)! ! Process finished with exit code 1!
  15. 1. Know what you require() 2. Node is still JavaScript

    3. Do not run as root 3. Use good security defaults 4. Security can be automated, too!
  16. # Attacker yoursite.com PUT /account/edit { firstName: ‘<script>…’ } #

    Victim # Victim <script>…</script> GET /addressBook <script>…</script> GET /addressBook yoursite.com yoursite.com
  17. Running "retire:jsPath" (retire) task! ! >> test-files/jquery-1.6.js! >> ↳ jquery

    1.6 has known vulnerabilities: http://web.nvd.nist.gov/view/ vuln/detail?vulnId=CVE-2011-4969! ! >> Aborted due to warnings. npm install grunt-retire --save-dev grunt retire
  18. Ok.