# csrf **Repository Path**: mirrors_pillarjs/csrf ## Basic Information - **Project Name**: csrf - **Description**: Logic behind CSRF token creation and verification. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-19 - **Last Updated**: 2026-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CSRF [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-image]][node-url] [![Build Status][ci-image]][ci-url] [![Test Coverage][coveralls-image]][coveralls-url] Logic behind CSRF token creation and verification. Read [Understanding-CSRF](https://github.com/pillarjs/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? * Express/connect: [csurf](https://www.npmjs.com/package/csurf) or [alt-xsrf](https://www.npmjs.com/package/alt-xsrf) * Koa: [koa-csrf](https://www.npmjs.com/package/koa-csrf) or [koa-atomic-session](https://www.npmjs.com/package/koa-atomic-session) ### Install ```sh $ npm install csrf ``` ### TypeScript This module includes a [TypeScript](https://www.typescriptlang.org/) declaration file to enable auto complete in compatible editors and type information for TypeScript projects. ## API ```js var Tokens = require('csrf') ``` ### new Tokens([options]) Create a new token generation/verification instance. The `options` argument is optional and will just use all defaults if missing. #### Options Tokens accepts these properties in the options object. ##### saltLength The length of the internal salt to use, in characters. Internally, the salt is a base 62 string. Defaults to `8` characters. ##### secretLength 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. #### tokens.create(secret) 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 `