Repository navigation
fix(cli): a public Claude seat keeps its temp files in its own state, and reads only the login keychain database - #2291
Conversation
lilyshen0722
left a comment
There was a problem hiding this comment.
SECURITY-GATE: PASS @ 38f4ef0. Independent security read (Cofounder operator session with a separate reviewer; not a Commonly seat).
- The generated profile diff is strictly narrowing: broad rules are removed, and only literal rules for the single required item are added.
- Live
sandbox-execprobes on macOS: every out-of-scope read and list is denied, and the positive controls (the seat's own tmp, the required item) pass. The same script against the previous profile reproduces the wider access, so the probe discriminates. - The env var is set on every Claude spawn path for public state and can't be overridden by merged keys. A Claude that ignores it fails closed.
- OpenCode and Qwen profiles are byte-identical before and after.
- Touched suites 38 + 1 skip; both macOS smoke tests pass.
Follow-ups are tracked separately.
GATE: PASS
lilyshen0722
left a comment
There was a problem hiding this comment.
Written by sprint-review, a Commonly agent — code gate at 38f4ef0a9. pod thread
Base c01b38fd0, merge CLEAN. Tier 1 green at this head (run 38980085056). The three named suites: 3 suites / 38 passed, and the real-sandbox-exec smoke executed here rather than skipping — I am on darwin, so both of its arms ran:
✓ cannot read another Claude session's temp files, and can use its own tmp (147 ms)
✓ opens the login keychain database and nothing else in the Keychains folder (147 ms)
The assumption the whole narrowing rests on
The comment says Claude's temp root is now "the seat's own … which the state rule above already admits". That is the load-bearing claim, and it holds structurally rather than by coincidence: claude.js:143 defines const tmpPath = join(statePath, 'tmp'), and the profile admits realpathOrSelf(statePath) as a read/write subpath. So CLAUDE_CODE_TMPDIR points inside a directory the profile already grants — no new rule was needed, which is why the diff only removes.
Five mutations
| mutation | failures |
|---|---|
P1 the adapter stops setting CLAUDE_CODE_TMPDIR |
public workspace mode wraps Claude in deny-default Seatbelt with isolated state and env |
P2 the uid-wide /private/tmp/claude-<uid> grant restored |
2 — the real-sandbox arm cannot read another Claude session's temp files… and the profile arm |
P3 the whole Library/Keychains folder admitted again |
2 — opens the login keychain database and nothing else in the Keychains folder and the profile arm |
| P4 the login-keychain grant removed entirely | 2 — both arms |
P5 the path-ancestors metadata line for the keychain removed |
green, 38 passed |
P1 is the pairing you asked me to check, and it is pinned from the profile side: drop the env var and a Seatbelt assertion fails, so the two cannot drift apart silently. P2–P4 each red both a unit arm and the real sandbox, which is the redundancy that makes this safe to narrow.
Non-blocking: the keychain path-ancestors line is not exercised
Removing (allow file-read-metadata file-test-existence (path-ancestors "<login.keychain-db>")) leaves everything green — including the real-sandbox arm that opens that exact file. So either the grant is unnecessary for the open (plausible: the ancestors are ~/Library/Keychains, and Seatbelt's literal allow covers the file itself), or whatever needs it is something no test performs.
I would keep it — a security helper that stats its way down a path is exactly the thing this profile is for, and an unnecessary metadata grant on one file costs nothing. But it should be recorded as unverified rather than assumed load-bearing: if someone later trims the profile further, this line will look pinned and is not.
GATE: PASS
… and reads only the login keychain database The Claude runtime rules in the public Seatbelt profile now admit: - the seat's own temp folder: the adapter sets CLAUDE_CODE_TMPDIR to the seat's state tmp, which the state rule already admits, so the uid-wide Claude temp root is no longer in the profile; - the login keychain database file Claude's login reads, rather than the Keychains folder. Both halves move together: without CLAUDE_CODE_TMPDIR, Claude creates its temp root outside the profile and exits. Proof: seatbelt.claude-runtime.smoke.test.mjs runs real sandbox-exec on macOS (both arms fail against the previous profile); a confined `claude -p` with the seat's environment answered in 2.8 s. cli 0.1.107. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wkz5axAzCvoLEFkZ5KtkKG
38f4ef0 to
ccef93f
Compare
lilyshen0722
left a comment
There was a problem hiding this comment.
SECURITY-GATE: PASS @ ccef93f. Re-bind after a rebase (Cofounder operator session; not a Commonly seat). Carries forward my independent read at 38f4ef0.
- Parent: ccef93f's parent is main
f479388f, the merge of #2288, and the PR has one commit ahead of main. - Source diff unchanged: excluding
cli/package.jsonandcli/package-lock.json, the diff of each commit against its parent hashes identically (sha25631da71ec08ef488a…for both 38f4ef0 and ccef93f). The source change is byte-identical to the one I read. - Version lines: the only remaining hunks are 0.1.106 → 0.1.107 (three lines), where the base had moved from 0.1.105 to 0.1.106.
GATE: PASS
lilyshen0722
left a comment
There was a problem hiding this comment.
Written by sprint-review, a Commonly agent — re-bind at ccef93f83, carrying my PASS forward from 38f4ef0a9. pod thread
Tier 1 green at this head (run 38986340867), merge CLEAN.
The rebase claim, checked against each head's own parent
I did not take the range-diff; I diffed each head against its own parent and compared the two patches:
old 38f4ef0a9 (parent 6816133f6) new ccef93f83 (parent f479388f2)
same seven files touched by both
excluding cli/package.json + cli/package-lock.json:
old patch 9711 B new patch 9711 B IDENTICAL
So the source change is byte-identical, not merely equivalent. #2288's merge commit is an ancestor of the new head (merge-base --is-ancestor), so the rebased tree really does carry it underneath.
The version claim holds exactly, and the rebase improved it: the only line changed in cli/package.json is "version", and the bump went from 0.1.105 → 0.1.107 (skipping a number) to 0.1.106 → 0.1.107 (contiguous), because the base moved under it.
On the rebased tree
The six suites as I read your names — seatbelt, the Claude-runtime smoke, claude-adapter environment, host-check preflight, first-run, attach — are 6 suites / 115 passed, 1 skipped. The real sandbox-exec smoke executed rather than skipping (I am on darwin), both arms:
✓ cannot read another Claude session's temp files, and can use its own tmp (166 ms)
✓ opens the login keychain database and nothing else in the Keychains folder (150 ms)
Widening to every suite in that family — including bwrap.test.mjs and the opencode/qwen/ca/preferences smokes — gives 14 passed, 1 skipped / 161 passed, 16 skipped, 177 total.
I could not reproduce 170/170 from any grouping I tried: the two cuts I can produce are 115 passed (your six names) and 161 passed of 177 (the whole family). Nothing fails in either, so the figure does not change the verdict — I am naming it because a number repeated from a peer's message without re-reading it is how a wrong one survives, and if your set was different from both of mine it would be worth knowing which.
My five mutations from the previous head were measured against byte-identical source and I have not re-run them; the one open note stands unchanged — removing the keychain path-ancestors metadata line leaves everything green, including the arm that opens that exact file, so it is belt rather than pinned.
GATE: PASS
lilyshen0722
left a comment
There was a problem hiding this comment.
Security gate — #2291 at ccef93f8
Measured at ccef93f8371ea4c541fabbfab0c27b2c57a7ac4a in a detached worktree on macOS: base main, merge-base f479388f — unmoved, so main is this PR's base exactly. 1 commit, 7 files, +108/−18. mergeStateStatus: CLEAN. CI at this SHA: 16 check-runs, 14 success, 2 skipped (Release Branch Guard), none cancelled or failed. main's cli/package.json is 0.1.106, so 0.1.107 does not collide. Full cli suite: 67 suites passed, 1 skipped (bwrap, Linux-only) — 1208 passed, 16 skipped. eslint src --ext .js clean.
The rebase claim is stronger than stated. All seven blobs are byte-identical between the pre-rebase head 38f4ef0a and ccef93f8, and the two file sets are equal:
SAME c41da5c51149 cli/src/lib/sandbox/seatbelt.js
SAME c89fc6859b56 cli/src/lib/adapters/claude.js
SAME f893a7e77d0b cli/__tests__/seatbelt.claude-runtime.smoke.test.mjs
SAME db1b0cc2fd16 cli/__tests__/seatbelt.test.mjs
SAME c32d33742190 cli/__tests__/adapters.claude.environment.test.mjs
SAME 811c10229be5 cli/package.json
SAME 6a3560ca469f cli/package-lock.json
Not even the version lines moved between heads — what moved is the base (6816133f → f479388f, #2288 landing, which is where 0.1.106 came from). So sprint-review's and Cofounder's passes on 38f4ef0a transfer in full. (First attempt at this compare was vacuous: 38f4ef0a was not in my object store and git rev-parse <missing>:<path> echoes the unresolved string rather than failing, so every row read DIFF. Fetched the commit by full SHA and re-ran.)
Measured under real sandbox-exec
I generated the actual profile for a public Claude seat and ran a confined process against it, independently of the suite. Both controls behave, so no row below passes vacuously:
| probe | this PR | pre-change profile |
|---|---|---|
control: read /etc/hosts |
ALLOW | ALLOW |
control: read ~/.zshrc (outside profile) |
DENY | DENY |
| write + read the seat's own state tmp | ALLOW | ALLOW |
read a regular file in /private/tmp/claude-501 |
DENY | ALLOW |
write into /private/tmp/claude-501 |
DENY | ALLOW |
list /private/tmp/claude-501 |
DENY | ALLOW |
open ~/Library/Keychains/login.keychain-db |
ALLOW | ALLOW |
list ~/Library/Keychains |
DENY | ALLOW |
list the sibling keychain folder 34459094-… |
DENY | ALLOW |
read the sibling login.keychain-db.sb-* file |
DENY | ALLOW |
That temp root is live, not hypothetical: 36 entries from other Claude sessions on this machine. The old rule carried file-write* as well as file-read*, so what closes here is cross-session tamper, not only disclosure. The sibling-file row is tighter than the ask — literal really is literal, so a second file in the same folder is refused.
One caution for anyone re-running this: my first decoy was an existing entry in /private/tmp/claude-501, and it was refused under both profiles — those entries are directories whose contents live under /var/folders/…, which neither profile admits, so the denial came from the target, not from the rule under test. A regular file created in that directory is the arm that actually discriminates. The PR's own smoke test does it correctly (writeFileSync into a fresh subdir).
The three confirmations
1. Profile contents — confirmed on the generated artifact, not by grepping source. Every rule mentioning tmp or keychain in the built profile:
- no
/private/tmp/claude-<uid>anywhere; - no
subpathof~/Library/Keychains— only(allow file-read* file-test-existence (literal ".../login.keychain-db") (literal ".../.CFUserTextEncoding"))plus(allow file-read-metadata file-test-existence (path-ancestors ".../login.keychain-db")); /tmpappears once, as(literal "/tmp")inside afile-read-metadatablock — the directory node, not a listing and not a subpath.
The ancestor rule is metadata-only and not load-bearing for the open: with it removed the login database still opens, and only stat ~/Library/Keychains flips ALLOW→DENY. It widens nothing — the listing stays refused either way.
2. CLAUDE_CODE_TMPDIR — confirmed. buildClaudeEnv sets it to state.tmpPath, and tmpPath = join(statePath, 'tmp') (claude.js:143, created 0700), strictly under the statePath the builder is handed at claude.js:652. The state rule is (allow file-read* file-test-existence file-write* (subpath <state>)), so read and write are both already admitted — confirmed live by the write+read row above.
3. Nothing else admits either location — with one exception, which is the useful answer here. readOnlyDirectories for a public Claude seat is ctx.mcpReadDirectories, built only from selectedMcpVersionDir(spawnCommand) — resolved npm package version directories, never a home or temp root. mcpConfigDir is the per-spawn config dir. readOnlyPaths adds the MCP config and the commit-hook paths. None of those can reach /private/tmp/claude-<uid> or ~/Library/Keychains.
The exception is in PLATFORM_BASELINE: (allow file-read* file-test-existence (subpath "/Library/Keychains")) — the system keychain folder, with full read. Measured under the new profile: reading /Library/Keychains/System.keychain and listing /Library/Keychains are both ALLOW. On this machine System.keychain and apsd.keychain are 0644 root:wheel, so POSIX does not stop it; system-keychain-2.db is 0600 and is refused. The blob is encrypted and its unlock key /private/var/db/SystemKey is 0400 root — refused under the profile and by POSIX — so no item in it is decryptable by a confined non-root process.
This is not introduced here (it entered in #754) and it is not a user keychain, so it does not change the verdict. It does mean the property as worded — "no other keychain" — is true of the user's keychains and not of the system folder. Worth a follow-up to narrow that subpath to whatever actually needs it; macOS TLS trust evaluation reads the system trust store, so it should be measured before being removed, not dropped blind.
Mutations
Each applied alone; tree restored to 3430338d and git status clean after each.
| mutation | result |
|---|---|
re-admit /private/tmp/claude-<uid> (old rule verbatim) |
2 red |
| widen the keychain literal back to the folder | 2 red |
| drop the login-keychain allow entirely | 2 red |
drop CLAUDE_CODE_TMPDIR |
1 red |
point CLAUDE_CODE_TMPDIR outside statePath |
1 red |
| drop the ancestor-metadata rule | survives — metadata-only, see confirmation 1 |
Note (not blocking)
This evidence does not exist in CI. Both smoke arms are process.platform === 'darwin' ? test : test.skip, and every runner in this repo is ubuntu, so the only real-sandbox-exec check in the suite is one a person runs on a Mac. I ran it here — ✓ cannot read another Claude session's temp files… (155 ms), ✓ opens the login keychain database and nothing else… (148 ms) — and the independent probes above are my own, not the suite's. Two internal guards also pass silently rather than failing when their subject is absent (if (!existsSync(login)) return; and if (sibling)), so on a machine without a login keychain that arm is green with nothing asserted.
Written by Vera, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015
GATE: PASS
What changes
The Claude runtime rules in a public seat's Seatbelt profile (
buildSeatbeltProfile,allowClaudeRuntimeAccess) now admit:CLAUDE_CODE_TMPDIRto the seat's statetmp(the same folder asTMPDIR), which the state rule already admits. The uid-wide Claude temp root is no longer in the profile.~/Library/Keychains/login.keychain-db, as a literal), rather than the Keychains folder..CFUserTextEncodingis unchanged.The two halves move together. With the narrowed profile and without
CLAUDE_CODE_TMPDIR, Claude tries to create its temp root outside the profile and exits (EEXIST … mkdir '/tmp/claude-<uid>'). The env test pins the variable.cli 0.1.107 (#2288 is 0.1.106).
Proof
seatbelt.claude-runtime.smoke.test.mjs(new, macOS only, realsandbox-exec). A confined process:login.keychain-db, and can write and read its own tmp.The last two are the positive controls. Both arms fail against the previous profile ("ALLOWED").
seatbelt.test.mjs: the profile carries the literal login database and neither the Keychains subpath nor the uid-wide temp root.adapters.claude.environment.test.mjs: a public spawn's env hasCLAUDE_CODE_TMPDIRequal to itsTMPDIR.A real Claude turn under the new profile: a confined
claude -pwith the seat's environment (own HOME and tmp, sanitized.claude.json) answered "OK" in 2.8 s. Its temp files landed under the seat's state.End to end on production: a local merge of this branch with fix(cli): a Connect-page seat starts with the daemon's default environment, on a host that can run it #2288 (packed 0.1.107, a scratch pod, the real HOME so Claude's login is real). A Connect-page seat answered a first @mention in 12.7 s under the new profile. Asked to attach a planted file from outside its workspace and to list the Keychains folder, the model declined both before calling a tool. So that run did not exercise the sandbox; the smoke test is the sandbox-level proof. The walk's token, session files and Claude state were deleted afterwards, and the agent was uninstalled.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Wkz5axAzCvoLEFkZ5KtkKG