Gathering detailed insights and metrics for @mojopizza/fastify-session
Gathering detailed insights and metrics for @mojopizza/fastify-session
Gathering detailed insights and metrics for @mojopizza/fastify-session
Gathering detailed insights and metrics for @mojopizza/fastify-session
npm install @mojopizza/fastify-session
Typescript
Module System
Min. Node Version
Node Version
NPM Version
72
Supply Chain
98.4
Quality
75.4
Maintenance
100
Vulnerability
100
License
TypeScript (98.41%)
JavaScript (1.59%)
Total Downloads
1,230
Last Day
3
Last Week
13
Last Month
28
Last Year
129
34 Stars
136 Commits
9 Forks
3 Watching
2 Branches
5 Contributors
Minified
Minified + Gzipped
Latest Version
0.15.6
Package Id
@mojopizza/fastify-session@0.15.6
Unpacked Size
54.17 kB
Size
13.90 kB
File Count
54
NPM Version
8.3.0
Node Version
16.13.1
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
160%
13
Compared to previous week
Last month
833.3%
28
Compared to previous month
Last year
-36.1%
129
Compared to previous year
3
25
Session plugin for fastify that supports both stateless and sateful sessions.
Requires fastify-cookie to handle cookies.
Can leverage crypto addons like @mgcrea/fastify-session-sodium-crypto to perform crypto.
Can leverage store addons like:
Built with TypeScript for static type checking with exported types along the library.
1npm install fastify-cookie @mgcrea/fastify-session
Defaults to a volatile in-memory store for sessions (great for tests), with hmac for signature.
1import createFastify, { FastifyInstance, FastifyServerOptions } from 'fastify'; 2import fastifyCookie from 'fastify-cookie'; 3import fastifySession from '@mgcrea/fastify-session'; 4 5const SESSION_SECRET = 'a secret with minimum length of 32 characters'; 6const SESSION_TTL = 86400; // 1 day in seconds 7 8export const buildFastify = (options?: FastifyServerOptions): FastifyInstance => { 9 const fastify = createFastify(options); 10 11 fastify.register(fastifyCookie); 12 fastify.register(fastifySession, { 13 secret: SESSION_SECRET, 14 cookie: { maxAge: SESSION_TTL }, 15 }); 16 17 return fastify; 18};
For better performance/security, you can use the @mgcrea/fastify-session-sodium-crypto addon:
Leveraging an external redis store, the session id (generated with nanoid) is signed using a secret-key with libsodium's crytpo_auth
1import createFastify, { FastifyInstance, FastifyServerOptions } from 'fastify'; 2import fastifyCookie from 'fastify-cookie'; 3import fastifySession from '@mgcrea/fastify-session'; 4import { SODIUM_AUTH } from '@mgcrea/fastify-session-sodium-crypto'; 5 6const SESSION_KEY = 'Egb/g4RUumlD2YhWYfeDlm5MddajSjGEBhm0OW+yo9s=''; 7const SESSION_TTL = 86400; // 1 day in seconds 8const REDIS_URI = process.env.REDIS_URI || 'redis://localhost:6379/1'; 9 10export const buildFastify = (options?: FastifyServerOptions): FastifyInstance => { 11 const fastify = createFastify(options); 12 13 fastify.register(fastifyCookie); 14 fastify.register(fastifySession, { 15 key: Buffer.from(SESSION_KEY, 'base64'), 16 crypto: SODIUM_AUTH, 17 store: new RedisStore({ client: new Redis(REDIS_URI), ttl: SESSION_TTL }), 18 cookie: { maxAge: SESSION_TTL }, 19 }); 20 21 return fastify; 22};
No external store required, the entire session data is encrypted using a secret-key with libsodium's crypto_secretbox_easy
Here we used a secret
instead of providing a key
, key derivation will happen automatically on startup.
1import createFastify, { FastifyInstance, FastifyServerOptions } from 'fastify'; 2import fastifyCookie from 'fastify-cookie'; 3import fastifySession from '@mgcrea/fastify-session'; 4import { SODIUM_SECRETBOX } from '@mgcrea/fastify-session-sodium-crypto'; 5 6const SESSION_TTL = 86400; // 1 day in seconds 7 8export const buildFastify = (options?: FastifyServerOptions): FastifyInstance => { 9 const fastify = createFastify(options); 10 11 fastify.register(fastifyCookie); 12 fastify.register(fastifySession, { 13 secret: 'a secret with minimum length of 32 characters', 14 crypto: SODIUM_SECRETBOX, 15 cookie: { maxAge: SESSION_TTL }, 16 }); 17 18 return fastify; 19};
1NODE_PATH=. y ts-node --project test/tsconfig.json test/benchmark/cryptoSeal.ts
1SODIUM_SECRETBOX#sealJson x 333,747 ops/sec ±0.62% (91 runs sampled) 2SODIUM_AUTH#sealJson x 376,300 ops/sec ±0.50% (89 runs sampled) 3HMAC#sealJson x 264,292 ops/sec ±3.13% (85 runs sampled) 4Fastest is SODIUM_AUTH#sealJson
1NODE_PATH=. y ts-node --project test/tsconfig.json test/benchmark/cryptoUnseal.ts
1SODIUM_SECRETBOX#unsealJson x 424,297 ops/sec ±0.69% (86 runs sampled) 2SODIUM_AUTH#unsealJson x 314,736 ops/sec ±0.96% (89 runs sampled) 3HMAC#unsealJson x 145,037 ops/sec ±5.67% (78 runs sampled) 4Fastest is SODIUM_SECRETBOX#unsealJson
Heavily inspired from
1The MIT License 2 3Copyright (c) 2020 Olivier Louvignes <olivier@mgcrea.io> 4 5Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 6documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 7rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 8persons to whom the Software is furnished to do so, subject to the following conditions: 9 10The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 11Software. 12 13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 14WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 15COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
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