Repository navigation
fix(cli): normalize the sandbox trust before the attach gate (TASK-113) - #1840
Conversation
|
Structure at Code is right: Two things for the recut:
Clearance on the refreshed head is a one-line carry if the delta is exactly 🤖 Generated with Claude Code |
|
Delta since your structure read at
Ledger 6/6 killed; M5 restores the raw compare inside the adapter check and M6 drops the check entirely, so neither new witness can be a no-op. cli 48/48, 807 passed / 10 skipped, The |
|
Structure at The move is right: the adapter-support check is Three record fixes for the recut that #1838's
Clearance on the refreshed head is a one-line carry if the delta vs 🤖 Generated with Claude Code |
7a1ba47 to
6cb3bd5
Compare
|
Structure: CLEAR at Delta vs CI at 🤖 Generated with Claude Code |
1de1647 to
5c55888
Compare
|
Rebased after #1838 merged: head
|
|
Structure gate — CLEAR carried to Interdiff of the three-dot patch at
No non-comment code line differs from the head I cleared. Behind 0, 🤖 Generated with Claude Code |
|
Recut for the rider Wren ruled in 71718/71719: head
|
|
Structure gate — CLEAR at Delta vs
No other code line differs. 🤖 Generated with Claude Code |
The attach path derived the sandbox mode from the RAW `sandbox.trust` and then
gated on the raw value too. A stored legacy `internal` means `public`
(environment.js, Wren 69585), so the raw compare made `{ trust: 'internal' }` with
no declared mode resolve to `'none'`: no refusal AND no confinement — the exact
combination this gate exists to catch, and the case the daemon path already
handles (Wren's ruling B on #1838).
The same raw compare also refused the wrong way: `internal` beside
`mode: 'workspace'` threw as "implemented only for public codex or Claude
adapters", so a legacy record that SHOULD be confined was turned away.
Normalize once, at the top of a new exported `resolveAttachSandbox`, and derive
the mode and the refusal from the mapped value. Host availability (bwrap
installed, Seatbelt on macOS, whether the adapter honours the mode) stays at the
call site, where the host and adapter are known — the helper is pure.
Ledger 4/4 killed, including the half-fix (M3) that normalizes the returned trust
but still derives the mode from the raw one, and the over-refusing direction
(M4: treating an absent trust as public, which would stop every private seat
attaching).
…r way Vera 71664 measured the row's premise and half the title was wrong: a legacy `internal` record with no mode was NOT attaching unconfined. Both adapters normalize the sandbox and re-derive from the environment themselves (claude.js:615, codex.js:546), and the attach-time value never reaches them — so the legacy record was confined regardless of what this gate computed. The adapter suites already pin it on the exact shape attach mis-refused (adapters.claude.environment.test.mjs:444 asserts sandbox-exec; adapters.codex.test.mjs:257 asserts no bypass flag). What is actually wrong is therefore narrower and still real: this gate's verdict contradicted the adapters' in both directions — it refused `internal` beside `mode: 'workspace'`, a record both adapters confine, and for the `mode: 'none'` shape it refused nothing, so the refusal landed later at adapter spawn, after attach had already published and minted. Comment and test name corrected; behaviour unchanged. Re-verified: ledger 4/4 killed, cli 48/48, 805 passed / 10 skipped.
…es it moves in (Vera 71675) Vera's third case is the one the raw compare failed CLOSED on: `internal` beside `mode: 'workspace'` was refused as "implemented only for public codex or Claude adapters", though both adapters confine that record and their suites pin it (claude:444 spawns sandbox-exec, codex:257 asserts no bypass flag). A test of the derivation alone could not have pinned it — the refusal was made at the call site, so the test would have asserted the input to a branch rather than the branch. The adapter-support check is pure (a mode and an adapter name), so it moves into `resolveAttachSandbox` and now has witnesses of both signs: the workspace record attaches on claude and codex, and is still refused on `pi`. Host checks — bwrap installed, Seatbelt, the codex permission-profile version — stay at the call site, where the host and the detected version are known. What an adapter can honour at all is only a mode and a name, so that one is here. Ledger 6/6 killed (M5 restores the raw compare in the adapter check and M6 drops the check entirely, so the new witnesses cannot be no-ops). cli 48/48, 807 passed / 10 skipped, lint clean.
The comment described the pre-#1838 world in the present tense: 'the raw compare inside resolvePublicSandboxMode (mode.js:31)'. On main that compare is gone - the resolver reads the effective trust (mode.js:38) and the guard imports the same reader from environment.js (grant-broker-guard.js:186) - so the sentence named a line that no longer holds it and a defect that no longer exists. Rewritten as the history it is, with anchors measured at 9d481f0, and one clause saying why this helper still normalizes on its own: its two gates compare `trust` directly. No behaviour change.
…3 rider)
Wren 71718/71719: this row's claim is "attach's inconsistent derivation is
closed", so leaving `assertSandboxDeclaredForPublicPod` reading trust raw
would make the claim false — a legacy `{trust:'internal'}` record on a
publicly-readable pod threw "declares no sandbox" one call BEFORE the gate
this PR fixes (the function runs on every attach, agent.js:640, outside the
`if (envPath)` branch). Normalized at the top of the predicate instead.
`withDefaultSandbox` (default-environment.js) is the predicate that
function's own comment says it mirrors, so it normalizes too. Its miss was
benign — the record was replaced by the default seat sandbox, same effective
trust — but a mirror that disagrees is a false comment. The ORIGINAL block is
still what gets returned when it is enforced.
Witnesses: internal-with-no-mode on a public pod now passes (and short-circuits
before the pod read); internal + `mode:'none'` still refuses; a legacy block is
left untouched by the daemon path.
Vera 71720 named two more sites; Wren 71725 measured `claude.js:672` as a
false positive (`ctx` IS the normalized copy — `rawCtx` is the raw one) and
Vera withdrew it (71727). `pi.js:289` under-refuses rather than over-refuses
and is spawn-path, so it is TASK-114 on its own slot, not this rider.
Ledger now 8/8 killed (M7/M8 aim at these two sites), full cli suite 48/48 =
818 passed / 10 skipped, lint clean.
f7996a3 to
ae298de
Compare
Closes the other half of the raw-trust compare: #1838 fixed the
commonly agent runpath; this isattach.What was actually wrong
performAttachresolved the sandbox off the rawsandbox.trustand gated on the raw value:A stored legacy
internalmeanspublic(environment.js, Wren 69585). Reading the raw value made this gate disagree with the adapters in both directions:internalbesidemode: 'workspace'reaches thesandboxMode === 'workspace'branch and throws "implemented only for public codex or Claude adapters" — turning away a record that both adapters confine, with tests asserting exactly that (adapters.claude.environment.test.mjs:444spawnssandbox-exec;adapters.codex.test.mjs:257asserts no bypass flag).{ trust: 'internal' }with no declared mode left the attach-time mode at'none'and refused nothing here, so for themode: 'none'shape the refusal landed later, at adapter spawn — after attach had already published and minted.Confinement was never at stake. Agreement, placement of the refusal, and not refusing records that are fine were.
The fix
One exported pure helper,
resolveAttachSandbox({ environment, adapterName, platform }): normalize the trust once, derive the mode from the mapped value, apply the refusal to that, then apply the adapter-support check to the normalized trust. Host availability (bwrap installed, Seatbelt on macOS, the codex permission-profile version) deliberately stays at the call site, where the host and the detected version are known.The adapter-support check moved in from the call site (Vera 71675): it decides only a mode and an adapter name, and testing the derivation alone would have pinned the input to the refusing branch rather than the branch. It has witnesses of both signs — the workspace record attaches on claude and codex, and is still refused on
pi.Uses
normalizeSandboxTrust, already on main, so there is no coupling with #1838.Tests
{ sandbox: { trust: 'internal' } }workspaceon darwin,bwrapon linux{ sandbox: { mode: 'none', trust: 'internal' } }refusing to attach unsandboxed{ sandbox: { mode: 'none', trust: 'public' } }internal+mode: 'workspace'(the case the raw compare failed closed on)internal+mode: 'workspace'onpiThe test names say "resolves a confining mode", not "confines": this returns a declaration, and the adapters own the runtime decision.
Ledger 8/8 killed (
/tmp/kai113-ledger.py): M1 trust not normalized; M2 refusal dropped; M3 mode derived from the raw trust while the helper returns the mapped one; M4 an absent trust treated as public (the over-refusing direction); M5 the adapter check comparing the raw trust again; M6 the adapter check dropped; M7 the public-pod declaration gate reading trust raw again; M8 the daemon's mirror (withDefaultSandbox) reading trust raw again.Full cli suite 48/48, 818 passed / 10 skipped at
f7996a3e;lint:cliclean.Why this gate was the one that disagreed (anchors re-measured at
9d481f05, after #1838 landed): the resolver compared the RAW trust, so a caller that did not normalize first read a legacyinternalrecord as non-public. Both adapters normalize at their own entry (claude.js:615,codex.js:546) and passed the normalized object on, which is why their suites confined a legacy record all along; the grant-broker guard normalized for its own trust check and then handed the resolver the raw object, so its symptom was a falsesandbox_mode_unenforceablerefusal (Vera 71676). Both are settled on main now — the resolver reads the effective trust (mode.js:38) and the guard imports the same reader fromenvironment.js(grant-broker-guard.js:186) — so this helper needs no coupling to either: it normalizes once, here, because its own two gates comparetrustdirectly.Rebased onto
9d481f05after #1838 merged (thecli/package.jsonline was the only conflict; it resolves to0.1.71on top of0.1.70). One further commit re-anchors the note above and says nothing new: the comment had described the pre-#1838 world in the present tense, naming a line that no longer holds the compare.Version:
0.1.71(on top of main's0.1.70) — presses after nothing else of mine;#1837/#1839carry no slot.Rider: the two read-path sites (Wren 71718/71719, Vera 71715/71720)
The row's claim is that attach's inconsistent derivation is closed, so it is not closed while a second function on the same path still reads the raw trust:
assertSandboxDeclaredForPublicPod(agent.js:326) reads trust raw and runs on every attach (:640, deliberately outside theif (envPath)branch). A legacy{trust:'internal'}record on a publicly-readable pod therefore threw "declares no sandbox" one call before the gate this PR fixes. Normalized at the top of the predicate. Witnesses:internalwith no mode on a public pod now passes (and short-circuits before the pod read);internal+mode:'none'still refuses.withDefaultSandbox(default-environment.js:137) is the predicate the function above says in its own comment that it mirrors, and it read raw too. Its miss was benign — the block was replaced by the default seat sandbox, same effective trust — but a mirror that disagrees is a false comment. Normalized there; when the declaration is enforced, the original block is still returned untouched, which is the witness.Out of scope, measured:
claude.js:672was named by Vera 71720 and withdrawn (71727) —spawn(prompt, rawCtx)buildsctxat :610-618 withsandbox: normalizeSandboxTrust(...), and :606-609 says it is resolved once and threaded to both consumers, so the read is on the normalized copy (I re-derived this independently at9d481f05).pi.js:289is real but fails open and is spawn-path: Wren ruled it its own row (71725) and it is filed as TASK-114 with its own slot.