GithubHelp home page GithubHelp logo

Comments (6)

esoylugoto avatar esoylugoto commented on June 4, 2024

@HoneyMeat express is using cookie version 0.5.0 internally, which discards the partitioned option. You can manually build your cookie and set your response header. For that you have to use cookie 0.6.0 as a dependency:

import { serialize } from 'cookie';
const cookie = serialize('myCookieName', 'mySessionId', {
  httpOnly: true,
  sameSite: 'none',
  secure: true,
  partitioned: true,
  path: '/',
});
return res.setHeader('Set-Cookie', cookie).status(200).send();

from session.

JoseAlbertoVazq avatar JoseAlbertoVazq commented on June 4, 2024

Same problem over here. Updated express package to 4.19.0 and express-session to 1.18.0, both have 0.6.0 version of the cookie package. The cookie is being set with no partition applied.

app.use(session({
        resave: false,
        saveUninitialized: false,
        secret: mySecret,
        cookie: {
          domain: myDomain
          path: '/',
          sameSite: !_.isNil(sameSite) ? sameSite : 'lax',
          secure: !!(!_.isNil(secure) && secure.toLowerCase() === 'true'),
          partitioned: true, // <-- HERE is where the attribute has to be set according to Express Session docs
        },
        store: storeObject,
      }));

Any tips on this??

from session.

esoylugoto avatar esoylugoto commented on June 4, 2024

@JoseAlbertoVazq if you check with developer tools, what do you see on your response headers, the response which sets the cookie?
If it is malformed browser might silently discard it.

from session.

esoylugoto avatar esoylugoto commented on June 4, 2024

@JoseAlbertoVazq If you are checking the dev tools on a different domain than which the cookie is set, your cookie connect.sid is expected to not show up. Are you sure you are checking it from the domain it is set?

Partition option makes the cookie work only from the domain it is set.

from session.

JoseAlbertoVazq avatar JoseAlbertoVazq commented on June 4, 2024

@JoseAlbertoVazq If you are checking the dev tools on a different domain than which the cookie is set, your cookie connect.sid is expected to not show up. Are you sure you are checking it from the domain it is set?

Partition option makes the cookie work only from the domain it is set.

The cookie is always shown but when I set the Partitioned attribute, and it always was like that, I'm running it on the same domain (on local, and on staging, but those are two different tests local --> local and staging --> staging)

from session.

JoseAlbertoVazq avatar JoseAlbertoVazq commented on June 4, 2024

Okay so I found the solution for my case. I am also using cookie-parser and its last release if from three years ago, so the cookie lib in its package.json was the 0.4.1 version.

Make sure to add this to your package.json

npm:

  "overrides": {
    "cookie": "0.6.0",
    "cookie-signature": "1.2.1"
  }

yarn:

  "resolutions": {
    "**/cookie": "0.6.0",
    "**/cookie-signature": "1.2.1"
  }

Also, ensure that the secure attribute in the CookieOptions object is set to true and is not being overridden by anything else in any other place in your code.

Now it's working for me !!

from session.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.