expressjs / expressjs/session

Add option to preserve session data when calling `regenerate()`

Open
#1,036 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
6.4k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Currently, `req.session.regenerate()` creates a new session and destroys the previous one, including its data.

In some use cases, developers may want to change only the session ID for security reasons (such as preventing session fixation) but keep the existing session data.

I would like to propose adding an option to the regenerate() method to preserve the current session data.

``` js
req.session.regenerate({ preserveData: true });
```

If preserveData: true, the session data from the old session would be copied to the new session.

If omitted or false, the behavior remains unchanged.

This would allow more flexible session management without breaking existing functionality.

If the maintainers agree with this idea, I am happy to work on a PR.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.