Repository navigation
Add --cookie-max-age to keep the login cookie across browser sessions - #8147
Conversation
4e26a60 to
7b570f7
Compare
|
Hi @code-asher, friendly ping when you have time. Checks are green, and I'm happy to rework the approach if you'd rather handle the cookie lifetime differently. |
code-asher
left a comment
There was a problem hiding this comment.
This looks great! I think we just add the unit to the flag name and we are golden.
| res.cookie(req.cookieSessionName, hashedPassword, getCookieOptions(req)) | ||
| // The max age is only set here, not in getCookieOptions, because those | ||
| // options are also used to clear the cookie on logout. | ||
| const maxAge = req.args["cookie-max-age"] |
There was a problem hiding this comment.
Oh just had a thought, maybe we call this cookie-max-age-seconds to match other flags like idle-timeout-seconds. Just to make it really clear what unit this flag represents.
(And also because in the future I think it would be cool to support strings like 10m for 10 minutes with all our time-based flags, and we would want to leave the unit-less version of the flags available for that.)
|
Done in 82a744c: renamed to |
Fixes #7301
Summary
Adds an opt-in
--cookie-max-age-seconds <seconds>flag so the login cookie can outlive the browser session.Problem
The login cookie is set without
Max-Age/Expires, so it is a session cookie and users must log in again every time the browser is closed (#7301). There is no setting to change this.Solution
A new numeric flag
cookie-max-age-seconds. When set, the cookie set insrc/node/routes/login.tsgetsmaxAge = seconds * 1000. Without the flag behaviour is unchanged. Non-positive or non-numeric values throw at startup, like--idle-timeout-seconds. The max age is added at login only, not ingetCookieOptions, because logout reuses those options to clear the cookie.Changes
src/node/cli.tscookie-max-age-secondsoption, description, validationsrc/node/routes/login.tsmaxAgewhen setting the login cookieCHANGELOG.mdtest/unit/node/cli.test.tstest/unit/node/routes/login.test.tsMax-Age=3600with the flag, noMax-Age/Expireswithout itBefore / After
Before:
Set-Cookie: code-server-session=...; Path=/; HttpOnly; SameSite=LaxAfter (
--cookie-max-age-seconds=3600):...; Max-Age=3600; Expires=...How to test
PASSWORD=x code-server --cookie-max-age-seconds 3600, log in, check the cookie expiry in devtools; restart the browser and confirm you are still logged in.Testing done
Notes for reviewers
Documented in the CHANGELOG and
--help. No env var yet; happy to addCODE_SERVER_COOKIE_MAX_AGEif you want one.