You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-ups from the review of #4833 (CLI session refresh-credential rotation). None blocks that PR.
Required behavior
Recovery after a lost store. When writing the replacement credential fails, or the process exits before the rename, the session file holds the credential that the cloud replaced. After the grace period the next command is refused. Define the recovery path with the cloud's side of the protocol, for example a re-issue of the current replacement to a caller that proves the replaced credential within the grace period.
Refresh response origin. The refresh request follows redirects and does not check the final response origin, so a redirect to another origin could supply the replacement credential. Reject a response whose origin differs from the stored cloud origin.
Failed-write test under root. The test forces the write to fail with chmod 0500 on the auth directory. That does not block writes when the suite runs as root. Force the failure in a way that does not depend on the user.
Completion conditions
A test covers a store that fails after the cloud rotated, and the next command either recovers or fails with a typed reason and the login hint.
A test covers a refresh response from a redirected origin, and no credential from it is stored.
The failed-write test fails when the fix is removed, also as root.
The issue is a follow-up implementation task from #4833, specifying new required behavior: recovery after a lost credential store, rejecting redirected refresh responses from a different origin, and making the failed-write test work as root.
A process that reads the credential, pauses past the grace window, then refreshes, sends a stale credential; a cloud that revokes on post-grace reuse then invalidates the replacement another process saved. Holding the session lock across read, request and store would close it.
A 200 refresh response that reports revoked and also carries tokens is accepted, because the access-token branch returns before the revocation check.
The request always sends acceptsRotatedRefreshCredential; a non-rotating control plane that rejects unknown body keys would answer 400.
From the #4833 review at c721659: if a live process holds the CLI session lock for longer than 60 s, a login after device approval or a refresh that received a rotated credential fails without saving it. Options: keep waiting with a progress message, save the credential to a recovery file, or make the replacement recoverable on the cloud side.
From the #4833 review: the refresh response carries no CLI session expiry, so a cloud whose session expiry slides with use (idle window) still sees the CLI treat the session as expired at the login-time expiresAt. Proposal: the refresh response adds cliSession.expiresAt, and the CLI stores it with the rotated credential.
Follow-up PR scope, from the #4833 reviews (stacked on feat/cli-session-refresh-rotation):
loginWithDeviceAuth: after the locked save, if the returned access token has expired (a long lock wait), get a fresh token from the saved session before returning it.
Refresh with rotation: after the rotated credential is saved, if the returned access token has expired, refresh again through the rotation-aware path.
Hold the session lock from reading the stored credential, through the refresh request, to the replacement write. Keep device approval polling outside the lock. This also covers the stale-credential case after the grace window.
Already noted: a refresh response that says revoked while carrying tokens; acceptsRotatedRefreshCredential sent to a non-rotating cloud; cliSession.expiresAt in refresh responses.
Move the CLI session lock to a writable state location shared by every operation on the session. When the credential file cannot be replaced (a 0500 auth directory), allow a non-rotating exchange under the lock instead of failing with cli_session_store_unwritable (src/cli/auth-session.ts:535, test auth-session-refusal.test.ts:281-315).
Check the access token's remaining lifetime after the final awaited lock release, on every path that hands a token to a caller (auth-session.ts:415, :313, :606). If the release consumed the lifetime, do one bounded refresh and return a typed failure if there is still no live token.
auth status should name cli_session_issuer_unverified and the re-login hint for a v1 or origin-unverified session, instead of plain "Not authenticated".
In an interactive connect, an unverified session could start auth login automatically, like a missing session does.
A stored session whose cloudBaseUrl is not a valid URL fails with Invalid AGENT_DEVICE_CLOUD_BASE_URL (resolveCloudBaseUrl in src/cli/auth-session.ts), though the variable may be unset. Reject such a record in parseCliSessionRecord or name the stored URL in the error. This behavior predates fix(auth): send a stored CLI session only to the cloud that issued it #4921.
Activity
apex-sentinel-staging commentedon Nov 20, 2026
Apex Sentinel · Issue review
Suggested label:
featureThe issue is a follow-up implementation task from #4833, specifying new required behavior: recovery after a lost credential store, rejecting redirected refresh responses from a different origin, and making the failed-write test work as root.
thymikee commentedon Nov 21, 2026
From the #4833 review, for this follow-up:
revokedand also carries tokens is accepted, because the access-token branch returns before the revocation check.acceptsRotatedRefreshCredential; a non-rotating control plane that rejects unknown body keys would answer 400.thymikee commentedon Nov 21, 2026
From the #4833 review at c721659: if a live process holds the CLI session lock for longer than 60 s, a login after device approval or a refresh that received a rotated credential fails without saving it. Options: keep waiting with a progress message, save the credential to a recovery file, or make the replacement recoverable on the cloud side.
thymikee commentedon Nov 21, 2026
From the #4833 review: the refresh response carries no CLI session expiry, so a cloud whose session expiry slides with use (idle window) still sees the CLI treat the session as expired at the login-time
expiresAt. Proposal: the refresh response addscliSession.expiresAt, and the CLI stores it with the rotated credential.thymikee commentedon Nov 21, 2026
Follow-up PR scope, from the #4833 reviews (stacked on
feat/cli-session-refresh-rotation):loginWithDeviceAuth: after the locked save, if the returned access token has expired (a long lock wait), get a fresh token from the saved session before returning it.revokedwhile carrying tokens;acceptsRotatedRefreshCredentialsent to a non-rotating cloud;cliSession.expiresAtin refresh responses.thymikee commentedon Nov 22, 2026
Follow-ups from the #4927 round-4 review (#4927 (comment)), moved here because #4927 is closed for new hardening:
expiresAtof a refresh response is a non-empty string before use (src/cli/auth-session.tsaround lines 606, 716, 976).nullsuccess body as a tokenless response (around line 713).website/docs/docs/commands.md(around line 2686) to the behavior that ships.thymikee commentedon Nov 22, 2026
From #4833 (comment):
cli_session_store_unwritable(src/cli/auth-session.ts:535, testauth-session-refusal.test.ts:281-315).auth-session.ts:415,:313,:606). If the release consumed the lifetime, do one bounded refresh and return a typed failure if there is still no live token.thymikee commentedon Nov 22, 2026
From #4921 (#4921 (comment)):
auth statusshould namecli_session_issuer_unverifiedand the re-login hint for a v1 or origin-unverified session, instead of plain "Not authenticated".connect, an unverified session could startauth loginautomatically, like a missing session does.thymikee commentedon Nov 22, 2026
From #4921 at 1abd533, outside its invariant:
cloudBaseUrlis not a valid URL fails withInvalid AGENT_DEVICE_CLOUD_BASE_URL(resolveCloudBaseUrlinsrc/cli/auth-session.ts), though the variable may be unset. Reject such a record inparseCliSessionRecordor name the stored URL in the error. This behavior predates fix(auth): send a stored CLI session only to the cloud that issued it #4921.auth logoutwith a version 1 file was checked: it removes the file. Theauth statuswording is already listed above. Read the finding on the next full Sentinel review.