Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

res.cookie option with sameSite 'none' throws TypeError: option sameSite is invalid at Object.serialize #653

Open
matjazonline opened this issue Apr 2, 2020 · 7 comments

Comments

@matjazonline
Copy link

matjazonline commented Apr 2, 2020

Related issues

I found the issue for Express framework
expressjs/express#3958
and looks it was fixed there.

[REQUIRED] Version info

node: v10.16.3

firebase-tools:

8.0.0.

[REQUIRED] Test case

export const sameSiteCookie = functions.https.onRequest((req, res) => {
cors(req, res, () => {
const expiresIn = 60 * 60 * 24 * 5 * 1000;
const options: any = {
maxAge: expiresIn,
httpOnly: true,
secure: true,
sameSite: 'none',
};
res.cookie('testCKI', 'value123', options);
res.end(JSON.stringify({
data: {
status: 'success'
}
}));
});
});

[REQUIRED] Steps to reproduce

calling the cloud function above

[REQUIRED] Expected behavior

set cookie value to SameSite=Never

[REQUIRED] Actual behavior

TypeError: option sameSite is invalid at Object.serialize (/worker/node_modules/cookie/index.js:174:15) at ServerResponse.res.cookie (/worker/node_modules/express/lib/response.js:853:36) at cors (/srv/lib/index.js:106:13) at cors (/srv/node_modules/cors/lib/index.js:188:7) at /srv/node_modules/cors/lib/index.js:224:17 at originCallback (/srv/node_modules/cors/lib/index.js:214:15) at /srv/node_modules/cors/lib/index.js:219:13 at optionsCallback (/srv/node_modules/cors/lib/index.js:199:9) at corsMiddleware (/srv/node_modules/cors/lib/index.js:204:7) at exports.sessionLogin.functions.https.onRequest (/srv/lib/index.js:98:5)

Were you able to successfully deploy your functions?

no error messages seen

@joehan joehan self-assigned this Apr 6, 2020
@joehan
Copy link
Contributor

joehan commented Apr 8, 2020

Thanks for reporting this @matjazonline. Could you also share which version of firebase-functions you are using?

This does look like a similar issue to the one that you found from Express - however, its not immediately clear to me which package is causing it here. According to that issue, this was fixed in [email protected], which firebase-functions has been using for 10 months now: https://github.com/firebase/firebase-functions/blame/master/package.json#L43

I'm going to do some further testing to see if I can repro this and figure out which package we need to update to stop this error.

@matjazonline
Copy link
Author

matjazonline commented Apr 9, 2020 via email

@swftvsn
Copy link

swftvsn commented Apr 30, 2020

@joehan we also hit this:

TypeError: option sameSite is invalid
at Object.serialize (/worker/node_modules/cookie/index.js:174:15)
at ServerResponse.res.cookie (/worker/node_modules/express/lib/response.js:853:36)

We have "cookie": "^0.4.1" in package.json and our package-lock.json has

"cookie": {
  "version": "0.4.1",
  "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
  "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA=="
},

The stack trace how ever matches the lines in older cookie lib version, so for some reason the versions are not honored when deployed to CF?

Running with "firebase-functions": "^3.6.1", and latest cli to deploy. 8 as the node engine.

@swftvsn
Copy link

swftvsn commented Apr 30, 2020

You can check here: https://github.com/jshttp/cookie/pull/89/files that the lines match cookie lib < 1.4.0 being used in CF.

@swftvsn
Copy link

swftvsn commented May 1, 2020

@matjazonline for the time being, you can write raw cookies (multiple) like this:

res.setHeader('set-cookie', [
 'firstCookie=' + valueForFirst + '; Max-Age=' + expiresSeconds + '; Path=/some/path/; Expires=' + expiresDate.toUTCString() + '; Secure; SameSite=None; Domain=my-domain.com; HttpOnly', 
 'secondCookie=' + valueForSecond + '; Max-Age=' + expiresSeconds + '; Path=/other/; Expires=' + expiresDate.toUTCString() + '; SameSite=Strict;'
])

etc.

@shivanshu41
Copy link

Did anyone fix this issue ?

@rhodgkins
Copy link
Contributor

The functions-framework, which I believe the Firebase functions are run on, uses express: 4.16.4 - that's no the issue is it?

Had similar problems with x-powered-by header and it turns out the functions use a child app of the functions framework app, or something like that...!

@joehan joehan removed their assignment Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants