Giter Site home page Giter Site logo

sfnode-nov-2018's Introduction

SFNode meetup talk (November 2018)

Intro

Security happens in layers. Node.js is part of an ecosystem. There are many tools that will help you code quickly but still remain secure. Just because you add security doesn't mean vulnerabilities disappear. Good security should give you more time to react and counter active attacks.

Security happens in Layers, the ecosystem

alt text

Threats by category, Top 10 Threats 2017

  • "tl;dr" Solution: make sure to validate the data you get from users.
  • Prevent query injection vulnerabilities by using ORM/ODM libraries like Mongoose have this feature. Below is an video of an academic example of this vulnerability.
  • Avoid JavaScript eval statements and new Function
  • Avoid module loading require(someVariable) using a variable
  • "tl;dr" Solution: encrypt sensitive data.
  • Extract secrets from config files or use packages to encrypt them
    • Pass secrets wtih environment variables and save the secrets in a file on your server.
    • use cryptr
  • "tl;dr" Solution: use JSON and avoid serializing sensitive data.
  • Run unsafe code in a sandbox
    • use a dedicated child process
    • use a cloud serverless framework
    • use libraries like sandbox or vm2
  • Take extra care when working with child processes
    • use the child_process.execFile if you are unsure
  • "tl;dr" Solution: deny access by default.
  • Run Node.js as non-root user
  • "tl;dr" Solution: review default settings to secure installation.
  • Adjust the HTTP response headers for enhanced security
    • use helmet to protect express servers
  • Hide error details from clients
    • set NODE_ENV to production
  • Modify session middleware settings, don't use the defaults.
  • "tl;dr" Solution: separate untrusted data from browser content.
  • Escape HTML, JS, and CSS output
  • "tl;dr" Solution: no serialized data from untrusted sources.
  • Validate incoming JSON schemas
  • Limit payload size using a reverse proxy or middleware. - configure express bodyparser to accept small-size payloads
  • "tl;dr" Solution: read the logs for unusual activity.
  • use due diligence. Check logs, write scripts, use things like linkerd or splunk to monitor possible intrusions.

DDOS

  • Limit concurrent requests using a middleware. Cloud load balancers and firewalls can be configured to help with this.
  • Avoid DOS attacks by explicitly setting when a process should crash
  • Prevent RegEx from overloading your single thread execution with an overly complex query.

alt text

User input is a major vulnerability, please treat it like hostile code and sanitize it. Filter and validate user input.

Threats in the Wild

Acknowledgements

sfnode-nov-2018's People

Contributors

trewaters avatar

Stargazers

Ivan Ka avatar Palmer Oliveira avatar Zbyszek Tenerowicz avatar

Watchers

James Cloos avatar  avatar

Forkers

ik-security

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.