Skip to content

Add --cookie-max-age to keep the login cookie across browser sessions - #8147

Open
harshbhx wants to merge 2 commits into
coder:mainfrom
harshbhx:fix/7301-cookie-max-age
Open

harshbhx wants to merge 2 commits into
coder:mainfrom
harshbhx:fix/7301-cookie-max-age

Conversation

@harshbhx

Copy link
Copy Markdown
Contributor

Fixes #7301

Summary

Adds an opt-in --cookie-max-age <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. When set, the cookie set in src/node/routes/login.ts gets maxAge = 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 in getCookieOptions, because logout reuses those options to clear the cookie.

Changes

File Change
src/node/cli.ts new cookie-max-age option, description, validation
src/node/routes/login.ts apply maxAge when setting the login cookie
CHANGELOG.md Unreleased entry
test/unit/node/cli.test.ts parsing and validation
test/unit/node/routes/login.test.ts login sets Max-Age=3600 with the flag, no Max-Age/Expires without it

Before / After

Before: Set-Cookie: code-server-session=...; Path=/; HttpOnly; SameSite=Lax
After (--cookie-max-age=3600): ...; Max-Age=3600; Expires=...

How to test

  1. PASSWORD=x code-server --cookie-max-age 3600, log in, check the cookie expiry in devtools; restart the browser and confirm you are still logged in.
  2. Without the flag the cookie is still a session cookie.

Testing done

  • New unit tests; the two login tests and the cli test fail without the change, pass with it (96/96 in cli + login suites)
  • Prettier check on the touched files
  • Full suite and e2e only via fork CI; not tried in a real browser

Notes for reviewers

Documented in the CHANGELOG and --help. No env var yet; happy to add CODE_SERVER_COOKIE_MAX_AGE if you want one.

@harshbhx
harshbhx requested a review from a team as a code owner November 19, 2026 19:46

This branch has not been deployed

No deployments
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.

Allow configuring login cookie with an expiry duration

1 participant