Search code examples
node.jshttpcookiesnetlifynetlify-function

Strange cookie behaviour in Netlify Functions


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?


Solution

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

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