Socket
Socket
Sign inDemoInstall

@fastify/cookie

Package Overview
Dependencies
Maintainers
19
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/cookie - npm Package Compare versions

Comparing version 7.4.0 to 8.0.0

types/plugin.d.ts

9

package.json
{
"name": "@fastify/cookie",
"version": "7.4.0",
"version": "8.0.0",
"description": "Plugin for fastify to add support for cookies",
"main": "plugin.js",
"types": "plugin.d.ts",
"types": "types/plugin.d.ts",
"scripts": {

@@ -45,3 +45,3 @@ "lint": "standard | snazzy",

"benchmark": "^2.1.4",
"fastify": "^4.0.0-rc.2",
"fastify": "^4.0.0",
"sinon": "^14.0.0",

@@ -51,4 +51,3 @@ "snazzy": "^9.0.0",

"tap": "^16.0.0",
"tsd": "^0.22.0",
"typescript": "^4.5.5"
"tsd": "^0.22.0"
},

@@ -55,0 +54,0 @@ "dependencies": {

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

function plugin (fastify, options, next) {
const secret = options.secret || ''
const secret = options.secret
const enableRotation = Array.isArray(secret)

@@ -72,11 +72,19 @@ const algorithm = options.algorithm || 'sha256'

fastify.decorate('parseCookie', parseCookie)
fastify.decorate('signCookie', signCookie)
fastify.decorate('unsignCookie', unsignCookie)
if (typeof secret !== 'undefined') {
fastify.decorate('signCookie', signCookie)
fastify.decorate('unsignCookie', unsignCookie)
fastify.decorateRequest('signCookie', signCookie)
fastify.decorateRequest('unsignCookie', unsignCookie)
fastify.decorateReply('signCookie', signCookie)
fastify.decorateReply('unsignCookie', unsignCookie)
}
fastify.decorateRequest('cookies', null)
fastify.decorateRequest('unsignCookie', unsignCookie)
fastify.decorateReply('cookie', setCookie)
fastify.decorateReply('setCookie', setCookie)
fastify.decorateReply('cookie', setCookie)
fastify.decorateReply('clearCookie', clearCookie)
fastify.decorateReply('unsignCookie', unsignCookie)

@@ -83,0 +91,0 @@ fastify.addHook('onRequest', onReqHandlerWrapper(fastify))

@@ -195,5 +195,5 @@ # @fastify/cookie

The method `unsignCookie(value)` is added to the `fastify` instance and the `reply` object
via the Fastify `decorate` & `decorateReply` APIs. Using it on a signed cookie will call the
the provided signer's (or the default signer if no custom implementation is provided) `unsign` method on the cookie.
The method `unsignCookie(value)` is added to the `fastify` instance, to the `request` and the `reply` object
via the Fastify `decorate`, `decorateRequest` and `decorateReply` APIs, if a secret was provided as option.
Using it on a signed cookie will call the the provided signer's (or the default signer if no custom implementation is provided) `unsign` method on the cookie.

@@ -200,0 +200,0 @@ **Example:**

@@ -817,1 +817,34 @@ 'use strict'

})
test('should not decorate fastify, request and reply if no secret was provided', async (t) => {
t.plan(8)
const fastify = Fastify()
await fastify.register(plugin)
t.notOk(fastify.signCookie)
t.notOk(fastify.unsignCookie)
fastify.get('/testDecorators', (req, reply) => {
t.notOk(req.signCookie)
t.notOk(reply.signCookie)
t.notOk(req.unsignCookie)
t.notOk(reply.unsignCookie)
reply.send({
unsigned: req.unsignCookie(req.cookies.foo)
})
})
const res = await fastify.inject({
method: 'GET',
url: '/testDecorators'
})
t.equal(res.statusCode, 500)
t.same(JSON.parse(res.body), {
statusCode: 500,
error: 'Internal Server Error',
message: 'req.unsignCookie is not a function'
})
})
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