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.
csrf-sync
A utility package to help implement stateful CSRF protection using the Synchroniser Token Pattern in express.
think-csrf
CSRF for ThinkJS 3.x
npm install csrf
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99
Supply Chain
99.5
Quality
79
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
314 Stars
294 Commits
35 Forks
17 Watchers
9 Branches
28 Contributors
Updated on Jul 10, 2025
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
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
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
update tool detected
Details
Reason
license file detected
Details
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
no vulnerabilities detected
Reason
security policy file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
dependency not pinned by hash detected -- score normalized to 6
Details
Reason
1 out of 2 merged PRs checked by a CI test -- score normalized to 5
Reason
branch protection not enabled on development/release branches
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
found 29 unreviewed changesets out of 30 -- score normalized to 0
Reason
project is not fuzzed
Details
Reason
1 commit(s) out of 30 and 0 issue activity out of 8 found in the last 90 days -- score normalized to 0
Score
Last Scanned on 2025-07-07T21: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