GithubHelp home page GithubHelp logo

nherment / node-hmac-csrf Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 144 KB

sessionless csrf with origin check, falling back to cookie based hmac token when origin is not present

JavaScript 100.00%

node-hmac-csrf's Introduction

hmac-csrf

Express middleware

sessionless csrf with

  • HTTP Origin check for modern browsers.
  • Fall back to hmac token
  • Token generated based on the session cookie. Works with hmac signed cookies with a stateless server.
  • ability to exclude routes from the CSRF path.
  • Compatible with templates
    var HmacCsrf = require('hmac-csrf')

    var options = {
      'secret'       : '123456',
      'validityDelay': 86400000,      // the delay after which a CSRF token expires, in ms
      'sessionCookie': 'connect.sid'  // the cookie used in the HMAC generation
      'algorithm'    : 'sha256',      // the HMAC algorithm
      'origin'       : null,          // If the HTTP origin header should be used for CSRF protection, put it here
      'templateAttr' : 'locals',      // the '_csrf' token will be set on res[templateAttr]
      'ignore': [                     // do not run CSRF validation for these paths
        '/foo/bar'
      ],
      'keys': {
        'query'      : '_csrf',
        'body'       : '_csrf',
        'header'     : 'x-csrf-token'
      }
    }

    // set the middleware on express (look at express documentation)
    app.use(HmacCsrf(options))

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.