Skip to content

Commit

Permalink
build(deps-dev): replace standard with neostandard
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Dec 8, 2024
1 parent 9eb9cb6 commit 4aed499
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/csrf-protection/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/csrf-protection/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/csrf-protection.svg?style=flat)](https://www.npmjs.com/package/@fastify/csrf-protection)
[![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)

This plugin helps developers protect their Fastify server against [CSRF](https://en.wikipedia.org/wiki/Cross-site_request_forgery) attacks.
In order to fully protect against CSRF, developers should study [Cross-Site Request Forgery Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html)
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"type": "commonjs",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit",
"test:unit": "tap",
"test:typescript": "tsd"
Expand Down Expand Up @@ -40,9 +41,9 @@
"@fastify/session": "^11.0.0",
"@types/node": "^22.0.0",
"fastify": "^5.0.0",
"neostandard": "^0.11.9",
"proxyquire": "^2.1.3",
"sinon": "^19.0.2",
"standard": "^17.1.0",
"tap": "^18.7.2",
"tsd": "^0.31.0"
},
Expand Down
27 changes: 13 additions & 14 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference types="node" />

import { FastifyPluginAsync, FastifyRequest } from 'fastify';
import { Options as CSRFOptions } from "@fastify/csrf";
import { CookieSerializeOptions as FastifyCookieSerializeOptions } from "@fastify/cookie";
import { FastifyPluginAsync, FastifyRequest } from 'fastify'
import { Options as CSRFOptions } from '@fastify/csrf'
import { CookieSerializeOptions as FastifyCookieSerializeOptions } from '@fastify/cookie'

declare module 'fastify' {
interface FastifyInstance {
Expand All @@ -20,12 +20,12 @@ declare module 'fastify' {
}
}

type FastifyCsrfProtection = FastifyPluginAsync<fastifyCsrfProtection.FastifyCsrfOptions>;
type FastifyCsrfProtection = FastifyPluginAsync<fastifyCsrfProtection.FastifyCsrfOptions>

declare namespace fastifyCsrfProtection {
export type CookieSerializeOptions = FastifyCookieSerializeOptions

export type GetTokenFn = (req: FastifyRequest) => string | void;
export type GetTokenFn = (req: FastifyRequest) => string | void

interface FastifyCsrfProtectionOptionsBase {
cookieKey?: string;
Expand All @@ -38,15 +38,15 @@ declare namespace fastifyCsrfProtection {
interface FastifyCsrfProtectionOptionsFastifyCookie {
sessionPlugin?: '@fastify/cookie';
csrfOpts?: | ({
[k in keyof CSRFOptions]: k extends "userInfo"
[k in keyof CSRFOptions]: k extends 'userInfo'
? true
: CSRFOptions[k];
} & Required<Pick<CSRFOptions, "hmacKey">>)
} & Required<Pick<CSRFOptions, 'hmacKey'>>)
| ({
[k in keyof CSRFOptions]: k extends "userInfo"
? false
: CSRFOptions[k];
});
[k in keyof CSRFOptions]: k extends 'userInfo'
? false
: CSRFOptions[k];
});
}

interface FastifyCsrfProtectionOptionsFastifySession {
Expand All @@ -68,12 +68,11 @@ declare namespace fastifyCsrfProtection {
/**
* @deprecated Use FastifyCsrfProtectionOptions instead
*/
export type FastifyCsrfOptions = FastifyCsrfProtectionOptions;
export type FastifyCsrfOptions = FastifyCsrfProtectionOptions

export const fastifyCsrfProtection: FastifyCsrfProtection
export { fastifyCsrfProtection as default }
}


declare function fastifyCsrfProtection(...params: Parameters<FastifyCsrfProtection>): ReturnType<FastifyCsrfProtection>
declare function fastifyCsrfProtection (...params: Parameters<FastifyCsrfProtection>): ReturnType<FastifyCsrfProtection>
export = fastifyCsrfProtection
13 changes: 6 additions & 7 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ declare module 'fastify' {
}
}

async function run() {
async function run () {
await fastify.register(FastifyCookie)
await fastify.register(FastifyCsrfProtection)

Expand All @@ -38,7 +38,6 @@ async function run() {
fastify.addHook('onRequest', fastify.csrfProtection)
}


fastify.register(FastifyCsrfProtection, { csrfOpts: { algorithm: 'sha1', hmacKey: 'hmac' } })
expectError(fastify.register(FastifyCsrfProtection, { csrfOpts: { algorithm: 1 } }))

Expand All @@ -47,7 +46,7 @@ fastify.register(FastifyCsrfProtection, {
csrfOpts: {
hmacKey: '123'
},
getUserInfo(req) {
getUserInfo (req) {
const info = req.session.get('username')
if (info) {
return info
Expand All @@ -61,10 +60,10 @@ expectError(fastify.register(FastifyCsrfProtection, { getUserInfo: 'invalid' }))
fastify.register(FastifyCsrfProtection, { csrfOpts: { hmacKey: 'hmac' }, sessionPlugin: '@fastify/cookie' })
fastify.register(FastifyCsrfProtection, { csrfOpts: { hmacKey: 'hmac' } })
fastify.register(FastifyCsrfProtection, { })
fastify.register(FastifyCsrfProtection, { csrfOpts: { }})
expectError(fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true}}))
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true, hmacKey: 'key'}})
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie'})
fastify.register(FastifyCsrfProtection, { csrfOpts: { } })
expectError(fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true } }))
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true, hmacKey: 'key' } })
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie' })
fastify.register(FastifyCsrfProtection, { csrfOpts: { }, sessionPlugin: '@fastify/session' })
fastify.register(FastifyCsrfProtection, { csrfOpts: { }, sessionPlugin: '@fastify/secure-session' })
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/session' })
Expand Down

0 comments on commit 4aed499

Please sign in to comment.