3

On a SvelteKit endpoint, I am setting a cookie with an expiry using the cookie package on NPM. The code is kind of like the following:

export const post = async () => {
    const flavor = cookie.serialize('flavor', 'chocolate chip', {
        expires: new Date(Date.now() + 1000 * 60)
    })
    const headers = new Headers()
    headers.append('Set-Cookie', flavor)

    return new Response(null, {
        headers,
    })
}

On local environment, everything's dandy (: But in production, the expiry gets split into a different set-cookie header, pictured below:

the expiry field is split, with the remainder on a new set-cookie header

I am using the Netlify Adapter, and I've found that it seems to split on commas (relevant code below), but this is problematic as the specification for date demands a comma separating the day of the week and everything else.

headers.forEach((value, key) => {
    if (key === 'set-cookie') {
        m[key] = value.split(', ');
    } else {
        h[key] = value;
    }
});

Am I missing something with setting cookies, or is this perhaps an unintended side-effect of the adapter?

Auroratide
  • 2,299
  • 10
  • 15
  • 1
    This sounds like a bug - I'd open an issue on the SvelteKit repo. – Geoff Rich Feb 23 '22 at 16:27
  • This is probably because the implementation follows RFC 2109, which allows multiple cookies passed into the `Set-Cookie` header using commas as separators, see https://stackoverflow.com/questions/2880047/is-it-possible-to-set-more-than-one-cookie-with-a-single-set-cookie – Thomas Hennes Feb 23 '22 at 16:33
  • 1
    But @GeoffRich is right, if this impedes with setting the expiry dates on cookies (which also expect a comma, see https://stackoverflow.com/questions/11136372/which-date-formats-can-i-use-when-specifying-the-expiry-date-when-setting-a-cook), then it is likely a bug. – Thomas Hennes Feb 23 '22 at 16:34
  • Thanks, I can open up an issue! – Auroratide Feb 23 '22 at 16:42

1 Answers1

0

This was a bug that was addressed in this issue.

Auroratide
  • 2,299
  • 10
  • 15