[Conformance] Claude Code host: a file named with `@` in the prompt reaches the model without the Guardian, and the reference Guardian does not evaluate `userMessage`

Aperta
#598 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start with the Claude Code host hook registration and hookmap, then read the reference Guardian dispatch in reference-implementations/agt/packages/guardian/src/handshake.ts and server.ts. Trace how steps/userMessage is mapped and evaluated; the issue proposes allowing or denying these messages and blocking Claude Code prompts on denial. Done means the host sends UserPromptSubmit to the Guardian and a deny prevents the prompt and referenced file from reaching the model.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

status:needs-triage type:conformance
What you ran

Claude Code 2.1.325 (claude-opus-5-5), non-interactive (-p), permission mode default, --allowedTools Read, against the reference Guardian.

  • ACS: the branch of #597 at 201ddb3, on top of integration at d3323ba. AGT Guardian, Bun 1.3.11, a Docker container, the stock manifest and the default failure posture (proceed).
  • Hooks: the settings.json from #597 (PreToolUse on ^(Bash|WebFetch|Read)$, PostToolUse on ^(Bash|Read)$), plus a probe on UserPromptSubmit that saves its own stdin. The probe ran in three variants: silent (exit 0, no output), {"decision":"block"} on stdout, and exit 2.
  • Test file: fake-secret.txt in reference-implementations/agt/, containing AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE, the example key from the AWS documentation.
  • Prompt: @fake-secret.txt Reply with only: fatto., and in one case @/tmp/fuori-progetto/fake-secret.txt Reply with only: fatto., an absolute path outside the project.
  • 3 runs per case, each with a fresh Guardian and a fresh session. I checked what reached the model in the session transcript, in the api-request-blob entries where Claude Code records the request it sent.
What you expected

docs/spec/instrument/hooks.md, userMessage:

Fires when external user input arrives, before it is presented to the agent's reasoning context.

and L132:

Decision: ALLOW / DENY / MODIFY. Guardian MAY redact content before delivery to the agent.

A file named with @ is that kind of input. Anthropic's documentation (Reference files and directories) says:

This includes the content of the file in the conversation when it fits the Read tool's token limit, 25,000 tokens by default. A text file larger than 256KB isn't included.

Your PreToolUse hooks don't run when Claude Code includes a file you reference with @, because it makes no tool call.

So I expected the file not to go through the Read hooks fixed in #597. What I wanted to know is which hook fires, what it receives, whether it can stop the file, and what the reference Guardian would do with it.

What happened
Case Hooks that fired File attached by Claude Code Key in the request to the model
Silent probe UserPromptSubmit (0) yes yes, 3 of 3
Silent probe, absolute path outside the project UserPromptSubmit (0) yes yes, 3 of 3
Probe answers {"decision":"block"} UserPromptSubmit (0) no no request sent
Probe exits 2 UserPromptSubmit (2) no no request sent
permissions.deny: ["Read(./fake-secret.txt)"], silent probe UserPromptSubmit (0) no no, the prompt went out without it
CLAUDE_CODE_DISABLE_FILE_MENTIONS=1 in the environment, silent probe UserPromptSubmit (0), then PreToolUse:Read (0), PostToolUse:Read (0) no no: the model called Read, the Guardian answered allow and then modify, and the model got [REDACTED]

In the first two cases the Guardian received nothing: no envelope, no audit entry. The file outside the project was attached and sent the same way as the one inside it.

The probe received cwd, hook_event_name, permission_mode, prompt, prompt_id, session_id and transcript_path. prompt was the raw text, @fake-secret.txt Reply with only: fatto., without the file's content. That matches the hooks reference: "UserPromptSubmit hooks receive the prompt field containing the submitted text."

With the block, the result was "UserPromptSubmit operation blocked by hook: probe block", followed by the original prompt, and the transcript had no file attachment and no request to the model. The hooks reference says "block" "stops the prompt before it reaches Claude". A hook that exits 2 blocks too, with its stderr shown as the reason.

The file misses three layers in turn, and that is why it never reaches the Guardian.

  1. Claude Code attaches the file itself, with no tool call, so PreToolUse and PostToolUse don't fire. The documentation quoted above says so, and the runs show it.
  2. The AGT Claude Code host registers only PreToolUse and PostToolUse. UserPromptSubmit fires, but nothing in the shipped settings.json or the hookmap listens to it.
  3. Even if the host sent steps/userMessage, the reference Guardian would not decide on it. It evaluates only steps/toolCallRequest and steps/toolCallResult (handshake.ts#L74), and any other method gets "method not dispatched by this Guardian" (server.ts#L944). The AGT README lists steps/userMessage as "mapped, not evaluated" (README.md#L333). And handshake.json says a client MUST treat a method the Guardian does not evaluate as "ALLOW-by-default" (handshake.json#L80).

With this input, then, the reference deployment gave the model the file's content, both for a file inside the project and for one outside it.

What a fix could do depends on what the hook allows. Apart from the block, which I measured, this part comes from the documentation and from reasoning about it.

  • UserPromptSubmit can stop the prompt and the file with it, as measured. It can't change what Claude Code attaches. The hooks reference (Decision control) lists the events that can rewrite content and says: "UserPromptSubmit: can't replace the prompt; it only injects additionalContext alongside it".
  • A Guardian that evaluates userMessage here can therefore allow or deny the whole prompt. It can't redact the file the way it redacts a Read result today. The MODIFY that hooks.md allows for userMessage has no way to reach the attachment on this host.
  • The hook sees the path, not the content. A host could decide on the path alone, the way the request gate already decides on Read's file_path. It could also read the file at that path itself and send the content, so the Guardian decides on what the file holds. Either way the outcome is a block, not a redaction.

The other route is on the Claude Code side, and it is documented. A Read deny rule keeps a path out ("Claude Code doesn't include a file that the rule matches"). CLAUDE_CODE_DISABLE_FILE_MENTIONS=1 turns the @ reference into a path that the model then reads with Read, which goes through the gates fixed in #597. That is the last row of the table. The documentation says that variable "requires Claude Code v2.1.299 or later, and Claude Code ignores it in project and local settings", so the reference implementation can't turn it on through the project settings.json it ships. I set it in the environment and didn't test it in a settings file.

What I'd propose, for discussion:

  1. The reference Guardian evaluates steps/userMessage, at least allow or deny. #229, still open, answers it with allow-by-default and records it in the session chain, which is not the same as evaluating it against policy.
  2. The Claude Code host maps UserPromptSubmit to steps/userMessage and applies a deny as a block. Bar's adapter in adapters/ already maps UserPromptSubmit to steps/turnStart and then steps/userMessage (mapping.md). I haven't measured that adapter on an @ reference.
  3. Until then, the Claude Code host README states that a file named with @ never reaches the Guardian, and points deployments to the two documented controls above.

This is not #330 or #331. #330 is the Read tool, where the host fires PreToolUse and PostToolUse and the fix is in the shim (#597). In #331, shell-mode output, no hook fires at all, so it waits on Claude Code. Here a hook fires and can block, so the gap can be closed on the ACS side.

Related: #330, #331, #597, #212 (file reads on Cursor), #184 (row D7, userMessage and agentResponse not dispatched), #229, #31, #16.

Not tested: interactive mode, a directory named with @, an MCP resource named with @server:resource, the CLAUDE.md files that an @ reference also adds to the context, a file above the size limit, runs without --allowedTools Read, the variable set in user or managed settings, and other hosts.

Current Priority Scope

Feeds the runnable Guardian reference implementation

Lingua principale
TypeScript
Stelle
183
Fork
56
Merge medio
3g 1h
PR unite (30g)
67

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di GenAI-Security-Project/agent-control-standard

Tutte le issue di GenAI-Security-Project/agent-control-standard

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.