Repository navigation
Conversation
AGENT_DEVICE_CLOUD_BASE_URL overrode the cloud origin stored with the CLI session, so the stored refresh credential went to whatever origin the variable named. A refresh now refuses an override with another origin (UNAUTHORIZED, reason cloud_login_origin_mismatch) before any request, and cloud auth requests no longer follow redirects, which would resend a credential or device code to the redirect target.
Size Report
Startup median (7 runs, lower is better):
|
auth-session.test.ts is at the 1000-line cap.
… table R89 measures wire-published reason literals against the merge-base. Read the reason from a ReasonTable beside the origin check and regenerate the error reasons page.
This comment has been minimized.
This comment has been minimized.
|
The change binds a stored CLI session to its issuing cloud as intended, but five problems remain at af2a887. A second independent pass found them. A second independent pass found that existing version-1 session records can still name an origin that did not issue the credential (auth-session.ts:434). Before this change, a login for origin A could follow a device-auth poll redirect to origin B and store B's credential under A's URL (base a9750b5, A second independent pass found that a late rotation can replace the credential of a different origin (auth-session.ts:483). Two origins backed by a cloned session store can return the same session ID and initial credential. If a refresh at A is in flight while a login at B replaces the record, the lock-protected comparison accepts B's record and stores A's replacement under B's URL. The next refresh then sends it to B. The saved origin must be part of the lock-protected comparison before a rotation is applied. A second independent pass found that same-origin auth redirects now fail (auth-session.ts:599). If a cloud answers a device-auth start, device-auth poll, or CLI-session refresh POST with a 307 or 308 to its canonical path, the base follows it. This head fails at the first redirect, even when the stored issuer and the requested origin match. A cross-origin redirect also gives a generic fetch failure instead of the origin-mismatch reason. The rule should be: every redirect target is resolved and its origin checked against the original request origin before it is followed, within a bounded chain. A cross-origin target should return a typed refusal before it is followed. A second independent pass found that a same-origin override changes the identity of an existing cloud connection (auth-session.ts:461). Take a login at https://cloud.example and a named connection created on the base with AGENT_DEVICE_CLOUD_BASE_URL=https://cloud.example/path. If the profile leaves clientId or runId for the CLI to supply, repeating the same connect now hashes the stored URL instead of the override (cloud-profile.ts:43-56). The profile and its path change, and the existing connection is rejected unless the caller passes --force (connection.ts:162-171). The stored URL should stay the refresh destination, and the validated same-origin override should stay the connection identity input. A second independent pass found that the cloud connect docs no longer match behavior (commands.md:2686). They say connect refreshes a stored CLI session into a short-lived token. With a different cloud API origin set and a valid stored session, connect now stops with cloud_login_origin_mismatch before it fetches the profile. Please qualify the refresh description with the stored-origin rule, and say the caller can log in at the new origin or unset the override. Not blocking, and these can be taken or left: add one sentence to the AGENT_DEVICE_CLOUD_BASE_URL row in configuration.md that, with a stored login, the variable must name the same origin or the user must run auth login with it; catch the redirect failure in postJson and rethrow a typed AppError with a hint naming the cloud base URL (the default cloud answers the refresh POST with a 307 to /unlock today, and it was already broken at base); compare the stored origin with the origin of the override only when it is set, so a hand-edited malformed stored URL is not reported as an invalid override (also true at base); open a follow-up issue to bind use of the minted access token to a daemonBaseUrl allowed for the issuing cloud, since with both settings it goes to flags.daemonBaseUrl while the refresh credential itself stays home; and split the origin test into two tests with the temp dir removed in a finally, as the sibling tests do. CI is green: all 17 checks pass or skip at af2a887, and Body rules failed at packet time but passes on rerun. There are no conflicts. The five items above must be fixed before merge. Not verified here: the new test and the src/cli suite were not run locally, so the claim that the test fails on base comes from reading the base path. No real cloud was exercised; a request to the default cloud showed a same-origin 307 to /unlock on the refresh path, and what a working cloud answers was not tested. The error-reasons.md page appears to be generated from ReasonTable comments, and the generator was not rerun. |
…e a rotation, and document the rule A same-origin AGENT_DEVICE_CLOUD_BASE_URL still names the connection, while the refresh goes to the URL stored with the session. A rotation is not stored over a session that a login moved to another cloud. The commands docs state the stored-origin rule and the cloud_login_origin_mismatch outcome.
|
Reply to #4921 (comment), at 727d73c:
|
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
|
At 727d73c, three items from the earlier review are fixed, and two remain open on the code. The two declined items are outside the scope that blocks this PR. CI shows 16 checks with none failing, and there are no conflicts. A second independent pass found that a version-1 record can already hold cloud A's URL with a credential issued by cloud B. The old login could follow a cross-origin poll redirect and save the response credential under its original login URL. The old refresh could also run against cloud B through the environment override and store B's replacement under A's URL. Both records pass the version-1 parser at auth-session.ts#L296-L310. With the override unset, either refresh path then sends B's credential to A, as in auth-session.ts#L435. This breaks the rule that a credential goes only to the cloud that issued it, even though the request matches the stored URL. The rule to enforce: a stored session is used only when its issuer is established from persisted state. Please version the session format so a fresh login through the origin-checked flow records the issuer. Please also require a fresh login before refreshing any legacy record whose issuer cannot be established. A second independent pass also found a regression for clouds that serve an auth POST through a 307 or 308 to a working path on the same origin. Before this PR, fetch followed the redirect and kept the POST. Now the shared transport at auth-session.ts#L605 rejects the first response. A redirect at device-auth start stops login from starting. A redirect at device-auth poll stops login from finishing. A redirect at refresh stops a valid stored session from refreshing. The rule to enforce: every auth request, in the shared transport that all three call, follows a bounded redirect chain only when each resolved target has the original request origin. Accepted hops keep Fetch redirect semantics, and cross-origin targets are rejected before anything is resent. Please update the command documentation to describe this behavior. Not verified here: the new tests and the src/cli suite were not run locally, so regression validity comes from reading the earlier code at a9750b5. Not verified here: any real cloud, since the |
Summary
The CLI stores the cloud origin with its CLI session, but
AGENT_DEVICE_CLOUD_BASE_URLoverrode it, so the stored refresh credential was sent to whatever origin that variable named.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.redirect: 'error', so a redirect cannot resend a credential or device code to another host.Stacked on #4833; retarget to
mainafter 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):
Validation
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.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).Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.