Skip to content

Commit aaa777b

Browse files
authored
build(deps-dev): replace standard with neostandard (#172)
* build(deps-dev): replace standard with neostandard * chore: add eslint.config.js * test(types): add required params for fastify session plugin
1 parent 9eb9cb6 commit aaa777b

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![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)
44
[![NPM version](https://img.shields.io/npm/v/@fastify/csrf-protection.svg?style=flat)](https://www.npmjs.com/package/@fastify/csrf-protection)
5-
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
5+
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
66

77
This plugin helps developers protect their Fastify server against [CSRF](https://en.wikipedia.org/wiki/Cross-site_request_forgery) attacks.
88
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)

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict'
2+
3+
module.exports = require('neostandard')({
4+
ignores: require('neostandard').resolveIgnoresFromGitignore(),
5+
ts: true
6+
})

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"type": "commonjs",
77
"types": "types/index.d.ts",
88
"scripts": {
9-
"lint": "standard",
9+
"lint": "eslint",
10+
"lint:fix": "eslint --fix",
1011
"test": "npm run test:unit",
1112
"test:unit": "tap",
1213
"test:typescript": "tsd"
@@ -40,9 +41,9 @@
4041
"@fastify/session": "^11.0.0",
4142
"@types/node": "^22.0.0",
4243
"fastify": "^5.0.0",
44+
"neostandard": "^0.11.9",
4345
"proxyquire": "^2.1.3",
4446
"sinon": "^19.0.2",
45-
"standard": "^17.1.0",
4647
"tap": "^18.7.2",
4748
"tsd": "^0.31.0"
4849
},

types/index.d.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/// <reference types="node" />
22

3-
import { FastifyPluginAsync, FastifyRequest } from 'fastify';
4-
import { Options as CSRFOptions } from "@fastify/csrf";
5-
import { CookieSerializeOptions as FastifyCookieSerializeOptions } from "@fastify/cookie";
3+
import { FastifyPluginAsync, FastifyRequest } from 'fastify'
4+
import { Options as CSRFOptions } from '@fastify/csrf'
5+
import { CookieSerializeOptions as FastifyCookieSerializeOptions } from '@fastify/cookie'
66

77
declare module 'fastify' {
88
interface FastifyInstance {
@@ -20,12 +20,12 @@ declare module 'fastify' {
2020
}
2121
}
2222

23-
type FastifyCsrfProtection = FastifyPluginAsync<fastifyCsrfProtection.FastifyCsrfOptions>;
23+
type FastifyCsrfProtection = FastifyPluginAsync<fastifyCsrfProtection.FastifyCsrfOptions>
2424

2525
declare namespace fastifyCsrfProtection {
2626
export type CookieSerializeOptions = FastifyCookieSerializeOptions
2727

28-
export type GetTokenFn = (req: FastifyRequest) => string | void;
28+
export type GetTokenFn = (req: FastifyRequest) => string | void
2929

3030
interface FastifyCsrfProtectionOptionsBase {
3131
cookieKey?: string;
@@ -38,15 +38,15 @@ declare namespace fastifyCsrfProtection {
3838
interface FastifyCsrfProtectionOptionsFastifyCookie {
3939
sessionPlugin?: '@fastify/cookie';
4040
csrfOpts?: | ({
41-
[k in keyof CSRFOptions]: k extends "userInfo"
41+
[k in keyof CSRFOptions]: k extends 'userInfo'
4242
? true
4343
: CSRFOptions[k];
44-
} & Required<Pick<CSRFOptions, "hmacKey">>)
44+
} & Required<Pick<CSRFOptions, 'hmacKey'>>)
4545
| ({
46-
[k in keyof CSRFOptions]: k extends "userInfo"
47-
? false
48-
: CSRFOptions[k];
49-
});
46+
[k in keyof CSRFOptions]: k extends 'userInfo'
47+
? false
48+
: CSRFOptions[k];
49+
});
5050
}
5151

5252
interface FastifyCsrfProtectionOptionsFastifySession {
@@ -68,12 +68,11 @@ declare namespace fastifyCsrfProtection {
6868
/**
6969
* @deprecated Use FastifyCsrfProtectionOptions instead
7070
*/
71-
export type FastifyCsrfOptions = FastifyCsrfProtectionOptions;
71+
export type FastifyCsrfOptions = FastifyCsrfProtectionOptions
7272

7373
export const fastifyCsrfProtection: FastifyCsrfProtection
7474
export { fastifyCsrfProtection as default }
7575
}
7676

77-
78-
declare function fastifyCsrfProtection(...params: Parameters<FastifyCsrfProtection>): ReturnType<FastifyCsrfProtection>
77+
declare function fastifyCsrfProtection (...params: Parameters<FastifyCsrfProtection>): ReturnType<FastifyCsrfProtection>
7978
export = fastifyCsrfProtection

types/index.test-d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare module 'fastify' {
1212
}
1313
}
1414

15-
async function run() {
15+
async function run () {
1616
await fastify.register(FastifyCookie)
1717
await fastify.register(FastifyCsrfProtection)
1818

@@ -37,17 +37,17 @@ async function run() {
3737

3838
fastify.addHook('onRequest', fastify.csrfProtection)
3939
}
40-
40+
run()
4141

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

45-
fastify.register(FastifySession)
45+
fastify.register(FastifySession, { secret: 'a secret with minimum length of 32 characters' })
4646
fastify.register(FastifyCsrfProtection, {
4747
csrfOpts: {
4848
hmacKey: '123'
4949
},
50-
getUserInfo(req) {
50+
getUserInfo (req) {
5151
const info = req.session.get('username')
5252
if (info) {
5353
return info
@@ -61,10 +61,10 @@ expectError(fastify.register(FastifyCsrfProtection, { getUserInfo: 'invalid' }))
6161
fastify.register(FastifyCsrfProtection, { csrfOpts: { hmacKey: 'hmac' }, sessionPlugin: '@fastify/cookie' })
6262
fastify.register(FastifyCsrfProtection, { csrfOpts: { hmacKey: 'hmac' } })
6363
fastify.register(FastifyCsrfProtection, { })
64-
fastify.register(FastifyCsrfProtection, { csrfOpts: { }})
65-
expectError(fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true}}))
66-
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true, hmacKey: 'key'}})
67-
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie'})
64+
fastify.register(FastifyCsrfProtection, { csrfOpts: { } })
65+
expectError(fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true } }))
66+
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie', csrfOpts: { userInfo: true, hmacKey: 'key' } })
67+
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/cookie' })
6868
fastify.register(FastifyCsrfProtection, { csrfOpts: { }, sessionPlugin: '@fastify/session' })
6969
fastify.register(FastifyCsrfProtection, { csrfOpts: { }, sessionPlugin: '@fastify/secure-session' })
7070
fastify.register(FastifyCsrfProtection, { sessionPlugin: '@fastify/session' })

0 commit comments

Comments
 (0)