User agent based `sameSite` cookie value
See original GitHub issueStarting with July, Chrome in specific cases requires the sameSite
property of cookies to be set to None
. However some browsers like specific versions of Safari don’t support that value and automatically switch to Strict
when None
is sent. User agent sniffing is therefore necessary for deciding which value to send, which however isn’t possible with the current implementation of express-session.
Since I wouldn’t include the UA sniffing part into this library (neither did Microsoft with ASP.NET Core), would it be OK to add the functionality for sameSite
to also accept a function (req) => string | boolean
to set the value based on the incoming request?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
SameSite Cookie Attribute Changes - Auth0
Describes how browser changes, such as the SameSite cookie attribute, affects your web applications that embed content from third-party domains.
Read more >User-Agent Sniffing Only Way to Deal With ... - CatchJS
The 2019 SameSite standard mandates that cookies should not be sent in POST requests from other sites, unless they are marked with SameSite=None ......
Read more >SameSite cookies - HTTP - MDN Web Docs
This is the default cookie value if SameSite has not been explicitly specified in recent browser versions (see the "SameSite: Defaults to ...
Read more >Work with SameSite cookies in ASP.NET Core | Microsoft Learn
Developers are able to programmatically control the value of the sameSite attribute using the HttpCookie.SameSite property. Setting the SameSite ...
Read more >SameSite cookie recipes - web.dev
With the introduction of the new SameSite=None attribute value, sites can now explicitly mark their cookies for cross-site usage.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The issue with this proposal, of course, is that you will need to go though all the modules on npm getting them to do this. I would suggest (if not already on npm) to create a module that will alter any existing set-cookie headers on the response just before they are sent, as a hook. When it sniffs the user agent is Safari, it would remove sameSite=None from the header. This solution would not require every npm module to add sameSite as a function or similar and require users to then add this sniffing logic there for everything that needs it 👍
I just thought because basically everyone using
sameSite: 'none'
will run into that issue and I didn’t think about changing the set-cookie header by using a middleware. Anyway, thank you again for your help!