Socket
Socket
Sign inDemoInstall

@fastify/cookie

Package Overview
Dependencies
Maintainers
19
Versions
27
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 9.0.1 to 9.0.2

2

package.json
{
"name": "@fastify/cookie",
"version": "9.0.1",
"version": "9.0.2",
"description": "Plugin for fastify to add support for cookies",

@@ -5,0 +5,0 @@ "main": "plugin.js",

@@ -9,9 +9,5 @@ 'use strict'

const kReplySetCookies = Symbol('fastify.reply.setCookies')
const kReplySetCookiesHookRan = Symbol('fastify.reply.setCookiesHookRan')
function fastifyCookieSetCookie (reply, name, value, options) {
let sendHeaders = false
if (reply[kReplySetCookies] === null) {
sendHeaders = true
reply[kReplySetCookies] = new Map()
}
const opts = Object.assign({}, options)

@@ -38,3 +34,3 @@

if (sendHeaders) {
if (reply[kReplySetCookiesHookRan]) {
setCookies(reply)

@@ -79,5 +75,6 @@ }

let setCookie = reply.getHeader('Set-Cookie')
const setCookieIsUndefined = setCookie === undefined
/* istanbul ignore else */
if (setCookie === undefined) {
if (setCookieIsUndefined) {
if (reply[kReplySetCookies].size === 1) {

@@ -88,2 +85,4 @@ for (const c of reply[kReplySetCookies].values()) {

reply[kReplySetCookies].clear()
return

@@ -101,4 +100,5 @@ }

reply.removeHeader('Set-Cookie')
if (!setCookieIsUndefined) reply.removeHeader('Set-Cookie')
reply.header('Set-Cookie', setCookie)
reply[kReplySetCookies].clear()
}

@@ -111,5 +111,3 @@

// Explicitly set the property to null so that we can
// check if the header was already set
fastifyRes[kReplySetCookies] = null
fastifyRes[kReplySetCookiesHookRan] = true

@@ -156,2 +154,3 @@ done()

fastify.decorateReply(kReplySetCookies, null)
fastify.decorateReply(kReplySetCookiesHookRan, false)

@@ -158,0 +157,0 @@ fastify.decorateReply('cookie', setCookie)

@@ -27,3 +27,4 @@ 'use strict'

function validateSecrets (secrets) {
for (const secret of secrets) {
for (let i = 0; i < secrets.length; ++i) {
const secret = secrets[i]
if (typeof secret !== 'string' && Buffer.isBuffer(secret) === false) {

@@ -63,3 +64,4 @@ throw new TypeError('Secret key must be a string or Buffer.')

for (const secret of secrets) {
for (let i = 0; i < secrets.length; ++i) {
const secret = secrets[i]
const expected = Buffer.from(crypto

@@ -66,0 +68,0 @@ .createHmac(algorithm, secret)

@@ -1190,1 +1190,40 @@ 'use strict'

})
test('cookies get set correctly if set inside multiple onSends', (t) => {
t.plan(10)
const fastify = Fastify()
fastify.register(plugin)
fastify.addHook('onSend', async (req, reply, payload) => {
reply.setCookie('foo', 'foo', { path: '/' })
})
fastify.addHook('onSend', async (req, reply, payload) => {
reply.setCookie('foo', 'foos', { path: '/' })
return payload
})
fastify.get('/test1', (req, reply) => {
reply
.send({ hello: 'world' })
})
fastify.inject({
method: 'GET',
url: '/test1'
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 200)
t.same(JSON.parse(res.body), { hello: 'world' })
const cookies = res.cookies
t.equal(cookies.length, 2)
t.equal(cookies[0].name, 'foo')
t.equal(cookies[0].value, 'foo')
t.equal(cookies[0].path, '/')
t.equal(cookies[1].name, 'foo')
t.equal(cookies[1].value, 'foos')
t.equal(cookies[1].path, '/')
})
})
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