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')
axios.get('/api')
Options
csrfMonkey('my-custom-csrf-header')
csrfMonkey('my-custom-csrf-header', 'my-csrf-token')
Restore
var restore = csrfMonkey()
restore()
Credits