Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/csrf

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/csrf - npm Package Compare versions

Comparing version 7.0.0 to 7.1.0

eslint.config.js

2

benchmark/create.js

@@ -23,3 +23,3 @@ 'use strict'

minSamples: 100,
fn: 'var token = tokens.create(secret)'
fn: 'const token = tokens.create(secret)'
})

@@ -26,0 +26,0 @@

@@ -22,3 +22,3 @@ 'use strict'

minSamples: 100,
fn: 'var secret = tokens.secretSync()'
fn: 'const secret = tokens.secretSync()'
})

@@ -25,0 +25,0 @@

@@ -24,3 +24,3 @@ 'use strict'

setup: 'token = tokens.create(secret)',
fn: 'var valid = tokens.verify(secret, token)'
fn: 'const valid = tokens.verify(secret, token)'
})

@@ -32,3 +32,3 @@

setup: 'token = tokens.create(secret).replace(/[a-zA-Z]/g, "=")',
fn: 'var valid = tokens.verify(secret, token)'
fn: 'const valid = tokens.verify(secret, token)'
})

@@ -35,0 +35,0 @@

{
"name": "@fastify/csrf",
"description": "primary logic behind csrf tokens",
"version": "7.0.0",
"version": "7.1.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",

@@ -24,3 +24,4 @@ "main": "index.js",

"bench": "node benchmark/index.js",
"lint": "standard",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",

@@ -34,3 +35,3 @@ "test:unit": "tap",

"benchmark": "^2.1.4",
"standard": "^17.1.0",
"neostandard": "^0.12.0",
"tap": "^18.7.1",

@@ -37,0 +38,0 @@ "tsd": "^0.31.0"

# CSRF
[![CI](https://github.com/fastify/csrf/workflows/CI/badge.svg)](https://github.com/fastify/csrf/actions/workflows/ci.yml)
[![CI](https://github.com/fastify/csrf/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/csrf/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/csrf.svg?style=flat)](https://www.npmjs.com/package/@fastify/csrf)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

@@ -7,0 +7,0 @@ Logic behind CSRF token creation and verification.

interface TokensConstructor {
(options?: Tokens.Options & { userInfo: true}): Tokens.TokensUserinfo;
(options?: Tokens.Options & { userInfo: true }): Tokens.TokensUserinfo;
(options?: Tokens.Options): Tokens.TokensSimple;
new(options?: Tokens.Options & { userInfo: true}): Tokens.TokensUserinfo;
new(options?: Tokens.Options & { userInfo: true }): Tokens.TokensUserinfo;
new(options?: Tokens.Options): Tokens.TokensSimple;

@@ -14,5 +14,5 @@ }

*/
secret(callback: SecretCallback): void;
secret(): Promise<string>;
secret(callback: SecretCallback): void;
secret(): Promise<string>;
/**

@@ -23,3 +23,3 @@ * Create a new secret key synchronously.

}
export interface TokensSimple extends TokensBase {

@@ -30,3 +30,3 @@ /**

create(secret: string): string;
/**

@@ -37,3 +37,3 @@ * Verify if a given token is valid for a given secret.

}
export interface TokensUserinfo extends TokensBase {

@@ -44,3 +44,3 @@ /**

create(secret: string, userInfo: string): string;
/**

@@ -51,5 +51,5 @@ * Verify if a given token is valid for a given secret.

}
export type SecretCallback = (err: Error | null, secret: string) => void;
export type SecretCallback = (err: Error | null, secret: string) => void
export interface Options {

@@ -61,6 +61,6 @@ /**

algorithm?: string;
/**
* The string length of the salt
*
*
* @default 8

@@ -71,17 +71,17 @@ */

* The byte length of the secret key
*
*
* @default 18
*/
secretLength?: number;
/**
* The maximum milliseconds of validity of this token. 0 disables the check.
*
*
* @default 0
*/
validity?: number;
/**
* Require userInfo on create() and verify()
*
*
* @default false

@@ -93,3 +93,3 @@ */

* The HMAC key used to generate the cryptographic HMAC hash
*
*
*/

@@ -112,5 +112,5 @@ hmacKey?: string | ArrayBuffer | Buffer | TypedArray | DataView | CryptoKey;

| Float32Array
| Float64Array;
| Float64Array
declare function Tokens(...params: Parameters<TokensConstructor>): ReturnType<TokensConstructor>
declare function Tokens (...params: Parameters<TokensConstructor>): ReturnType<TokensConstructor>
export = Tokens

@@ -1,19 +0,20 @@

import { expectError, expectType } from "tsd";
import { Tokens } from "..";
/* eslint-disable no-new -- Testing constructor types, so no need to assign */
import { expectError, expectType } from 'tsd'
import { Tokens } from '..'
Tokens();
new Tokens();
Tokens({});
new Tokens({});
Tokens({ algorithm: 'sha1' });
Tokens({ algorithm: 'sha256' });
Tokens({ saltLength: 10 });
Tokens({ secretLength: 10 });
Tokens({ userInfo: true });
Tokens({ validity: 10000 });
Tokens({ hmacKey: 'foo' });
new Tokens({ saltLength: 10 });
new Tokens({ secretLength: 10 });
new Tokens({ userInfo: true });
new Tokens({ validity: 10000 });
Tokens()
new Tokens()
Tokens({})
new Tokens({})
Tokens({ algorithm: 'sha1' })
Tokens({ algorithm: 'sha256' })
Tokens({ saltLength: 10 })
Tokens({ secretLength: 10 })
Tokens({ userInfo: true })
Tokens({ validity: 10000 })
Tokens({ hmacKey: 'foo' })
new Tokens({ saltLength: 10 })
new Tokens({ secretLength: 10 })
new Tokens({ userInfo: true })
new Tokens({ validity: 10000 })

@@ -23,25 +24,25 @@ expectError(Tokens('secret'))

expectError(new Tokens({}).create('secret', 'userInfo'));
expectError(new Tokens({ userInfo: false}).create('secret', 'userInfo'));
expectError(new Tokens({ userInfo: true }).create('secret'));
expectError(new Tokens({}).create('secret', 'userInfo'))
expectError(new Tokens({ userInfo: false }).create('secret', 'userInfo'))
expectError(new Tokens({ userInfo: true }).create('secret'))
expectError(new Tokens({}).verify('secret', 'token', 'userinfo'));
expectError(new Tokens({ userInfo: false}).verify('secret', 'token', 'userInfo'));
expectError(new Tokens({ userInfo: true }).verify('secret', 'token'));
expectError(new Tokens({}).verify('secret', 'token', 'userinfo'))
expectError(new Tokens({ userInfo: false }).verify('secret', 'token', 'userInfo'))
expectError(new Tokens({ userInfo: true }).verify('secret', 'token'))
expectError(new Tokens({ hmacKey: 123 }));
expectError(new Tokens({ hmacKey: 123 }))
expectType<Promise<string>>(Tokens().secret());
expectType<Promise<string>>(new Tokens().secret());
expectType<Promise<string>>(Tokens().secret())
expectType<Promise<string>>(new Tokens().secret())
expectType<void>(Tokens().secret((err, secret ) => {
expectType<Error| null>(err)
expectType<void>(Tokens().secret((err, secret) => {
expectType<Error | null>(err)
expectType<string>(secret)
}));
expectType<void>(new Tokens().secret((err, secret ) => {
expectType<Error| null>(err)
}))
expectType<void>(new Tokens().secret((err, secret) => {
expectType<Error | null>(err)
expectType<string>(secret)
}));
}))
expectType<string>(Tokens().secretSync())
expectType<string>(new Tokens().secretSync())

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc