https://github.com/thinkjs/think-csrf
CSRF for ThinkJS 3.0
https://github.com/thinkjs/think-csrf
csrf think-middleware thinkjs3
Last synced: 8 months ago
JSON representation
CSRF for ThinkJS 3.0
- Host: GitHub
- URL: https://github.com/thinkjs/think-csrf
- Owner: thinkjs
- License: mit
- Created: 2017-05-23T03:23:11.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-06-30T23:51:22.000Z (almost 5 years ago)
- Last Synced: 2025-01-24T11:35:03.954Z (over 1 year ago)
- Topics: csrf, think-middleware, thinkjs3
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 2
- Watchers: 13
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# think-csrf
[](https://www.npmjs.com/package/think-csrf)
[](https://travis-ci.org/thinkjs/think-csrf)
[](https://coveralls.io/github/thinkjs/think-csrf?branch=master)
CSRF for Thinkjs 3.0
## Install
```
$ npm install think-csrf --save
```
## How to use
config file `src/config/middleware.js`
```javascript
const csrf = require('think-csrf');
module.exports = [{
handle: csrf,
options: {
session_name: 'csrf_token',
form_name: '_csrf',
header_name: 'x-csrf-token'
}
}];
```
**Usage**
`ctx.csrf` getter for CSRF token
## Options
| Name | Description | Default |
| :------ | :------ | :------ |
| `session_name` | csrf token's session name | `'csrf_token'` |
| `form_name` | request csrf token's name in body and query | `'_csrf'` |
| `header_name` | request csrf token's name in header | `'x-csrf-token'` |
| `errno` | error status | `403` |
| `errmsg` | error message | `'invalid csrf token'` |