Skip to content

fix(cli): stop sanity logout from sending env tokens to the session endpoint#1584

Closed
shapirodaniel wants to merge 2 commits into
stack/mint-and-claim/a1/06-ambient-reminderfrom
stack/mint-and-claim/a1/07-logout-env-token
Closed

fix(cli): stop sanity logout from sending env tokens to the session endpoint#1584
shapirodaniel wants to merge 2 commits into
stack/mint-and-claim/a1/06-ambient-reminderfrom
stack/mint-and-claim/a1/07-logout-env-token

Conversation

@shapirodaniel

@shapirodaniel shapirodaniel commented Jul 22, 2026

Copy link
Copy Markdown

Description

this PR quashes a pre-existing edge case: sanity logout was sending mint-and-claim robot tokens to populus session endpoints, which yielded raw, internal service errors. to address that, we're providing human/agent messaging on handling logout/login, while preserving non-401 api errors

Stack

(each PR reviews against its base; merge bottom-up only):

  1. stack/mint-and-claim/a1/01-terminal-presentation
  2. stack/mint-and-claim/a1/02-mint-core
  3. stack/mint-and-claim/a1/03-claim-reminders
  4. stack/mint-and-claim/a1/04-init-signpost
  5. stack/mint-and-claim/a1/05-remint-guardrail
  6. stack/mint-and-claim/a1/06-ambient-reminder
  7. stack/mint-and-claim/a1/07-logout-env-token ← this diff

What to review

commands/logout.ts: the env-token short-circuit and error sanitization.

Testing

Layer-scoped unit tests included (test:source ≥ 1:1); every layer validated standalone (full typecheck + targeted tests at each checkout).

pr1584-logout-env-token-warning

🤖 Generated with Claude Code


Note

Medium Risk
Touches CLI authentication and logout API behavior; changes are narrowly scoped with clear user messaging and tests, but mishandling tokens could affect session invalidation.

Overview
sanity logout no longer uses getCliToken(), which could prefer SANITY_AUTH_TOKEN and send robot/env credentials to /auth/logout. It now reads the stored session via getCliUserConfig('authToken') and passes that token explicitly into logout().

When SANITY_AUTH_TOKEN is set, the command warns that logout cannot end that identity and tells the user to remove the variable. With only an env token and no stored session, it skips the API and avoids the misleading “No login credentials” message. If both env and session exist, it still ends the stored session after the warning.

Non-401 logout failures now report only HTTP status (not response bodies that may leak internal service names) and leave local credentials so the user can retry. Tests cover env-only, env+session, and error sanitization, and clear SANITY_AUTH_TOKEN in the suite so shell tokens do not affect other cases.

Reviewed by Cursor Bugbot for commit a0bad1e. Bugbot is set up for automated code reviews on this repo. Configure here.

@shapirodaniel

Copy link
Copy Markdown
Author

bugbot run

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @sanity/cli

Compared against stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1d)

@sanity/cli

Metric Value vs stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1)
Internal (raw) 2.2 KB -
Internal (gzip) 838 B -
Bundled (raw) 11.20 MB -
Bundled (gzip) 2.11 MB -
Import time 858ms -6ms, -0.6%

bin:sanity

Metric Value vs stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1)
Internal (raw) 782 B -
Internal (gzip) 423 B -
Bundled (raw) 9.90 MB -
Bundled (gzip) 1.78 MB -
Import time 2.07s -8ms, -0.4%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1d)

Metric Value vs stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1)
Internal (raw) 114.1 KB -
Internal (gzip) 29.2 KB -
Bundled (raw) 21.76 MB -
Bundled (gzip) 3.46 MB -
Import time 768ms +2ms, +0.2%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-build

Compared against stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1d)

@sanity/cli-build/_internal/build

Metric Value vs stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1)
Internal (raw) 113.8 KB -
Internal (gzip) 28.7 KB -
Bundled (raw) 17.76 MB -
Bundled (gzip) 3.56 MB -
Import time 1.11s +6ms, +0.5%

@sanity/cli-build/_internal/env

Metric Value vs stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1)
Internal (raw) 1.8 KB -
Internal (gzip) 644 B -
Bundled (raw) 1.31 MB -
Bundled (gzip) 333.8 KB -
Import time 123ms +1ms, +0.8%

@sanity/cli-build/_internal/extract

Metric Value vs stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1)
Internal (raw) 8.6 KB -
Internal (gzip) 2.7 KB -
Bundled (raw) 155.0 KB -
Bundled (gzip) 39.5 KB -
Import time 241ms +2ms, +1.0%

🗺️ ./_internal/env · ./_internal/extract · @sanity/cli-build:./_internal/build treemap too large to embed · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — create-sanity

Compared against stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1d)

Metric Value vs stack/mint-and-claim/a1/06-ambient-reminder (f15a4f1)
Internal (raw) 908 B -
Internal (gzip) 483 B -
Bundled (raw) 931 B -
Bundled (gzip) 491 B -
Import time ❌ ChildProcess denied: node -
Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

Comment thread packages/@sanity/cli/src/commands/__tests__/logout.test.ts
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli/src/actions/init/initAction.ts 90.2% (+ 0.1%)
packages/@sanity/cli/src/actions/init/newCommandBanner.ts 100.0% (new)
packages/@sanity/cli/src/commands/logout.ts 91.3% (- 8.7%)
packages/@sanity/cli/src/commands/new.ts 100.0% (new)
packages/@sanity/cli/src/commands/projects/mint.ts 99.1% (new)
packages/@sanity/cli/src/hooks/prerun/claimReminders.ts 88.9% (new)
packages/@sanity/cli/src/services/mintProject.ts 76.8% (new)
packages/@sanity/cli/src/util/claimNudges.ts 96.8% (new)
packages/@sanity/cli/src/util/envFile.ts 100.0% (new)
packages/@sanity/cli/src/util/flowOutput.ts 78.9% (new)
packages/@sanity/cli/src/util/newCommandSplash.ts 100.0% (new)
packages/@sanity/cli/src/util/terminalLink.ts 100.0% (new)

Comparing 12 changed files against main @ f6fd22ccd40bb8346e8ecdb5e0cfe54d62f54823

Overall Coverage

Metric Coverage
Statements 78.6% (+ 0.0%)
Branches 70.1% (- 0.2%)
Functions 74.5% (+ 0.2%)
Lines 79.1% (+ 0.0%)

@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from 89fceb8 to 0c76d83 Compare July 22, 2026 16:01
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from 08d64c6 to 087dfc2 Compare July 22, 2026 16:01
@shapirodaniel

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 087dfc2. Configure here.

@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from aae0c9c to 16b3d9a Compare July 22, 2026 17:03
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from 92acb0c to 294038e Compare July 22, 2026 17:03
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from 88b6a10 to 8c23560 Compare July 22, 2026 17:58
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from 840cb6e to d2c413c Compare July 22, 2026 17:58
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from c92f162 to 563ef34 Compare July 22, 2026 18:16
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from 234e0c2 to eeae721 Compare July 22, 2026 18:16
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from e2e0180 to 97b4f4d Compare July 22, 2026 18:23
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from 1c52e0c to 40d1b6c Compare July 22, 2026 18:23
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from 09a38ca to a5d9ee8 Compare July 22, 2026 18:33
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from 5242789 to d86c767 Compare July 22, 2026 18:34
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from 7fccfad to 076ca58 Compare July 22, 2026 19:05
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from c8e4942 to 0b63f3b Compare July 22, 2026 19:05
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from 4a455df to 43146bd Compare July 22, 2026 19:15
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from d037f67 to d77c564 Compare July 22, 2026 19:15
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from 0147139 to 07cd654 Compare July 22, 2026 21:04
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from 4b13919 to fb712c1 Compare July 22, 2026 21:04
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from f9f492c to 68fdc80 Compare July 22, 2026 21:14
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from ea3e9f3 to c856974 Compare July 22, 2026 21:14
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from 841af5d to 890f1e0 Compare July 22, 2026 21:21
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from bc9be57 to 14cc694 Compare July 22, 2026 21:21
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from bb55ef1 to 508af35 Compare July 22, 2026 21:23
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from 141de79 to 818801c Compare July 22, 2026 21:26
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from d32bf8a to 0e2e34f Compare July 22, 2026 21:26
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch 3 times, most recently from 5e024e7 to 9c79ff8 Compare July 22, 2026 21:34
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from 27e3879 to 50f78be Compare July 22, 2026 21:34
@shapirodaniel

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f8100e5. Configure here.

…ndpoint

An env-sourced SANITY_AUTH_TOKEN (often a robot token from `sanity new`'s
.env) is not a login session: logging out cannot end it, and the session
endpoint rejects robot tokens with a raw internal error. Logout now names
the variable and instructs removal, targets only the stored login session,
and surfaces API failures by status alone — response bodies can name
internal services.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/06-ambient-reminder branch from a1d8d81 to f15a4f1 Compare July 22, 2026 21:56
@shapirodaniel
shapirodaniel force-pushed the stack/mint-and-claim/a1/07-logout-env-token branch from f8100e5 to 0c44527 Compare July 22, 2026 21:56
@shapirodaniel
shapirodaniel marked this pull request as ready for review July 22, 2026 22:47
@shapirodaniel
shapirodaniel requested a review from a team as a code owner July 22, 2026 22:47

@jwoods02 jwoods02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the whole stack Line comments are spread across the individual PRs, but leaving some general feedback here

The minted project config ledger lifecycle is solid with lots of edge cases though out (not clobbering .env, announcing on other projects if user forgets about unclaimed project concurrent process protection etc)

Two general comments:

  1. The two reminder mechanisms (tiered waterfall, machine-global, max 4 fires vs ambient line, directory-scoped, every command) confused me until I read runClaimNudges closely. The interplay (one slot per invocation, waterfall wins) only exists in a docstring. Worth a short written comment or little refactor maybe?

  2. Messaging consistency. We state the same facts differently across five surfaces: mint outro, waterfall nudges, ambient line, farewells, init banner. I've left copy suggestions on the individual PRs but happy to do a holistic wording pass offline

  3. Fable over comments in my opinion and a lot of the comments are more useful inside the context of your coding sessions than in the PR's IMO. Nit and happy to be overruled but I'd go through a comment cleanup pass, some can be deleted, some only need to be 1 liners.

Also worth knowing: these PR titles become the public changelog verbatim so maybe merge the PR's into 1, fix the changeset before merge into main? (I'm not a big stacked diff guy so unsure if there's cleaner ways here)

const envToken = process.env.SANITY_AUTH_TOKEN?.trim()
if (envToken) {
this.warn(
'SANITY_AUTH_TOKEN is set in the environment (often via ./.env) — logging out cannot end it. Remove that variable to stop acting as its identity.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we improve this error message a bit?

@shapirodaniel

Copy link
Copy Markdown
Author

all feedback addressed on #1592, canceling this PR to consolidate after offline sync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants