1

I'm seeing some strange cookie behaviour on a Gatsby site hosted on Netlify. In my Netlify Function, I sometimes receive cookies like this:

"headers": {
  "cookie": "__stripe_mid=someId, nf_jwt=someId, __stripe_sid=someId",
   /* ... */
},

Instead of like this (with semi-colon delimiters instead of commas):

"headers": {
  "cookie": "__stripe_mid=someId; nf_jwt=someId; __stripe_sid=someId",
   /* ... */
},

When it is sent as in the first example, it is causing my cookie.parse() code to occasionally give me an object with a single key, and the value a concatenation of the rest of the cookies. Like this:

{
  __stripe_mid: "someId, nf_jwt=someId, __stripe_sid=someId"
}

I can confirm that in Chrome DevTools, the cookies are being sent with semi-colon separators (as they should). But when they end up being passed to the Netlify Function, they've changed to commas. Example Netlify Function:

export async function handler (event) {
  console.log(event.headers.cookies) // Comma separated cookies
}

I cannot seem to work out what causes this. Does anybody have any idea why I would receive Cookies from a browser in a different format at different times?

shennan
  • 10,798
  • 5
  • 44
  • 79

1 Answers1

0

This was an error on their end and should be fixed now:

https://github.com/netlify/netlify-plugin-nextjs/issues/255

https://answers.netlify.com/t/bug-netlify-functions-event-headers-cookie-sometimes-suddenly-used-comma-instead-of-semicolon/36793/12

gtsiou
  • 46
  • 2
  • Interesting. This really threw me at the time. To solve the issue I ended up creating custom parsing code, which I presume can now be reverted. Very annoying! – shennan May 26 '21 at 16:26