← Back to Pull requests

(fix) spawn: scrub the ambient credential inputs and the endpoint pair the isolation missed (issue #1535) #1536

Closed
unknown closed this pull request without merging on Nov 03, 2026 14:32 UTC
View on GitHub
unknown unknown commented on Sep 18, 2026 19:36 UTC
Author

Closes #1535.
Closes #1625.

SPAWN_ENV_REMOVE is the list of variables sessiometer removes from each environment it builds for an isolated spawn, and it was missing five inputs that Claude Code reads. Three of them decide the credential the child uses. ANTHROPIC_AUTH_TOKEN supplies one. CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR names a descriptor Claude Code reads an OAuth token from. That token outranks the seeded keychain item while the descriptor is readable and no access token from the CLAUDE_BG_AUTH_SNAPSHOT_PATH snapshot was consumed first. CLAUDE_CODE_API_KEY_FILE_DESCRIPTOR, when set, can stop the child's API clients from using the claude.ai login, and it supplies an API key while its descriptor is readable. The other two decide where the credential goes. ANTHROPIC_BASE_URL sets the host that Claude Code's first-party API client sends the child's credential to. On that client, a custom Authorization header from ANTHROPIC_CUSTOM_HEADERS replaces the bearer the client builds, unless Claude Code writes its own Authorization over it. That is a static read; no run set the variable. The list already removed two more credential inputs, CLAUDE_CODE_OAUTH_TOKEN and ANTHROPIC_API_KEY. Inherited, the five credential inputs do not all act the same way. In a 2026-11-02 run of the refresh child, with CLAUDE_CODE_OAUTH_TOKEN or a readable OAuth descriptor inherited, the child attempted no connection to the token host before it timed out. With ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN, it still attempted that connection. With the API-key descriptor variable set and nothing readable behind it, it exited 1 with Not logged in · Please run /login. In a separate run with no credential in the environment, a dummy stored token reached an inherited base URL as Authorization: Bearer. The three credential inputs and the two endpoint inputs the list was missing are now removed from the environment that each of the three seams builds: the refresh spawn, the login spawn and the issue #783 login-shell PATH harvest.

What changed

  • src/isolated_spawn.rs — SPAWN_ENV_REMOVE gains ANTHROPIC_AUTH_TOKEN (the contributor's commit), CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR and CLAUDE_CODE_API_KEY_FILE_DESCRIPTOR (#1535), and ANTHROPIC_BASE_URL and ANTHROPIC_CUSTOM_HEADERS (#1625). Its doc comment states the membership rule: an input is eligible when Claude Code reads it to decide which credential, credential store or OAuth client identity the child uses, or which host receives that credential, and eligibility is not membership. The doc comment names Claude Code 2.1.294 as the version the precedence was read at and cites the ledger section below. It says what each input supplies or selects, and it no longer claims that every inherited credential input stops the refresh. the_recorded_env_credential_sources_are_scrubbed_by_name (#1535) pins the five credential inputs by name at all three seams. the_base_url_and_its_companion_headers_are_scrubbed_by_name (#1625) pins the two endpoint inputs the same way. Deleting any of those names from the list fails a test with a message that names the seam and the variable. refresh_plan_builds_the_legacy_command pins the five new removals in its hand-written env map. A scrub_seams() helper builds the three seams once for the scrub tests. The login plan's #[cfg_attr(not(test), allow(dead_code))] attributes in this file are dropped, because login_account builds that plan in production.

  • build/version-compat.md — a new section, # Issue #1535 — environment inputs Claude Code consults ahead of the claude.ai login (CC 2.1.294), records the selection order read statically from the stock 2.1.294 binary: the login gate, the OAuth bearer builder and the API-key resolver, each with the byte offsets that locate it. Its subsection on ANTHROPIC_BASE_URL and ANTHROPIC_CUSTOM_HEADERS records why both are on the list, with the 2026-11-02 measurements. The section also lists the inputs the scrub leaves out with their reasons, what the read did not settle, and what would falsify it. The 2.1.207 "auth-source precedence" note gains a dated pointer: its order is the source-labelling order, not the selection order. The CC_SUPPORTED_MIN and CC_SUPPORTED_MAX lines are unchanged.

  • docs/specs/spawn-env-scrub.feature.md — Rule 5 covers the #1535 variables. Rule 6 covers the #1625 pair with three scenarios, the third being the measured case of a stored token sent as the bearer to an inherited base URL. The title now covers variables that decide where the credential goes, and the header counts match the rules and examples.

  • README.md — the paragraph on the official CLI's own network calls now says those calls run under that account's credential. It says sessiometer removes the variables listed in SPAWN_ENV_REMOVE from the environment it builds for those children, so they do not inherit a credential or a gateway that your shell sets through those variables. It no longer says the calls go "to Anthropic" under "your credential", "exactly as it would if you ran it yourself".
  • Decisions

    The maintainer delegated both decisions to councils on 2026-11-02.

  • ANTHROPIC_BASE_URL. It is scrubbed in this PR together with ANTHROPIC_CUSTOM_HEADERS, under #1625, after a security, a Rust and a delivery member converged with high confidence. Their shared falsifier ran and did not fire: with no credential in the environment, a stored token reached an inherited base URL as Authorization: Bearer.

  • The earlier third commit's other hunks. Its edits to the login prose, dead-code allowances and keep-alive tests in src/login.rs, src/capture.rs and src/paths.rs, and to the scrub-guard name in src/refresh.rs, are out of this PR and go to their own PR for #1415 and #1548. Row I-11 of docs/requirements/roster-loss-prevention.md needed no change, because the document declares its line anchors read at c1b9de8 and all of them resolve there.
  • Verification

    Black-box verification of all 16 acceptance criteria (AC1–AC8 of #1535's ratified scope, AC9–AC16 of #1625): Run 5 — PASS · Cardinality: 88 executed / 16 ACs · Rejected probes: 0 · package .tmp/verify-alexey-pelykh-sessiometer-issue-1535-package.md, block ## Run 5 — 2026-11-03T13:48:17Z (a local file in the maintainer's checkout). It graded a5dca2ab5ca4d39d5dd4ba0af7c5f1317594477d (tree f22e05dec48170a7902676c37043bfc52f2e5e40), and the verifier recorded that identity before its first probe and after its last. Run 4 (2026-11-03T12:32:57Z), on the same tree, read FAIL on ten probes. The verifier's return attributes each of those failures to its own instrument, names a sibling probe that shows the criterion holds, and found no defect in the four files. Run 5 is the re-run that return asked for. Runs 1 and 2 read PASS against earlier trees. Run 3 read FAIL against the pre-polish widened tree, and polish fixed its one defect.

    a5dca2a was never pushed. 312e11e is its rebase onto main at 3f05d39, and the rebase gave every commit a new SHA. git range-diff fd8640b..a5dca2a origin/main..HEAD reads = for all three commits, so 312e11e carries the graded patches unchanged.

    Local gate run 2026-11-03T11:39:16Z–11:40:49Z on tree dcd17b8, this branch's change merged onto b9df076, every step exit 0: the test job's five commands on rustc 1.96.0 (2472 passed, 0 failed, 18 ignored), the msrv job's build and test on 1.87.0 (2472 passed), both deny checks, the four doc-gates scripts and the three trailer guards. The pushed tree 48952778 differs from dcd17b8 only in the documentation main gained since b9df076 (c39c3ca and 3f05d39), and no Rust code reads those files. On it, at 14:14Z, the four doc-gates scripts, the three trailer guards and both deny checks were re-run, all exit 0. Not run locally: the swift, panel-goldens and formula jobs, whose paths this PR does not touch, and check-ci-ok-needs.sh, because yq is not installed and ci.yml is unchanged.

    CI on 312e11e: run 41651806514, ci-ok success. test, msrv, deny, doc-gates and gate-change-ack passed; swift, panel-goldens and formula were path-skipped.

    Not checked: Linux and Windows builds, since no CI job compiles for either; the macOS keychain read in the base-URL case, since the store probe used the plaintext credentials file.

    Follow-ups

  • #1626 — the other inherited inputs that bypass or redirect the seeded login, including _CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL and CLAUDE_CODE_API_BASE_URL.

  • #1618 — Claude Code's fixed-path credential fallbacks, which no environment scrub reaches.

  • #1619 — whether the isolated spawn's environment stays a denylist or becomes an allowlist.

  • #1620 — a drift canary for the inputs Claude Code consults ahead of the claude.ai login.

  • #1621 — the live harvest test, which stays green with the harvest scrub deleted.

  • #1622 — a sweep of inherited descriptors at process start.

  • A separate PR for #1415 and #1548 carries the hunks removed from this PR.

  • Not filed: a completeness check for scrub_seams(), which today protects only the seams listed in it by hand.

  • Not filed: the sentence after the quote below says ANTHROPIC_AUTH_TOKEN is honoured unconditionally at 2.1.294. The ledger's removal table says Y9() writes that bearer only when neither Me nor co() holds. That sentence is kept unchanged here.
  • From the original PR description (Stefano Benatti)

    Found the hard way rather than by reading: an ambient CLAUDE_CODE_OAUTH_TOKEN in my own ~/.zshrc silently defeated every swap — status reported the newly-active account while sessions kept billing the other one, which sessiometer's own usage samples confirmed. Mapping the chain to explain that surfaced this neighbouring hole. I have not independently re-verified against the CC binary that ANTHROPIC_AUTH_TOKEN is honoured; the authority cited is the repo's own recorded chain.

    The continuation re-read the binary: at 2.1.294, ANTHROPIC_AUTH_TOKEN is honoured unconditionally in this build, and the chain the issue cited turned out to be the source-labelling order rather than the selection order, which the ledger section now records.

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: alexey-pelykh Review duration: 65935m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1536"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%