Skip to content

Duplicate session cookie when changing configuration #1010

@AntoineAwaida

Description

@AntoineAwaida

I noticed that changing the configuration in production/deployed mode of express-session cookies can lead to duplicate connect.sid cookie stored in the browser with the old and the new configuration - which can be very problematic to retrieve the right session afterwards.

New configuration :

    store: redisStore,
    secret: envConfig.OTHER_TOKEN_SECRET,
    resave: false,
    saveUninitialized: true,
    cookie: {
      secure: envConfig.ENV === 'local' ? false : true,
      httpOnly: true,
      sameSite: envConfig.ENV === 'local' ? 'lax' : 'none',
      maxAge: 60 * 60 * 1 * 1000, // 1 hour
      partitioned: envConfig.ENV === 'local' ? false : true,
    },

Old configuration :

    store: redisStore,
    secret: envConfig.OTHER_TOKEN_SECRET,
    resave: false,
    saveUninitialized: true,
    cookie: {
      secure: true, 
      httpOnly: true,
      sameSite: envConfig.ENV === 'local' ? 'lax' : 'none',
    },

WhatsApp Image 2024-12-27 at 10 40 40

To fix this, I had no choice but to change the name of the session cookie stored in the browser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions