Repository navigation
harden(hooks): wire tirith + supply-chain gates into the live hook path (#100 G1) - #106
Merged
Merged
Conversation
…path G1 audit finding #2 of #100: the Tirith pre-execution gate and the supply-chain gate only ran on the legacy `contextcrawler rewrite` subcommand (hooks/rewrite_cmd.rs). The live Claude Code PreToolUse path (`contextcrawler hook claude` -> process_claude_payload) did permissions + rewrite but never invoked either gate, so the defence-in-depth layer was effectively dark for every real agent session. Wire both gates into process_claude_payload_with, after the existing PermissionVerdict::Deny handling and before get_rewritten: * New pure helper gate_decision(tirith, supply_chain) -> GateDecision { Proceed, Ask, Deny } maps the two gate verdicts. supply-chain Block -> Deny; supply-chain Unavailable -> Ask (fail closed); tirith should_downgrade -> Ask; both clean -> Proceed. Block outranks Ask. * supply-chain Block reuses the #102 deny machinery -- emits a PayloadAction::Deny (audit_tag deny:supply_chain_block) routed through the existing emit_claude_deny. No new PayloadAction variant. * A gate Ask sets gate_ask, which suppresses the permissionDecision "allow" so Claude Code prompts -- a gate Ask wins over a permissions Allow. * A gate-flagged command with no rewrite (e.g. `pip install foo`) cannot express "ask" in the PreToolUse protocol, so it fails CLOSED to a deny rather than a silent Skip. Both gates stay opt-in: Tirith via CONTEXTCRAWLER_TIRITH_REQUIRED, supply-chain via supply_chain.enabled. When disabled the gates are no-ops and the hook behaves byte-for-byte as before -- covered by a no-regression test asserting `git status` still rewrites with no deny. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…100 — config cache + visible no-rewrite deny The defence-in-depth gates now run on every hook-routed Bash command, so two non-blocker issues from the Codex review are tightened here. Finding 1 — supply_chain_gate::load_config() read the config file from disk on every call, before the early-return-when-disabled. Back it with a process-lifetime std::sync::OnceLock cache (read_config_from_disk does the actual read once) so the hottest path hits disk at most once per process. tirith_gate has no equivalent per-call config read — it spawns a subprocess and only the dashboard touches files — so no change needed there. Finding 2 — when a gate returns Ask on a command with no contextcrawler rewrite, the code hard-Denies (the PreToolUse protocol can't express "ask without rewrite"). The Deny is correct (fail closed) but was silent. Emit a clear stderr line — "[contextcrawler] gate flagged '<cmd>' (ask) but it has no rewrite; denying (protocol limitation)" — via the factored-out gate_no_rewrite_deny_log() helper so an operator can see why a command was blocked. Deny behaviour itself is unchanged. Tests: load_config returns a stable &'static (pointer-identity proves the cache); gate_no_rewrite_deny_log emits the explanatory line. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
noogalabs
pushed a commit
to noogalabs/contextcrawler
that referenced
this pull request
Jun 4, 2026
…hard deny (thehoff#111) The thehoff#106 gate wiring put the Tirith defence-in-depth gate on the live `hook claude` path. When a gate returned `GateDecision::Ask` for a command with no contextcrawler rewrite (e.g. a credential-bearing `curl` loop), the no-rewrite branch fell through to a hard `PayloadAction::Deny` — an "ask" the user could never answer. Real users hit this in REST-verification workflows. The Claude Code PreToolUse protocol supports `permissionDecision` values of `allow`, `deny`, and `ask` (the existing `handle_vscode` path already emits `ask`). This change routes a gate `Ask` + non-rewritable command to a real `ask` decision so the user gets an approve/deny prompt. - Add `PayloadAction::Ask { reason, audit_tag, cmd }` mirroring `Deny`. - Add `emit_claude_ask` alongside `emit_claude_deny`; same JSON schema, `permissionDecision: "ask"`. - `run_claude` gains an `Ask` arm; `run_claude_inner` mirrors it. - The `gate_no_rewrite` branch now returns `Ask` (audit tag `ask:gate_no_rewrite`) instead of `Deny`; stderr line reworded. - A supply-chain hard `Block` (`GateDecision::Deny`) still routes through `Deny` — a real hard-block stays a deny. - Gate decision is now injectable via `process_claude_payload_with_gate` so the no-rewrite Ask path is deterministically testable. Tests: gate `Ask` + non-rewritable command yields the `Ask` action / `ask` JSON; gate `Ask` + rewritable command still rewrites; supply-chain `Block` still denies. cargo test --workspace and clippy --workspace --release pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
User-directed fix for G1 audit finding #2 (issue #100): the defence-in-depth gates were not on the live hook path. Now wired in. Codex-reviewed; follow-up applied.
The problem
contextcrawler hook claude(the installed PreToolUse hook) →process_claude_payloadran permissions + rewrite but never invokedtirith_gateorsupply_chain_gate. Those gates fired only on thecontextcrawler rewritesubcommand — a non-default entrypoint. Defence-in-depth did not run for the actual agent hook.What changed (
src/hooks/hook_cmd.rs)gate_decision(tirith, supply_chain) -> GateDecision { Proceed, Ask, Deny }. supply-chainBlock→ Deny;tirith should_downgrade→ Ask; supply-chainUnavailable→ Ask (fail-closed); else Proceed. Block outranks Ask.process_claude_payloadafter thePermissionVerdict::Denyblock, before rewrite. A gateAsk/Denyoverrides a permissionsAllow(theallowemit now requiresverdict == Allow && !gate_ask).PayloadAction::Deny/emit_claude_deny— no duplicate machinery.Deny(the PreToolUse protocol can't express "ask without rewrite") — and now logs why.CONTEXTCRAWLER_TIRITH_REQUIRED) and supply-chain (supply_chain.enabled) stay opt-in — when disabled the gates are no-ops, exactly as before. This change makes them actually run on the hook path when enabled.Codex review follow-up (
8b53388)supply_chain_gate::load_config()now caches viaOnceLock— disk read at most once per process (the gates run on every hook call; a per-call disk read was hot-path overhead).Denynow emits a stderr line explaining the protocol-limitation reason.Test plan
cargo test --workspace— 2332 pass, 0 failtest_disabled_gates_no_regression— drives the real gate fns; disabled gates →git statusstill rewrites normally, no denycargo build --releasecleanPart of the #100 audit.
🤖 Generated with Claude Code