-
Notifications
You must be signed in to change notification settings - Fork 347
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
[Feature request] Add a CookieStore
option to Request
& Response
#1384
Comments
CookieStore
option to Request
CookieStore
option to Request
& Response
This feature request could be generalized somewhat. The fundamental problem is that server-side HTTP clients need a way to get cookies from request A and send those cookies back to the server in request B. Adding a The rest of this comment provides more explanation and justification for this feature requests. Server-Side Cookies Use CasesCopying from nodejs/node#41749 (comment):
Here's another discussion of use cases from nodejs/node#41749 (comment):
WorkaroundsBelow is what server apps must do to enable cookie propagation between requests. There may be more steps, but the two below are the ones I know about. Note that redirect requests require different handling to support cases where the cookie is set by a redirect response.
JustificationBoth (1) and (2) above are non-trivially complex. Both cookies and redirection are fraught with potential security issues and the manual steps described above are quite un-ergonomic. So, realistically, I'd expect that most cookie-needing Node apps will rely on an (as yet unwritten?) library that wraps More DiscussionI don't know enough about the security implications to have an opinion about whether cookie control as recommended in the OP is needed for |
couldn't have said it any better. |
Hey there! 👋 fetch-cookie maintainer here :) We do support redirects (although I'm currently working on improving that part as it's not perfectly compliant), but only for the node-fetch specific wrapper I realized recently that That being said, fetch-cookie cannot currently work with undici because the If the Node.js implementation ever allows userland code to read the That being said I do support the feature request in the original message. I wrote fetch-cookie 7 years ago as what I thought would be a "temporary workaround" and now hundreds of people depend on it. Anything that makes it obsolete would make me more than happy, and that
The main issue I have with a One thing that I've been dreaming about recently that would help with that is a way to properly wrap |
@valeriangalliat, this statement seems to contradict what @devsnek says in nodejs/node#41749 (comment):
I confirmed on Node 17.5 and I am able to read the (await fetch('https://wikipedia.com/')).headers.get('set-cookie')
// => 'WMF-Last-Access=18-Feb-2022;Path=/;HttpOnly;secure;Expires=Tue, 22 Mar 2022 00:00:00 GMT, WMF-Last-Access-Global=18-Feb-2022;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Tue, 22 Mar 2022 00:00:00 GMT, GeoIP=(REDACTED!); Path=/; secure; Domain=.wikipedia.org'
I strongly agree with this point. |
This is true, though the fact that multiple Set-Cookie headers get joined together into a single string makes it unusable. The joined string cannot be unambiguously parsed. |
I was looking into how some form of how a cookie jar could fit into NodeJS and Deno.
...it totally lacks any form of cookie handling. A default cookie jar would not be so perfect for backend either.
There exist some grate libraries like tough-cookie but isn't so web-ish when it comes to something as spec'ed as the CookieStore
I was thinking that it would be cool if you could construct CookieStore with
new CookieStore()
and being able to pass this to fetch/Request as an option. and so that we can agree upon a unified way of dealing with cookie jars in both Deno and NodeJS. while sending, reciving and encoding/decoding cookie stringsThis would take care of setting request
cookie
s that exist in the store and parsingset-cookies
like during redirects as well. + it would also simplify getting/setting cookies, and the Header class wouldn't need any special handling like #1346, #973 (we could forbid theset-cookie
header like the browser dose it and also remove anycookie
header from the response.headers as well)I was maybe thinking this could be useful for the web as well where you have the desire to handle multiple sessions/accounts simultaneously and dealing with cookies yourself in different tabs. This could also be a way of telling a single page application that cookies should never store a cookie on the clients machine (whetter it be session or persistent) maybe you could store a
CookieStore
in theIndexedDB
? otherwise it would totally be discarded when you leave the page. This could be useful for banks so that you are logged out as soon as you close/refresh the page, and having to login again.if you could pass a own instances of CookieStore to the request then it would also mean that any sub-sequent request to eg
/static/css/main.css
wouldn't send any cookie either via a<link>
tagThe text was updated successfully, but these errors were encountered: