Skip to content

Govern Read in the Claude Code host - #597

Merged
rocklambros merged 2 commits into
GenAI-Security-Project:integrationfrom
MK023:refimpl/claude-code-read
Nov 26, 2026
Merged

rocklambros merged 2 commits into
GenAI-Security-Project:integrationfrom
MK023:refimpl/claude-code-read

Conversation

@MK023

@MK023 MK023 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The Claude Code host in reference-implementations/agt governs 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 its file_path and through the result gate on file.content, and a redaction comes back in Read's own output shape.

 # hosts/claude-code/settings.json
-PreToolUse   "^(Bash|WebFetch)$"
+PreToolUse   "^(Bash|WebFetch|Read)$"
-PostToolUse  "^Bash$"
+PostToolUse  "^(Bash|Read)$"

 # mapping.yaml, policy_target_argument.by_tool
+Read: file_path

 # policy/manifest.yaml
+Read: {type: Tool, id: Read, security_labels: [shell]}

 # hosts/claude-code/claude-code.hookmap.yaml, PostToolUse
 outputs:
   from: $.tool_response.stdout
   within: $.tool_response
+  by_tool:
+    Read:
+      from: $.tool_response.file.content
+      within: $.tool_response

outputs.by_tool works like policy_target_argument: from and within are the default, and a listed tool uses its own pair and inherits nothing from the default. In packages/host-adapter, outputsFor picks the pair, and both buildPayload and governStep call it, so a replacement is written into the same leaf that went to the Guardian. loadHookmap rejects a malformed by_tool entry. Bash keeps its path, and OpenCode's single outputs path loads as before.

Which issue does this implement

Closes #330

Base branch

  • integration, because this touches the specification, schemas, a reference
    implementation, an adapter, tests, or CI
  • main, because every changed path is on the documentation lane allowlist in
    CONTRIBUTING.md

Type of change

  • Specification change (schema, hooks, events, AgBOM)
  • Reference implementation or adapter
  • Documentation
  • Tooling or CI
  • Governance (licensing, security policy, contributor docs)

Evidence

Before, on Claude Code 2.1.316 against integration (my 2 Nov comment on #330, 3 runs out of 3):

  • With Read in both matchers, the request is denied with evaluation_failed.
  • With Read only in the PostToolUse matcher, the model gets the example key in plaintext.

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:

Case Hooks Guardian What the model got
Read of a text file Pre 0, Post 0 allow, then modify [REDACTED] in place of the key
Same file read twice Pre 0, Post 0, twice allow, then modify, twice [REDACTED] both times
Read with offset and limit Pre 0, Post 0 allow, then modify [REDACTED]
cat of the same file through Bash Pre 0, Post 0 allow, then modify [REDACTED]

I also ran it once interactively, in the default permission mode, and got the same result.

bun test in reference-implementations/agt goes from 1285 to 1292 passing, with 4 skipped and 0 failing, and bun run typecheck exits 0. Each new case failed against integration before the code went in:

  • At the result gate, through the real shim, a modify redacts the secret out of file.content and keeps every sibling field. A deny withholds it the same way, and an allow leaves the file alone and writes no audit entry.
  • At the request gate, a Read is allowed and evaluated on file_path.
  • loadHookmap refuses a malformed by_tool entry in three shapes.

Scope and deviations from the 2 Nov scope

The Go Guardian from #169 replays answers recorded from this Guardian, and TestRecordingIsCurrent checks the git ids of the paths that decide them. This commit touches three of them, mapping.yaml, policy/manifest.yaml and packages/guardian/src/assemble-snapshot.ts, so it re-records agt-go/agtbridge/testdata/ts-cases.json with scripts/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 setup and make check pass, 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. On integration at bf985ca, macos-15-intel already fails in TestOneHandleServesParallelCalls, 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.yaml and build-envelope.ts, and in each one both sides add lines next to each other. With both kept, the merged tree passes bun 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.

I tested this

  • I synced my branch with the base branch before opening this
  • uv run pytest -v passes on my machine
  • uv run mkdocs build --strict passes on my machine

Checklist

  • Commits are signed off with git commit -s (required by the DCO)
  • Prose follows STYLE.md
  • No secrets, tokens, or internal URLs in the diff

Security

  • This change has no security impact

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.

@github-actions

Copy link
Copy Markdown

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.

@MK023

MK023 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@almogbhl the PR for #330 is up. It covers text only, as we agreed: images, PDFs and notebooks stay with #568, where the audit log fix comes next. The body has the live measurements on Claude Code 2.1.325 and the local merge with #521.

@drk-ram drk-ram left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / outputsFor in build-envelope.ts and govern-step.ts): Resolving outputs.by_tool[tool] through a single outputsFor(entry, payload) helper used by both buildPayload and governStep ensures Read extracts and patches $.tool_response.file.content inside $.tool_response.file without inheriting Bash's stdout/stderr paths.
  • Load-time validation (assertByToolWellFormed): Verifying at loadHookmap time that each by_tool entry declares only {from, within} with from strictly inside within prevents 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>
@MK023
MK023 force-pushed the refimpl/claude-code-read branch from 201ddb3 to 0b78a14 Compare November 18, 2026 09:33
@MK023

MK023 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

I rebased this onto integration at bf985ca, now at 0b78a14. #169 landed after the approval, and its Go parity test failed on any PR that touches mapping.yaml, policy or packages/guardian/src until the recording was refreshed.

The only change from 201ddb3, the commit @drk-ram approved, is agt-go/agtbridge/testdata/ts-cases.json. It now has the new git ids of those three paths, recorded with scripts/record-ts-cases.sh. The 49 recorded answers are the same, and git range-diff shows nothing else.

@drk-ram drk-ram left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@almogbhl

Copy link
Copy Markdown
Collaborator

Thanks @MK023, great work, and the live runs make this easy to trust.

Non-blocking, for after merge:

  • The stock policy is small. The request gate's only rule is rm -rf /, so every Read is allowed, and redaction catches only ghp_ and AKIA keys. A .env password or a private key still reaches the model. Worth one line in the Claude Code README, so nobody reads "Read is governed" as "reading files is safe".
  • Grep returns file lines too, so it's the next path with the same leak (Track the dogfooding scenarios no run has covered #434 item 7).
  • Looking forward to the @-mention issue you mentioned.

almogbhl
almogbhl previously approved these changes Nov 19, 2026
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>
@MK023

MK023 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@almogbhl thanks for the review.

The @-mention issue is #598. A file named with @ in the prompt reaches the model without the Guardian, and the reference Guardian does not evaluate userMessage either. I've updated the line in this PR's body that still said I would open it.

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 integration and conflicted with this PR in one sentence of reference-implementations/agt/README.md. The quick start now names Read in both matchers and keeps the onFailure note from #462. I merged integration into the branch instead of rebasing, so the reviewed commit stays as it was (0b78a14), and the merge is 8a35bb2. Against integration, the PR diff is the same as before except for that sentence. The recording in ts-cases.json is still current, because #462, #599, #600 and #602 touch none of the paths it pins.

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. bun test gives 1302 pass, 4 skip and 0 fail, and the typecheck is clean. pytest passes 1238 tests, and mkdocs build --strict builds the docs. In the Go workflow, make setup and make check pass, the pure Go build and tests pass, and so do the image build and its conformance probes.

@bar-capsule bar-capsule left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 8a35bb2. The merge keeps #462's onFailure: block on the PreToolUse hook, so a crashing hook now blocks a Read too.

@drk-ram drk-ram left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the merge commit 8a35bb2 in reference-implementations/agt/README.md. Naming Read alongside Bash in both PreToolUse and PostToolUse matchers while preserving the onFailure note from #462 looks clean. LGTM.

@MK023

MK023 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@bar-capsule thanks for the approval at 8a35bb2. The PR is clean against integration. Is anything still needed from me before it merges? #615 and the notebook change for #568 are stacked on it, so I'll realign them once this is in.

@MK023

MK023 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@bar-capsule, #355 and #521 change some of the same files as this PR: govern-step.ts for #355, claude-code.hookmap.yaml and build-envelope.ts for #521. Whichever lands second will need its conflicts resolved. If that is #597, I will update it the same day.

@rocklambros
rocklambros merged commit ac31e8a into GenAI-Security-Project:integration Nov 26, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from Needs triage to Done in ACS Project Tracker Nov 26, 2026
rocklambros added a commit that referenced this pull request Nov 26, 2026
Carries PR #597 (Govern Read in the Claude Code host) to release/0.2.

Signed-off-by: Rock Lambros <rock@rockcyber.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Conformance] Claude Code host: Read bypasses the Guardian, so a secret that the Bash path redacts reaches the model in plaintext

5 participants