fix(auth): send a stored CLI session only to the cloud that issued it
TH
8h ago+138+138+012345678901234567890123456789-11-11-01234567890123456789
Summary
The CLI stores the cloud origin with its CLI session, but AGENT_DEVICE_CLOUD_BASE_URL overrode it, so the stored refresh credential was sent to whatever origin that variable named.
- A refresh refuses an override with a different origin before any request:
UNAUTHORIZED, reasoncloud_login_origin_mismatch(declared in aReasonTable), with a hint to log in again or unset the variable. The same origin with a different path or trailing slash still works. - Cloud auth requests (device-auth start and poll, session refresh) send
redirect: 'error', so a redirect cannot resend a credential or device code to another host.
Stacked on #4833; retarget to main after it merges.
Before / after
Stored CLI session issued by https://cloud.example, refresh with a different origin named
(the new test covers both rows; a same-origin override with another path still refreshes):
base: POSTs the stored refresh credential to https://elsewhere.example
head: refuses before any request
UNAUTHORIZED: The stored CLI session belongs to another cloud API origin.
reason: cloud_login_origin_mismatch
Validation
- Tested at
af2a887668. New testa stored CLI session is sent only to the cloud that issued it, without redirectsfails on the base commit and passes at head. - Locally at head:
pnpm format,pnpm typecheck,pnpm lint,pnpm check:layering, andnpx vitest run src/clipass (one unrelated timing test failed once under host load and passes alone). - CI obligations: GitHub lanes cover the rest. Unresolved risks: none known.

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.