Skip to content

Chunked v3 session cookies lost after v4 upgrade #2066

Open
@cbovis

Description

@cbovis

Checklist

Description

I've been investigating whether existing sessions will be maintained when upgrading to v4 and was pleased to see the team has planned for the scenario. I've found an edge case though which breaks.

Sometimes our v3 integration will generate chunked session cookies. These have the format of appSession.{index} (e.g. appSession.0 and appSession.1). If the session is using chunked cookies then it gets lost after upgrading to v4. If the cookie isn't chunked and is simply named appSession then it migrates correctly.

I dug into the source code and believe I found the issue. In the stateless session store the legacy cookie is fetched via the getChunkedCookie method:

cookies.getChunkedCookie(LEGACY_COOKIE_NAME, reqCookies);

This method checks for cookies in the format __{cookieName}__{index}. Therefore __appSession__0 etc. doesn't yield any matching cookies. The issue here being that the format has changed between v3 and v4.

A potential fix that comes to mind is extending the getChunkedCookie method to receive a legacyFormat boolean argument which can be used internally to instead look for {cookieName}.{index}.

Reproduction

See description

Additional context

No response

nextjs-auth0 version

4.4.2

Next.js version

14.2.26

Node.js version

22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions