Repository navigation
fix(#8259): verify Claude hooks.json and hook scripts before each launch - #8261
Conversation
The Claude runtime passed --settings /sandbox/claude-config/hooks.json on every iteration but never checked it or the hook scripts under /sandbox/claude-config/hooks/. The agent runs as the user that wrote both, so iteration 1 could rewrite them and iteration 2 would load the edits. Port the codex launch guard to Claude, reusing its helpers: - Bootstrap (installClaudeHooks) records, runner-side and keyed by sandbox name, the digest of the hooks.json it uploaded and the embedded digest of each hook script it installed. - Run refuses with exit -1 when hooks are enabled but no digests were recorded. Otherwise the launch checks hooks.json and runs the exhaustive hooks-directory check (codexHookScriptsGuard) before sourcing .env, then again after it behind `unset -f`, using `command -p` utilities. A mismatch exits 97, which Run reports as tampered hooks. - The hook commands now run `python3 -B`. Without it, running the PostToolUse chain writes hooks/__pycache__/, and the exhaustive check would refuse iteration 2 of every run. Not covered here: Claude Code's own claude-config/settings.json (plugin state from bootstrapPlugins), the target repo's .claude/settings.json, and rewrites during an iteration. The docs now say so. Launch tests change hooks.json or a script between iterations (modify, append, delete, swap, plant __pycache__ or a json/ package, rewrite from .env, shadow sha256sum) and assert iteration 2 is refused. Pre-existing failures that also occur on the base commit in this sandbox: TestSSRFValidator_DNSResolution and TestSSRFValidator_EgressAllowlist (internal/security), and TestStartFetchService_* and TestPostScriptEnv_NoSchemaAppended* (internal/cli). pre-commit could not fetch its hook repos (TLS), so the local hooks were run directly. Closes #8259 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🤖 Review · Commit: |
|
🤖 Finished Review · ✅ Success · Started 3:48 PM UTC · Completed 3:58 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.07 |
Site previewPreview: https://df5a090f-site.fullsend-ai.workers.dev Commit: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Risk Assessment: moderate (2/5) DetailsModerate risk preserved following re-review anchoring, driven by unflagged modifications to runtime launch behavior and elevated file churn, balanced by complete acceptance criteria coverage and low metadata risk from a familiar bot author with no protected path edits. Previous runRisk Assessment: moderate (2/5) DetailsModerate risk preserved following re-review anchoring, driven by unflagged modifications to runtime launch behavior and elevated file churn, balanced by complete acceptance criteria coverage and low metadata risk from a familiar bot author with no protected path edits. Previous run (2)Risk Assessment: moderate (2/5) DetailsModerate risk preserved following re-review anchoring, driven by unflagged modifications to runtime launch behavior and elevated file churn, balanced by complete acceptance criteria coverage and low metadata risk from a familiar bot author with no protected path edits. Previous run (3)Risk Assessment: moderate (2/5) DetailsModerate risk driven by unflagged modifications to existing runtime launch behavior and elevated churn in touched files, balanced by complete acceptance criteria coverage and low metadata risk from a familiar bot author with no protected path edits. Previous run (4)Risk Assessment: moderate (2/5) DetailsModerate risk driven by unflagged modifications to existing runtime launch behavior and elevated churn in touched files, balanced by complete acceptance criteria coverage and low metadata risk from a familiar bot author with no protected path edits. Previous run (5)Risk Assessment: moderate (2/5) DetailsModerate risk: a focused security fix by an automated bot with complete acceptance criteria coverage and no protected-path edits, balanced by high churn and coupling across the touched runtime files and a change to launch behavior without a feature flag. |
ReviewFindingsMedium
Earlier findings
Labels: PR hardens the sandboxed Claude runtime launch in Go and touches security docs. Next steps:
Previous runReviewFindingsHigh
Medium
Low
Previous run (2)ReviewFindingsHigh
Next steps:
Previous run (3)ReviewFindingsHigh
Earlier findings
Next steps:
Previous run (4)ReviewFindingsHigh
Low
Next steps:
Previous run (5)ReviewFindingsMedium
Low
Next steps:
|
|
🤖 Finished Fix · ✅ Success · Started 4:00 PM UTC · Completed 4:07 PM UTC Commit: Runtime: claude · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.54 |
- clear LD_PRELOAD, LD_LIBRARY_PATH and LD_AUDIT after sourcing .env and before the second hooks guard, matching the codex launch; add launch tests for the ordering and the effect - reject a HooksSettingsPath other than the default in ClaudeRuntime.Run so --settings cannot load a file the guard did not hash - rename claudeHooksTamperedExit to claudeHooksMissingExit (97) - update architecture.md and tool-call-risk-assessment.md, which still said Claude Code had no hooks integrity check Not changed: moving the codex-prefixed helpers into a runtime-neutral file (deliberate reuse, out of scope for this PR). Pre-commit hooks could not run (hook repos unreachable from the sandbox); checked whitespace, secrets, gofmt, go vet and go test ./internal/runtime/. Addresses #8261 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
🔧 Fix agent — iteration 1 (bot-triggered)Addressed 5 of 6 findings: added the LD_* unset before the second guard with tests, rejected a non-default hooks settings path, renamed the exit constant, and updated the two stale docs. Declined the helper-reorganisation nit as out of scope. go test ./internal/runtime passes. Pre-commit could not run because its hook repositories are unreachable from the sandbox. Fixed (5):
Disagreed (1):
Tests: passed CI inspections (5):
Conflict update: skipped; strategy Decision points
Next steps:
|
|
🤖 Finished Review · ✅ Success · Started 4:09 PM UTC · Completed 4:23 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.84 |
|
🤖 Finished Fix · ✅ Success · Started 4:25 PM UTC · Completed 4:30 PM UTC Commit: Runtime: claude · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.49 |
Address review feedback on PR #8261: the Claude launch guard verifies hooks.json and the hook scripts but does not pin the python3 interpreter, PATH or PYTHON* environment across the agent-writable .env. List that under "Not covered" in runtime-implementation.md, drop the "no longer shares this residue" wording, qualify the matching sentences in the threat-model and tool-call-risk docs, and add a short implementation note to ADR 0100. Pinning the interpreter and PATH is deferred: .env legitimately prepends runner-written PATH entries, so it needs a design of its own. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
🔧 Fix agent — iteration 2 (bot-triggered)Deferred the high-severity interpreter/PATH pinning finding as the review permits: documented it under 'Not covered' and removed the overstated 'no longer shares this residue' wording across the docs. Also added the optional short implementation note to ADR 0100. Docs only; no code changed. The sandbox could not run pre-commit (network blocked), so the staged secret scan and whitespace check were run instead. Fixed (2):
Tests: passed CI inspections (5):
Conflict update: skipped; strategy Decision points
Next steps:
|
|
🤖 Finished Review · ✅ Success · Started 4:32 PM UTC · Completed 4:43 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.50 |
|
🤖 Finished Review · ✅ Success · Started 2:42 PM UTC · Completed 2:55 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.83 |
|
@ralphbean @ifireball could one of you review and approve? I took this bot PR over: merged main, closed the |
waynesun09
left a comment
There was a problem hiding this comment.
Approving after the takeover. Main is merged in, and the hooks guard now runs on both sides of .env inside the pinned-binary launch; gateway runs check the hook scripts only, since their settings go inline. TestClaudeLaunch_EnvCannotReplaceClaude covers the claude function and PATH-wrapper routes, and a real local run did two clean iterations and refused iteration 2 with exit 97 after hooks.json was edited. What remains is tracked in #8494 and #8498.
…ks-integrity Point TestInstallClaudeHooks_PinsInterpreter's upload stub at $5: #8485 put --no-git-ignore before the sandbox name, so the local path moved from $4 to $5. Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
|
🤖 Finished Review · ✅ Success · Started 4:57 PM UTC · Completed 5:08 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.43 |
Renumber the ADR 0150 -> 0152 (0146-0151 are claimed by open PRs fullsend-ai#8679, fullsend-ai#8694, fullsend-ai#8698, fullsend-ai#8702; fullsend-ai#8702 was filed first for 0150). Per waynesun09's reviews (first round 14:56, second round 18:29): - restructure the Decision as rules 1-10 with the conformance table separated out (moved to docs/contributing/runtime-implementation.md so it can track the implementation as the code changes, linked from Consequences) - add the Options section back per the ADR template (fail-open with warning, per-runtime resolvers, version-floor acceptance, hash-verification as primary mechanism — each rejected) - add rules 9 (executables, not just directories) and 10 (scope: settings sources fullsend-ai#8637, hooks.json integrity fullsend-ai#8261, plugin trust ADR 0094) - gaps against the rules are tracked in issues, not the ADR: fullsend-ai#8763 (per-file trust for every executable a hook runs) and fullsend-ai#8764 (paths that let a tool call through without a hook verdict), both filed by the reviewer; rule 8's root-launch exception stays as a one-sentence stated limit - fix the pre-fullsend-ai#8605 Codex wording: the PATH was restored for itself and its hook adapter's children - fix the architecture.md sentence to state the decision for all runtimes, not Codex only - factual corrections from the first round: the shared resolver is hookPreflightInterpreter; the boundary value is FULLSEND_TRUSTED_PATH; the pre-fullsend-ai#8605 gap was image-PATH agent-writable dirs; pi included (same treatment in fullsend-ai#8589, pinned python3 not Node) Per the dual-model review round (GLM 5.3 + DeepSeek V4.1 Flash): - breaking change names the runtimes (pi has no version preflight) - forge scope before Consequences, full forge list Signed-off-by: James Tanner <jtanner@redhat.com>
Renumber the ADR 0150 -> 0152 (0146-0151 are claimed by open PRs fullsend-ai#8679, fullsend-ai#8694, fullsend-ai#8698, fullsend-ai#8702; fullsend-ai#8702 was filed first for 0150). Per waynesun09's reviews (first round 14:56, second round 18:29): - restructure the Decision as rules 1-10 with the conformance table separated out (moved to docs/contributing/runtime-implementation.md so it can track the implementation as the code changes, linked from Consequences) - add the Options section back per the ADR template - add rules 9 (executables, not just directories) and 10 (scope) - gaps tracked in issues only: fullsend-ai#8763 and fullsend-ai#8764 linked bare, no implementation-state prose in the ADR - fold the root-launch case into rule 8 as an explicit scope precondition (accurate wording: the PATH still drops relative, empty, and missing entries as root; it cannot exclude agent-writable directories) instead of a contradictory Consequences 'limit' - cite the pre-fullsend-ai#8605 Codex behavior at the correct SHA (bbe0ab2^1 = 191d723), not unqualified line numbers - state the OpenCode exclusion in rule 6 and the conformance table (no ADR 0090 hook wiring until unbound-force#515) - fix the fullsend-ai#8589 chronology (merged earlier the same day as fullsend-ai#8605, not an extension after it) - fix the Options wording on hash verification (detects a substitution only at the next check; the ADR 0094 preflight detects at check time, not 'after the fact') - reference PR fullsend-ai#8261 explicitly as a PR - fix the architecture.md sentence to state the decision for all runtimes, not Codex only - factual corrections from the first round: the shared resolver is hookPreflightInterpreter; the boundary value is FULLSEND_TRUSTED_PATH; the pre-fullsend-ai#8605 gap was image-PATH agent-writable dirs; pi included (same treatment in fullsend-ai#8589, pinned python3 not Node) - update the conformance table Codex row to the post-fullsend-ai#8633 mechanism (envDataTrustedPin within codexBinaryPin) with the bbe0ab2 state noted Per the dual-model review round (GLM 5.3 + DeepSeek V4.1 Flash): - breaking change names the runtimes (pi has no version preflight) - forge scope before Consequences, full forge list Signed-off-by: James Tanner <jtanner@redhat.com>
Summary
The Claude runtime loaded
/sandbox/claude-config/hooks.jsonvia--settingson every iteration but never checked it or the hook scripts under/sandbox/claude-config/hooks/. The agent can write to both, so iteration 1 could weaken the security hooks and iteration 2 would load the change. Each launch now checks both against digests held on the runner side and refuses to start (exit 97) on a mismatch. This is the same approach the codex runtime already uses.Related Issue
#8259
Changes
internal/runtime/claude_integrity.go(new):hooks.json, plus each installed script's name and the digest of its embedded copy.codexSHACheck,codexHookScriptsGuard,codexAssetSHA256). It binds each digest to its filename and checks the directory exhaustively: no extra entries, no symlinks or subdirectories.internal/runtime/claude.go:installClaudeHooksrecords the digests after a successful upload.Runfails closed (exit -1) when hooks are enabled but no digests were recorded.buildRunCommandruns the guard before sourcing.env, then again after it behindunset -f, usingcommand -putilities, so a.envthat rewrites a file or shadowssha256sumis still caught.internal/security/hooks.go: hook commands now runpython3 -B. Without it the PostToolUse chain writeshooks/__pycache__/during iteration 1, and the exhaustive check would then refuse iteration 2 of every run.runtime-implementation.md(hook contract, feature matrix, codex and pi comparisons), the threat model, and a troubleshooting entry indocs/runtimes/claude.md.claude-config/settings.json(plugin state written bybootstrapPlugins);<repo>/.claude/settings.json;Testing
make lint:pre-commitcould not fetch its hook repos in the sandbox (TLS error). I ran the local hooks directly instead: gofmt, go vet, lint-interface-doc-sync, lint-docs-links, lint-mint-embed-sync, lychee, plus whitespace and EOF checks. All passed.hooks.jsonor a script between iterations and assert iteration 2 is refused. Changes covered: modify, append, delete, swap in another allowed script, plant__pycache__/or ajson/package, rewrite a file from.env, and shadowsha256sumwith a function and a PATH entry.hooks.jsonwithPYTHONDONTWRITEBYTECODEunset and asserts the guard still passes. I confirmed this test fails without-B.Runfailing closed without recorded digests, andRunreporting exit 97.go test ./internal/runtime/passes. Patch coverage on the changed Go lines is about 95%.TestSSRFValidator_DNSResolutionandTestSSRFValidator_EgressAllowlist(internal/security; sandbox DNS);TestStartFetchService_*andTestPostScriptEnv_NoSchemaAppended*(internal/cli).🤖 Generated with Claude Code
Closes #8259
Post-script verification
agent/8259-claude-hooks-integrity)003926f5cd3a1f8dc33a32b66964960891ed738a..HEAD)