Giter Club home page Giter Club logo

express-security's Introduction

express security playground

My nodejs + express security and performance playground (boilerplate).

Security Known Vulnerabilities

  1. Cookie auth (secure, http-only, sameSite)
  2. Signed session + sliding expiration
  3. Cross-Site Request Forgery (CSRF)
  4. Cross-Site WebSocket Hijacking (CSWSH)
  5. Content-Security-Policy (CSP, nonce)
  6. Strict-Transport-Security (HSTS)
  7. Public-Key-Pins (HPKP)
  8. X-Frame-Options
  9. X-XSS-Protection
  10. X-Powered-By
  11. X-Download-Options
  12. X-Content-Type-Options
  13. Rate limits (number of requests per second)

Performance

  1. HTTP2
  2. Client caching (cache-control, e-tags, expires, last-modified, cache busting)
  3. Client assets minification
  4. GZIP, deflate
  5. Precompressed assets (Brotli and Gzip support)
  6. Imagemin
  7. Node cluster
  8. Memory and redis caching

Others

  1. HTTPS
  2. Redis store (session, caching)
  3. Web sockets (socket.io, cookies authentication, shared session, redis store)
  4. Logging (winston -> Console, FileSystem)
  5. Custom errors (4XX, 5XX)
  6. Configuration + Environment (config.json + config.dev.json)
  7. Nodemon
  8. Webpack + babel + SASS + postcss + autoprefixer
  9. ES6 modules (babel, babel-preset-env)
  10. Unit tests (ES6, mocha + chai)
  11. E2E tests (ES6, mocha + chai, supertest + superagent)
  12. ESLint 3 (linting server, client, tests and pug templates)
  13. npm scripts (npm-run-all, cross-env, client tasks, server tasks)
  14. http://realfavicongenerator.net/
  15. Pug view engine

How to run

Disclaimer: The main purpose of this repository is to demonstrate security, caching and performance principles, it's not about DB, UI, UX.

Certificate

The application runs only on HTTPS, so a certificate is required. If you want to just try it locally, then generate self-signed certificate online for domain localhost and save both files into the server/certificates/ folder. Name them server.cert and server.key.

Redis The application uses Redis to store sessions, caching, websockets and saving rate limits. Please follow their installation guide.

Production build

  1. run yarn install or npm install
  2. run yarn run start or npm run start
  3. open URL https://localhost:8443/ in a browser (you can change the port if you re-run the previous command with PORT=8444 yarn run start)
  4. use any username and password to log in. There is no real DB behind the app, it's not the main purpose of the demo.

Development

  1. run yarn install or npm install
  2. run yarn run build:client
  3. run yarn run watch:server (runs nodemon so any change in server's code immediately restarts server)
  4. open URL https://localhost:5000/ in a browser (you can change the port in nodemon.json)

Running the cluster

The application can run as a cluster of node applications. Use "useCluster" option in server/config/config.json:

  • "auto": no cluster in dev mode, all possible cores in prod mode.
  • true: all possible cores in all modes.
  • any number: spawn a given number of instances.
  • anything else: no cluster in any mode.

Configuring application

You can change server/config/config.json file directly. If you are in development mode and you don't want to commit your config changes, then create config.dev.json next to the original JSON file and store your overrides there. Both configs are deeply merged together, config.dev.json takes precedence.

Running tests

  • run yarn run test:unit to run unit tests only
  • run yarn run test:vulnerabilities to check app dependencies for vulnerabilities (using nsp)

to run e2e tests, you have to start the server in development first

  • then run yarn run test:e2e

If you want to run all tests, start the server in development mode and then run yarn run test

The application uses rate limiters to prevent hundreds of requests from the same IP address. This protection must be turned off while running e2e tests, otherwise the tests will start to fail randomly after the limits are reached. To turn it off, create config.dev.json and add into it:

{
  "rateLimiter": {
    "enabled": false
  }
}

express-security's People

Contributors

mcibique avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

express-security's Issues

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.