Tox1469/csrf-token

GitHub: Tox1469/csrf-token

一个基于 HMAC‑SHA256 的 CSRF 令牌生成与验证工具,解决跨站请求伪造防护中的令牌一致性与安全性问题。

Stars: 0 | Forks: 0

[![CI](https://img.shields.io/github/actions/workflow/status/Tox1469/csrf-token/ci.yml?style=flat-square&label=ci)](https://github.com/Tox1469/csrf-token/actions) [![License](https://img.shields.io/github/license/Tox1469/csrf-token?style=flat-square)](LICENSE) [![Release](https://img.shields.io/github/v/release/Tox1469/csrf-token?style=flat-square)](https://github.com/Tox1469/csrf-token/releases) [![Stars](https://img.shields.io/github/stars/Tox1469/csrf-token?style=flat-square)](https://github.com/Tox1469/csrf-token/stargazers) # csrf-token 生成和验证 HMAC-SHA256 CSRF tokens。 ## 安装 ``` npm install csrf-token ``` ## 用法 ``` import { createToken, verifyToken } from 'csrf-token'; const token = createToken(process.env.SECRET!, sessionId); const ok = verifyToken(token, process.env.SECRET!, sessionId); ``` ## API - `createToken(secret, sessionId)` — 生成 nonce + HMAC。 - `verifyToken(token, secret, sessionId)` — 返回布尔值。 ## 安全性 请与 SameSite=Lax/Strict cookies 结合使用。请使用常数时间进行比较。 ## 许可证 MIT
标签:自动化攻击