Is there an existing issue for this?
Current Behavior
The keyring session store keys entries by host only. normalizeHost in cli/sessionstore/sessionstore.go returns strings.ToLower(u.Host), so http://coder.example.com and https://coder.example.com map to the same entry. Every command that runs with --url http://coder.example.com and --use-keyring=true therefore uses the token that was stored for the https deployment:
coder login token --url http://coder.example.com prints the https token.
coder logout --url http://coder.example.com sends that token to http://coder.example.com in client.Logout() and then deletes the shared entry, signing the https session out.
- Any other command, such as
coder ssh, sends the https token in cleartext to the http URL.
coder login http://coder.example.com --use-token-as-session overwrites the https entry with the http token.
File mode already guards against this. coder login token compares the stored URL with --url and refuses with file session token storage only supports one server at a time when they differ. The keyring path has no such check.
The main way to hit this is a mistyped or misconfigured URL: a user who is signed in to https://coder.example.com in the terminal and points a client at http://coder.example.com leaks the https token over plaintext. The VS Code extension defaults coder.useKeyring to true in coder/vscode-coder#1107 and shares the CLI's store, so the same host-keyed entry is used by both.
Relevant Log Output
$ coder login https://coder.example.com --use-keyring=true
# ...signed in...
$ coder login token --url http://coder.example.com --use-keyring=true
<prints the https session token>
Expected Behavior
Keyring entries are scoped to the full origin (scheme, host, and port), or the keyring read compares the stored URL with --url the way file mode does and refuses on a mismatch. Either way, coder login token --url http://coder.example.com fails with a clear error instead of printing a token for a different scheme.
Steps to Reproduce
- On macOS or Windows, run
coder login https://coder.example.com --use-keyring=true and sign in.
- Run
coder login token --url http://coder.example.com --use-keyring=true.
- The
https session token is printed. Running coder logout --url http://coder.example.com --use-keyring=true sends it to the http URL and removes the https session.
Environment
- Host OS: macOS or Windows (any platform with keyring support)
- Coder Version: main at 9548f23 (after 2.32.0)
Additional Context
Related to #29105, which also touches how clients share the CLI's keyring store.
Is there an existing issue for this?
Current Behavior
The keyring session store keys entries by host only.
normalizeHostincli/sessionstore/sessionstore.goreturnsstrings.ToLower(u.Host), sohttp://coder.example.comandhttps://coder.example.commap to the same entry. Every command that runs with--url http://coder.example.comand--use-keyring=truetherefore uses the token that was stored for thehttpsdeployment:coder login token --url http://coder.example.comprints thehttpstoken.coder logout --url http://coder.example.comsends that token tohttp://coder.example.cominclient.Logout()and then deletes the shared entry, signing thehttpssession out.coder ssh, sends thehttpstoken in cleartext to thehttpURL.coder login http://coder.example.com --use-token-as-sessionoverwrites thehttpsentry with thehttptoken.File mode already guards against this.
coder login tokencompares the stored URL with--urland refuses withfile session token storage only supports one server at a timewhen they differ. The keyring path has no such check.The main way to hit this is a mistyped or misconfigured URL: a user who is signed in to
https://coder.example.comin the terminal and points a client athttp://coder.example.comleaks thehttpstoken over plaintext. The VS Code extension defaultscoder.useKeyringtotruein coder/vscode-coder#1107 and shares the CLI's store, so the same host-keyed entry is used by both.Relevant Log Output
Expected Behavior
Keyring entries are scoped to the full origin (scheme, host, and port), or the keyring read compares the stored URL with
--urlthe way file mode does and refuses on a mismatch. Either way,coder login token --url http://coder.example.comfails with a clear error instead of printing a token for a different scheme.Steps to Reproduce
coder login https://coder.example.com --use-keyring=trueand sign in.coder login token --url http://coder.example.com --use-keyring=true.httpssession token is printed. Runningcoder logout --url http://coder.example.com --use-keyring=truesends it to thehttpURL and removes thehttpssession.Environment
Additional Context
Related to #29105, which also touches how clients share the CLI's keyring store.