question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling setCookie, deleteCookie multiple times in the same request adds multiple set-cookie headers.

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.5.3

Plugin version

8.1.0

Node.js version

16.14.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

11

Description

I had tried to clear a cookie set by a different piece of code on the same request. However, it looks like when I call setCookie and deleteCookie in alternates for the same cookie name, there are multiple set-cookie headers in the response.

Steps to Reproduce

Run the following on onSend hook:

  reply.setCookie('session', sessionCookie, cookieOptsCopy);
  reply.clearCookie('session', cookieOptsCopy);
  reply.setCookie('session', sessionCookie, cookieOptsCopy);
  reply.clearCookie('session', cookieOptsCopy);
  reply.setCookie('session', sessionCookie, cookieOptsCopy);
  reply.clearCookie('session', cookieOptsCopy);
  reply.setCookie('session', sessionCookie, cookieOptsCopy);

results in something like this:

image

Expected Behavior

Setting cookie with the same name should modify the existing cookie.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mcollinacommented, Oct 17, 2022

Unfortunately I will have little time to look into this for a while.

0reactions
mcollinacommented, Oct 17, 2022

I mean, nested for loops are definitely not the way to go. I would hardly use or even support the pattern described at the top.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · fastify/fastify-cookie - GitHub
Calling setCookie, deleteCookie multiple times in the same request adds multiple set-cookie headers. bug good first issue ; Add support for encrypting cookies ......
Read more >
Multiple Set-cookie headers in HTTP - Stack Overflow
This usually ends up happening when you call session_start() and then session_regenerate_id() on the same page. Each will set its own header. All...
Read more >
setcookie - Manual - PHP
One way to set this is by adding the number of seconds before the cookie should expire ... Multiple calls to setcookie() are...
Read more >
Cookies, document.cookie - The Modern JavaScript Tutorial
Upon sign in, the server uses the Set-Cookie HTTP-header in the response to set a ... Next time when the request is sent...
Read more >
Set-Cookie - HTTP - MDN Web Docs
To send multiple cookies, multiple Set-Cookie headers should be sent ... cookie only for same-site requests, that is, requests originating ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found