Repository navigation
Conversation
When rolling is enabled, the session identifier cookie is re-sent on every response, but its attributes were inflated from the stored session data, so changes to the cookie option (such as sameSite, secure, or path) never applied to existing sessions. Build the re-sent cookie from the current resolved cookie options when a session is inflated with rolling enabled, while keeping the session's own expires and originalMaxAge.
yxshee
reviewed
Nov 4, 2026
yxshee
left a comment
There was a problem hiding this comment.
Checked on f98bf9c (on top of master):
npm test: 175 passing,npm run lint: clean- With
index.jsreverted to master, "should send updated cookie attributes on existing session" fails, as expected. "should honor session cookie changes" passes on both. It's a guard that a handler can still override the refreshed cookie, and it's useful to keep.
I agree with keeping expires/originalMaxAge: dropping a per-session "remember me" maxAge on the next request would be the bigger surprise.
Heads-up for whoever merges: this and my #1151 both restructure the store.generate body (this PR pulls the cookie into createCookie, #1151 moves the generator to generateSession). The conflict is textual only. I'll rebase #1151 onto this one if it lands first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
rolling: true, the re-sent session cookie now takes its attributes from the currentcookieoption instead of the cookie data stored with the session. Before, a change tosameSite,secure,httpOnly,pathordomainonly reached sessions created after the change.Addresses #1077.
In
index.js, the cookie construction instore.generatemoves into acreateCookie(req)function, andinflatecalls it whenrollingis enabled. Socookieas a function andsecure/sameSite: 'auto'resolve the same way as for a new session. The refresh happens before the route handler runs, so a handler can still changereq.session.cookiein the same request.Judgement call:
maxAgeis not refreshedThe session's own
expiresandoriginalMaxAgeare kept, so a per-sessionreq.session.cookie.maxAge(for example a "remember me" duration) is not changed. A storedoriginalMaxAgecannot be told apart from such an override. As a result, a change tocookie.maxAgein the options still applies only to new sessions, and themaxAgepart of the issue is not covered.The other attributes follow the current options. A per-visitor attribute that a handler set in an earlier request (for example
req.session.cookie.domain) is reset to the configured value on the next request.Alternatives, if you prefer one:
maxAgealso follows config and per-sessionmaxAgeoverrides are dropped. This means deleting the lines ininflatethat restoreexpiresandoriginalMaxAge.Not changed: the non-rolling path that re-sends a persistent cookie after a session change, and
req.session.reload(), which still restores the stored attributes.Tests
Two cases under "rolling option" in
test/session.js: an existing session gets the newSameSiteand keeps its original expiry, and a handler'sreq.session.cookie.sameSitechange still applies. The first fails without the change and passes with it.