Client or integration
Codex CLI
Area
Authentication and account pool
Summary
An imported local CLI credential (Grok ~/.grok/auth.json or Claude .credentials.json) whose expires_at is invalid (e.g. "garbage", "", "1970-01-01") is treated as valid and never refreshed:
src/oauth/local-token-detect.ts:27 — new Date(entry.expires_at as string).getTime() returns NaN for any unparseable string.
shouldAdoptGrokGeneration() (src/oauth/local-token-detect.ts:52-62) then behaves incorrectly for NaN:
disk.expires <= now + refreshSkewMs is always false for NaN → the expired/garbage credential passes the expiry gate;
bothExpiriesExist = stored.expires > 0 && disk.expires > 0 is false (NaN > 0 is false) → the function falls through to return true, so the disk credential is adopted as the authoritative generation.
authoritative() (src/oauth/index.ts:441) therefore replaces the stored credential with the garbage one, and the refresh path never re-validates it — the stale credential occupies the account slot indefinitely.
getLoginStatus() (src/oauth/index.ts:1178) reports loggedIn: !!cred (credential exists), ignoring expires/needsReauth; ocx status then prints ✓ logged in in the "OAuth logins" section for an expired or unparseable credential (the separate health block may flag needsReauth, but the logins section is the misleading first screen).
Same structural issue as a stale/epoch-garbage expires_at (e.g. 1970-01-22) observed in a real CLI credential file: the import is adopted even though it can never be refreshed.
Reproduction
- Create a fake Grok CLI credential:
{
"https://auth.x.ai::1": {
"key": "xai-stub-access",
"refresh_token": "xai-stub-refresh",
"expires_at": "not-a-date"
}
}
at ~/.grok/auth.json (or a Claude .credentials.json with expiresAt: "garbage").
- Run
ocx login xai --import-local (or any flow that reaches detectGrokCliToken/authoritative).
- Observe: the invalid-expiry credential is adopted (
shouldAdoptGrokGeneration returns true); ocx status shows xai ✓ logged in; no refresh is attempted because the expiry comparison is NaN.
Expected: an unparseable/expired expires_at must be treated as unknown → refresh required (or reject the import), never as "valid and never refresh".
Version
2.11.1 (121f1ad9)
Operating system
Cross-platform (Linux/macOS CLI credential paths; Windows unaffected by ~/.grok but the same parsing logic applies)
Provider and model
xai (grok) / anthropic (claude) — local CLI token import
Checks
Client or integration
Codex CLI
Area
Authentication and account pool
Summary
An imported local CLI credential (Grok
~/.grok/auth.jsonor Claude.credentials.json) whoseexpires_atis invalid (e.g."garbage","","1970-01-01") is treated as valid and never refreshed:src/oauth/local-token-detect.ts:27—new Date(entry.expires_at as string).getTime()returnsNaNfor any unparseable string.shouldAdoptGrokGeneration()(src/oauth/local-token-detect.ts:52-62) then behaves incorrectly forNaN:disk.expires <= now + refreshSkewMsis alwaysfalseforNaN→ the expired/garbage credential passes the expiry gate;bothExpiriesExist = stored.expires > 0 && disk.expires > 0isfalse(NaN > 0isfalse) → the function falls through toreturn true, so the disk credential is adopted as the authoritative generation.authoritative()(src/oauth/index.ts:441) therefore replaces the stored credential with the garbage one, and the refresh path never re-validates it — the stale credential occupies the account slot indefinitely.getLoginStatus()(src/oauth/index.ts:1178) reportsloggedIn: !!cred(credential exists), ignoringexpires/needsReauth;ocx statusthen prints✓ logged inin the "OAuth logins" section for an expired or unparseable credential (the separate health block may flagneedsReauth, but the logins section is the misleading first screen).Same structural issue as a stale/epoch-garbage
expires_at(e.g.1970-01-22) observed in a real CLI credential file: the import is adopted even though it can never be refreshed.Reproduction
{ "https://auth.x.ai::1": { "key": "xai-stub-access", "refresh_token": "xai-stub-refresh", "expires_at": "not-a-date" } }~/.grok/auth.json(or a Claude.credentials.jsonwithexpiresAt: "garbage").ocx login xai --import-local(or any flow that reachesdetectGrokCliToken/authoritative).shouldAdoptGrokGenerationreturnstrue);ocx statusshowsxai ✓ logged in; no refresh is attempted because the expiry comparison isNaN.Expected: an unparseable/expired
expires_atmust be treated as unknown → refresh required (or reject the import), never as "valid and never refresh".Version
2.11.1 (
121f1ad9)Operating system
Cross-platform (Linux/macOS CLI credential paths; Windows unaffected by
~/.grokbut the same parsing logic applies)Provider and model
xai (grok) / anthropic (claude) — local CLI token import
Checks