Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cookie Expiration Age Fix#7327

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jonathandunne wants to merge2 commits intocoder:main
base:main
Choose a base branch
Loading
fromjonathandunne:main

Conversation

jonathandunne
Copy link

@jonathandunnejonathandunne commentedApr 26, 2025
edited by code-asher
Loading

Fixes#7301
Fixes#5437

@jonathandunnejonathandunne requested a review froma team as acode ownerApril 26, 2025 03:23
Copy link
Member

@code-ashercode-asher left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for the contribution! Looks good to me so far. We will have to add it tosrc/node/cli.ts as well.

The. syntax is intriguing, but I want to say we call itauth-cookie-max-age for now.

@@ -326,6 +335,7 @@ export const getCookieOptions = (req: express.Request): express.CookieOptions =>
domain: getCookieDomain(url.host, req.args["proxy-domain"]),
path: normalize(url.pathname) || "/",
sameSite: "lax",
maxAge: getConfigCookieMaxAgeAsMilliseconds(req) || 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh wait is0 the right default? This will delete the cookie instantly, I think? We may want-1.

Copy link
Member

@code-ashercode-asherApr 28, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hmm actually zero or negative immediately expires the cookie it seems.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#max-agenumber
https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.2

Should it just be undefined? Also we may want?? instead of|| in case someone does explicitly set it to zero for some reason.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd read it in the Express JS docs setting it to 0 makes it session
https://expressjs.com/en/api.html#res.cookie
image

They gave this explanation to theexpires parameter, but also saidmaxAge is a "Convenient option for setting the expiry time relative to the current time in milliseconds". They didn't specify what to put here to make it session, nor what the default is.

Copy link
Member

@code-ashercode-asherApr 30, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah I also thought maybe it was an Express thing, but when I checked the source it seems to just immediately expire.

IfmaxAge is zero, it passesexpires set to now andmaxAge set to zero intocookie.serialize():

https://github.com/expressjs/express/blob/f9954dd317a1b534e62a5ae3aa7f52f3582b8881/lib/response.js#L764-L771

cookie.serialize() simply addsMax-Age=0 andExpires=<the now date> to the cookie:

https://github.com/jshttp/cookie/blob/2a1a4d8b2679b208f354e848e711dc8471fb83af/src/index.ts#L268-L274

Now, ifexpires is zero (although this is actually a type error), and there is no max age it does indeed skip settingExpires in that case, which would result in a session cookie. The difference is they doif (options.maxAge !== undefined) versusif (options.expires), so zero is not ignored in the max age case.

Copy link

@nb-programmernb-programmerMay 6, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah I also thought maybe it was an Express thing, but when I checked the source it seems to just immediately expire.

IfmaxAge is zero, it passesexpires set to now andmaxAge set to zero intocookie.serialize():

https://github.com/expressjs/express/blob/f9954dd317a1b534e62a5ae3aa7f52f3582b8881/lib/response.js#L764-L771

cookie.serialize() simply addsMax-Age=0 andExpires=<the now date> to the cookie:

https://github.com/jshttp/cookie/blob/2a1a4d8b2679b208f354e848e711dc8471fb83af/src/index.ts#L268-L274

Now, ifexpires is zero (although this is actually a type error), and there is no max age it does indeed skip settingExpires in that case, which would result in a session cookie. The difference is they doif (options.maxAge !== undefined) versusif (options.expires), so zero is not ignored in the max age case.

Hmm, what would be a good way to ensure it is properly a session cookie?Sendingnull seems illogical, but would work, or we can just skip the field if there is no config for it.

Edit:null won't work since theserialize method just checks for undefined, and raises an error if its not an integer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah I think something likemaxAge: getConfigCookieMaxAgeAsMilliseconds(req) ?? undefined would do the trick.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah waitgetConfigCookieMaxAgeAsMilliseconds always returns a number, so we would have to do it in there. We could returnnumber | undefined.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@code-ashercode-ashercode-asher requested changes

@nb-programmernb-programmernb-programmer left review comments

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Allow configuring login cookie with an expiry duration [Feat]: Remember password across browser session restarts
3 participants
@jonathandunne@code-asher@nb-programmer

[8]ページ先頭

©2009-2025 Movatter.jp