Gathering detailed insights and metrics for csrf
Gathering detailed insights and metrics for csrf
Gathering detailed insights and metrics for csrf
Gathering detailed insights and metrics for csrf
koa-csrf
CSRF tokens for Koa
csrf-csrf
A utility package to help implement stateless CSRF protection using the Double Submit Cookie Pattern in express.
think-csrf
CSRF for ThinkJS 3.x
csrf-sync
A utility package to help implement stateful CSRF protection using the Synchroniser Token Pattern in express.
npm install csrf
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99
Supply Chain
99.5
Quality
77.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
207,012,544
Last Day
130,286
Last Week
755,021
Last Month
3,275,682
Last Year
37,923,708
MIT License
310 Stars
293 Commits
32 Forks
18 Watchers
1 Branches
27 Contributors
Updated on Apr 24, 2025
Minified
Minified + Gzipped
Latest Version
3.1.0
Package Id
csrf@3.1.0
Size
4.69 kB
NPM Version
6.4.1
Node Version
8.15.1
Published on
Apr 10, 2019
Cumulative downloads
Total Downloads
Last Day
31.1%
130,286
Compared to previous day
Last Week
2.7%
755,021
Compared to previous week
Last Month
-6.1%
3,275,682
Compared to previous month
Last Year
36.1%
37,923,708
Compared to previous year
Logic behind CSRF token creation and verification.
Read Understanding-CSRF for more information on CSRF. Use this module to create custom CSRF middleware.
Looking for a CSRF framework for your favorite framework that uses this module?
1$ npm install csrf
This module includes a TypeScript declaration file to enable auto complete in compatible editors and type information for TypeScript projects.
1var Tokens = require('csrf')
Create a new token generation/verification instance. The options
argument is
optional and will just use all defaults if missing.
Tokens accepts these properties in the options object.
The length of the internal salt to use, in characters. Internally, the salt
is a base 62 string. Defaults to 8
characters.
The length of the secret to generate, in bytes. Note that the secret is
passed around base-64 encoded and that this length refers to the underlying
bytes, not the length of the base-64 string. Defaults to 18
bytes.
Create a new CSRF token attached to the given secret
. The secret
is a
string, typically generated from the tokens.secret()
or tokens.secretSync()
methods. This token is what you should add into HTML <form>
blocks and
expect the user's browser to provide back.
1var secret = tokens.secretSync() 2var token = tokens.create(secret)
Asynchronously create a new secret
, which is a string. The secret is to
be kept on the server, typically stored in a server-side session for the
user. The secret should be at least per user.
1tokens.secret(function (err, secret) { 2 if (err) throw err 3 // do something with the secret 4})
Asynchronously create a new secret
and return a Promise
. Please see
tokens.secret(callback)
documentation for full details.
Note: To use promises in Node.js prior to 0.12, promises must be
"polyfilled" using global.Promise = require('bluebird')
.
1tokens.secret().then(function (secret) { 2 // do something with the secret 3})
A synchronous version of tokens.secret(callback)
. Please see
tokens.secret(callback)
documentation for full details.
1var secret = tokens.secretSync()
Check whether a CSRF token is valid for the given secret
, returning
a Boolean.
1if (!tokens.verify(secret, token)) { 2 throw new Error('invalid token!') 3}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
11 different organizations found -- score normalized to 10
Details
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
no vulnerabilities detected
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
0 out of 1 merged PRs checked by a CI test -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
found 29 unreviewed changesets out of 30 -- score normalized to 0
Reason
no update tool detected
Details
Reason
project is not fuzzed
Details
Reason
0 commit(s) out of 30 and 0 issue activity out of 8 found in the last 90 days -- score normalized to 0
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Score
Last Scanned on 2025-05-05T21:28:37Z
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More