Repository navigation
Govern Read in the Claude Code host - #597
rocklambros merged 2 commits into
Conversation
|
This pull request's description says it closes #330, which is on the project roadmap. When it merges, GitHub closes that issue and the roadmap counts it as delivered. Please confirm the change delivers the whole issue before merging. |
drk-ram
left a comment
There was a problem hiding this comment.
Reviewed claude-code.hookmap.yaml, settings.json, mapping.yaml, policy/manifest.yaml, build-envelope.ts, govern-step.ts, and the updated test suites (201ddb30):
- Per-tool result output routing (
outputs.by_tool/outputsForinbuild-envelope.tsandgovern-step.ts): Resolvingoutputs.by_tool[tool]through a singleoutputsFor(entry, payload)helper used by bothbuildPayloadandgovernStepensuresReadextracts and patches$.tool_response.file.contentinside$.tool_response.filewithout inheritingBash'sstdout/stderrpaths. - Load-time validation (
assertByToolWellFormed): Verifying atloadHookmaptime that eachby_toolentry declares only{from, within}withfromstrictly insidewithinprevents misconfigured hookmaps from silently dropping redactions at runtime.
Read's file content reached the model without passing the Guardian. The shipped settings matched neither gate for Read, and the result gate's hookmap knew only Bash's stdout. Both settings matchers now include Read. The request gate reads its file_path, and the policy manifest registers Read so AGT does not fail closed on an unknown tool. At the result gate, outputs.by_tool gives Read its own path next to the existing one, the way policy_target_argument has a default and a by_tool map. Read's content is $.tool_response.file.content, and a modification is written back within $.tool_response, so Claude Code gets the shape it expects. buildPayload and governStep pick the path through the same function, outputsFor, and loadHookmap rejects a malformed by_tool entry. Bash keeps its path. Measured live on Claude Code 2.1.325: the model receives the file with the example key replaced by [REDACTED]. Read is governed on text only. An image, a PDF or a notebook has no file.content, so the posture decides, as the hookmap and the README now say. GenAI-Security-Project#568 tracks those types. Refs GenAI-Security-Project#330 Signed-off-by: Marco Bellingeri <49072576+MK023@users.noreply.github.com>
201ddb3 to
0b78a14
Compare
|
I rebased this onto The only change from 201ddb3, the commit @drk-ram approved, is |
drk-ram
left a comment
There was a problem hiding this comment.
Re-reviewed at 0b78a14b (ts-cases.json parity digest update): outputs.by_tool, assertByToolWellFormed, and the Claude Code Read request/result gate tests are clean and passing.
|
Thanks @MK023, great work, and the live runs make this easy to trust. Non-blocking, for after merge:
|
Resolves the conflict with GenAI-Security-Project#462 in reference-implementations/agt/README.md: the quick start keeps Read in both matchers and adds the onFailure note. Signed-off-by: Marco Bellingeri <49072576+MK023@users.noreply.github.com>
|
@almogbhl thanks for the review. The @-mention issue is #598. A file named with Agreed on the README line about the stock policy, and on Grep as the next path with the same leak (#434 item 7). I can take both after this lands. #462 landed on The push dismissed the approvals, as the branch rules require. @drk-ram @almogbhl, that sentence is the only new thing to look at. @bar-capsule, it still needs a code owner review when you have time. I ran the CI on the merged head locally, on linux/amd64 only. |
|
@bar-capsule thanks for the approval at 8a35bb2. The PR is clean against |
ac31e8a
into
GenAI-Security-Project:integration
Carries PR #597 (Govern Read in the Claude Code host) to release/0.2. Signed-off-by: Rock Lambros <rock@rockcyber.com>
What changed
The Claude Code host in
reference-implementations/agtgoverns Read. Until now the shipped settings matched neither gate for Read, so a file's content reached the model without the Guardian seeing it. Read goes through the request gate on itsfile_pathand through the result gate onfile.content, and a redaction comes back in Read's own output shape.outputs.by_toolworks likepolicy_target_argument:fromandwithinare the default, and a listed tool uses its own pair and inherits nothing from the default. Inpackages/host-adapter,outputsForpicks the pair, and bothbuildPayloadandgovernStepcall it, so a replacement is written into the same leaf that went to the Guardian.loadHookmaprejects a malformedby_toolentry. Bash keeps its path, and OpenCode's singleoutputspath loads as before.Which issue does this implement
Closes #330
Base branch
integration, because this touches the specification, schemas, a referenceimplementation, an adapter, tests, or CI
main, because every changed path is on the documentation lane allowlist inCONTRIBUTING.md
Type of change
Evidence
Before, on Claude Code 2.1.316 against
integration(my 2 Nov comment on #330, 3 runs out of 3):evaluation_failed.After, on Claude Code 2.1.325 with the shipped
settings.json, a fresh Guardian and a fresh session per run, 3 runs per case:[REDACTED]in place of the key[REDACTED]both times[REDACTED]catof the same file through Bash[REDACTED]I also ran it once interactively, in the default permission mode, and got the same result.
bun testinreference-implementations/agtgoes from 1285 to 1292 passing, with 4 skipped and 0 failing, andbun run typecheckexits 0. Each new case failed againstintegrationbefore the code went in:file.contentand keeps every sibling field. A deny withholds it the same way, and an allow leaves the file alone and writes no audit entry.file_path.loadHookmaprefuses a malformedby_toolentry in three shapes.Scope and deviations from the 2 Nov scope
file.base64orfile.cellsand nofile.content, so the result gate cannot build a request and the posture decides. Underdenythe hook exits 2, Claude Code still delivers the output, and the audit entry says it was blocked ([Bug] The Claude Code result gate can let a secret through on stderr or on exit 2 #375). The hookmap and the README say so, and [Conformance] Claude Code host: a Read of an image, a PDF or a notebook is delivered ungoverned, and underdenythe audit log says it was blocked #568 tracks it, starting with the audit entry.result-output.tsis unchanged.governStephands it Read's own pair throughoutputsFor, so the existing replacement code already writes intofile.contentwithintool_response.hosts/claude-code/test/andpackages/host-adapter/test/, rather than intest/redaction.test.ts. One helper there,withHookmapFile, moved up one level so the new cases can share it.@in the prompt reaches the model without the Guardian, and the reference Guardian does not evaluateuserMessage#598.packages/guardian/src/assemble-snapshot.ts. The comments and READMEs that named the old matchers name the new ones.The Go Guardian from #169 replays answers recorded from this Guardian, and
TestRecordingIsCurrentchecks the git ids of the paths that decide them. This commit touches three of them,mapping.yaml,policy/manifest.yamlandpackages/guardian/src/assemble-snapshot.ts, so it re-recordsagt-go/agtbridge/testdata/ts-cases.jsonwithscripts/record-ts-cases.sh, as the agt README asks. Only those three ids change. The 49 recorded answers are the same.I ran the Go workflow's Linux amd64 job locally after the rebase:
make setupandmake checkpass, and so do the image build and its conformance probes, which I ran over a Docker network instead of a published port. I can't run the arm64 and macOS jobs here. Onintegrationat bf985ca,macos-15-intelalready fails inTestOneHandleServesParallelCalls, so that job may stay red for a reason this PR doesn't touch.This PR is independent of #521 and doesn't use what it adds. I merged the two branches locally, with #521 at 91efabf. There are 4 conflicting hunks in 2 files,
claude-code.hookmap.yamlandbuild-envelope.ts, and in each one both sides add lines next to each other. With both kept, the merged tree passesbun test(1325 pass, 0 fail) and the typecheck. Whichever PR merges second rebases, and if that's this one I'll do it.Merge danger
Door: two-way. The change is configuration plus one selection function, and a revert restores the previous behavior.
Blast radius: the AGT Claude Code host only.
settings.jsongets two Guardian round trips on every Read.proceededunderproceed,blockedunderdeny, although the output is delivered in both cases ([Conformance] Claude Code host: a Read of an image, a PDF or a notebook is delivered ungoverned, and underdenythe audit log says it was blocked #568).I tested this
uv run pytest -vpasses on my machineuv run mkdocs build --strictpasses on my machineChecklist
git commit -s(required by the DCO)Security
It closes a path where a file's text content reached the model without the Guardian seeing it. The gap was already public in #330. The live runs used AWS's documented example key, and the test fixtures use a placeholder token.