thinkjs/think-csrf
GitHub: thinkjs/think-csrf
这是一个为ThinkJS 3.0提供的CSRF防护中间件,用于解决Web应用中的跨站请求伪造安全问题。
Stars: 2 | Forks: 1
此仓库已迁移。如需持续更新,请访问 https://img.shields.io/npm/v/think-csrf.svg。
# decide on the translation. Let's assume "think-csrf" is a technical term, so I'll keep it in English. But the examples show translation of other parts.
[](https://www.npmjs.com/package/think-csrf)
[](https://travis-ci.org/thinkjs/think-csrf)
[](https://coveralls.io/github/thinkjs/think-csrf?branch=master)
适用于 Thinkjs 3.0 的 CSRF 防护
## 安装说明
```
$ npm install think-csrf --save
```
## 使用方法
配置文件 `src/config/middleware.js`
```
const csrf = require('think-csrf');
module.exports = [{
handle: csrf,
options: {
session_name: 'csrf_token',
form_name: '_csrf',
header_name: 'x-csrf-token'
}
}];
```
**用法**
通过 `ctx.csrf` 获取器获取 CSRF token。
## 选项配置
| 名称 | 描述 | 默认值 |
| :------ | :------ | :------ |
| `session_name` | csrf token 的 session 名称 | `'csrf_token'` |
| `form_name` | 在请求体和查询参数中携带 csrf token 的字段名 | `'_csrf'` |
| `header_name` | 在请求头中携带 csrf token 的字段名 | `'x-csrf-token'` |
| `errno` | 错误状态码 | `403` |
| `errmsg` | 错误信息 | `'invalid csrf token'` |
标签:CMS安全, CSRF防护, GNU通用公共许可证, JavaScript, MITM代理, Node.js, npm包, Syscall, ThinkJS, TypeScript, Web安全, Web开发, 令牌验证, 会话管理, 前端安全, 后端安全, 安全中间件, 安全插件, 数据可视化, 框架安全, 网络安全, 自定义脚本, 蓝队分析, 隐私保护