Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add session.regenerate() #385

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sititou70
Copy link

To prevent session fixation attacks, it would be useful to have an API to regenerate session ID.

session.regenerate() API replaces the current session ID with a new generated one. Return Promise.

await session.regenerate();
await session.commit(); // if `autoCommit` is set to `false`.

This is similar to express-session's Session.regenerate(callback) and PHP's session_regenerate_id.

Copy link

changeset-bot bot commented May 22, 2024

⚠️ No Changeset found

Latest commit: cd08f40

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codecov bot commented May 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5615e7d) to head (cd08f40).

Additional details and impacted files
@@             Coverage Diff             @@
##           master      #385      +/-   ##
===========================================
+ Coverage   99.17%   100.00%   +0.82%     
===========================================
  Files           6         5       -1     
  Lines         121       126       +5     
  Branches       37        37              
===========================================
+ Hits          120       126       +6     
+ Misses          1         0       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MaxMEllon
Copy link

I needed regenerate function in express-session, so I used the forked version.
I hope this feature will be introduced for compatibility express-session and session fixation attacks.

@sititou70
Copy link
Author

I refactored the implementation based on @MaxMEllon 's code. Also, type definitions were missing and have been added.

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants