🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

csrf-monkey

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csrf-monkey

Monkeypatch xhr and fetch to automatically add csrf tokens to clientside requests

1.0.2
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Travis CI devDependency Status js-standard-style

csrf-monkey

Clientside csrf made simple

  • configurable, testable and restorable
  • handles both xhr and fetch
  • 100% test coverage
  • small footprint, no dependencies

Installation

npm install --save csrf-monkey

Usage

Default behaviour

Put your csrf token in a meta tag in your head like so:

<html>
  <head>
    <meta name='csrf-token' content='value'>
  </head>
  <body></body>
</html>

Then call csrf-monkey to patch xhr and window.fetch to automatically include the csrf token in all requests

var axios = require('axios')
var csrfMonkey = require('csrf-monkey')
csrfMonkey()


fetch('/api') // request will include csrf header ('x-csrf-token': value)
axios.get('/api') // request will include csrf header ('x-csrf-token': value)

Options

// csrfMonkey(header, token)

// you can also pass a custom header to csrf-monkey:
csrfMonkey('my-custom-csrf-header')

// and you can pass your csrf token value directly to csrf-monkey if you don't want to include it as a meta tag:
csrfMonkey('my-custom-csrf-header', 'my-csrf-token')

Restore

var restore = csrfMonkey()
restore() // Restores everything back to how it was

Credits

  • Inspired by csrf-xhr

FAQs

Package last updated on 13 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts