Git Product home page Git Product logo

crumb's Introduction

crumb Logo

CSRF crumb generation and validation for hapi

Build Status

Lead Maintainer: Marcus Stong

What to Use Crumb for and When to Use It

Crumb is used to diminish CSRF attacks using a random unique token that is validated on the server side.

Crumb may be used whenever you want to prevent malicious code to execute system commands, that are performed by HTTP requests. For example, if users are able to publish code on your website, malicious code added by a user could force every other user who opens the page, to load and execute code from a third party website e.g. via an HTML image tag. With Crumb implemented into your hapi.js application, you are able to verify requests with unique tokens and prevent the execution of malicious requests.

CORS

Crumb has been refactored to securely work with CORS, as OWASP recommends using CSRF protection with CORS.

It is highly discouraged to have a production servers cors.origin setting set to "[*]" or "true" with Crumb as it will leak the crumb token to potentially malicious sites

Plugin Options

The following options are available when registering the plugin

  • 'key' - the name of the cookie to store the csrf crumb in (defaults to 'crumb')
  • 'size' - the length of the crumb to generate (defaults to 43, which is 256 bits, see cryptile for more information)
  • 'autoGenerate' - whether to automatically generate a new crumb for requests (defaults to true)
  • 'addToViewContext' - whether to automatically add the crumb to view contexts as the given key (defaults to true)
  • 'cookieOptions' - storage options for the cookie containing the crumb, see the server.state documentation of hapi for more information
  • 'restful' - RESTful mode that validates crumb tokens from "X-CSRF-Token" request header for POST, PUT, PATCH and DELETE server routes. Disables payload/query crumb validation (defaults to false)
  • 'skip' - a function with the signature of function (request, reply) {}, which when provided, is called for every request. If the provided function returns true, validation and generation of crumb is skipped (defaults to false)

Additionally, some configuration can be passed on a per-route basis

  • 'key' - the key used in the view contexts and payloads for the crumb (defaults to whatever the key value in the main settings is)
  • 'source' - can be either 'payload' or 'query' specifying how the crumb will be sent in requests (defaults to payload)
  • 'restful' - an override for the server's 'restful' setting (defaults to match server setting)

crumb's People

Contributors

aef- avatar akanass avatar arb avatar briandela avatar cjihrig avatar dnecklesportfolio avatar eiriksm avatar geek avatar gyaresu avatar hueniverse avatar ldesplat avatar lloydbenson avatar mcandre avatar michelrossier avatar mtharrison avatar nlf avatar stongo avatar thegoleffect avatar tomsteele avatar

Watchers

 avatar  avatar

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.