Skip to content

fix(shell): read a generated image with a quoted path, type or PowerShell - #8749

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/fix-8702-shell-read-generated-images
Nov 22, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/fix-8702-shell-read-generated-images

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

On Windows the agent couldn't look at an image it had just generated from the shell unless the path was unquoted and the command was cat, dir, ls or wc. Paths with spaces need quotes, so the forms a model actually uses (dir "…png", type, PowerShell Get-Item '…') were refused, and the refusal said "Write blocked" for what was a read. Those reads now get the same answer they would get for a file in an allowed folder. Writes, deletes and every other file in GAIA's state folder stay refused, and a refused read now says why without calling it a write.

Closes #8702

This also fixes item 2 of #8697: the spreadsheet tool's refusal for C:\Windows\win.ini said "Write blocked". It came from the same place, so it now reads "No approval can grant it: 'C:\Windows\win.ini' is inside protected directory 'C:\windows'."

Test plan

  • python -m pytest tests/unit/test_generated_images_readable.py: the new cases fail on main and pass here. Covered: quoted and unquoted cat/ls/wc/file/dir/more, type, certutil -hashfile, and PowerShell Get-Item/Get-FileHash/Get-Content/Test-Path, each compared with the same line on a file in an allowed folder. Writes, deletes, renames, redirects, PowerShell Remove-Item/Set-Content/Copy-Item, piped or chained PowerShell, and quoted reads of other state files all stay refused. No read refusal contains "Write blocked", and the write refusal still does.
  • All shell-gate, security, write-guardrail and code-screen unit test files
  • PowerShell lines that run a command named by a string (& 'Remove-Item', '…' | iex, [scriptblock]::Create, . 'x.ps1') get the same verdict as on main
  • python util/lint.py --black --isort
  • Manual on Windows: generate an image, then ask the agent to show its size with dir "<path>" and its hash with PowerShell Get-FileHash '<path>'
🔍 Technical details
  • The generated-image allowance (fix(security): let the agent read the images GAIA generated #8478) applies only when the whole line reads. That check (_line_is_read_only) rejects any cmd.exe line with a quote, every PowerShell line, and type. A new windows_reads mode, used only for this allowance, also accepts:
    • double-quoted plain words (not single quotes, which cmd.exe passes to the program unchanged, and not \");
    • type <file> and certutil -hashfile <file> [alg];
    • a PowerShell line that is exactly one read cmdlet on single-quoted literal paths, optionally (…).Property but never a method call.
  • Command policy is unchanged. type and certutil still ask or refuse as they do for any folder; this only stops the path itself from being the reason.
  • The PowerShell code screen now runs read-only when the line only reads, so it no longer applies the write protections to a read.
  • The cmdlet check skips single-quoted strings. A ' inside a double-quoted string opens nothing, and a body with a backtick, non-ASCII quotes or an unclosed quote is checked whole, as before.
  • is_write_blocked now builds its message from a neutral reason plus write-only advice. _unaskable_reason, behind every "No approval can grant it", uses only the reason. The text of is_write_blocked is unchanged.
  • Agent evals: this changes which shell lines run, not prompts or tool schemas. Worth watching gaia_files on the next RC.

…hell

On Windows the agent could read an image it had just generated only with
an unquoted `cat`, `dir`, `ls` or `wc`. Quoted paths, which any path with
a space needs, and `type`, `certutil -hashfile` and PowerShell reads were
refused as a protected folder, worded as a blocked write. They now get
the same verdict as the same read of a file in an allowed folder.
Writes, deletes, renames and every other file in GAIA's state folder
stay refused.

PowerShell reads of generated images were also refused because every
generated name holds "SDXL-Turbo", which the cmdlet check read as a
cmdlet. Single-quoted strings, which PowerShell never runs, are no
longer searched for cmdlets.

A refused read is no longer described as "Write blocked": the reason now
names what the path is ("inside protected directory ..."). This also
fixes the spreadsheet tool's message for C:\Windows\win.ini (item 2 of
amd#8697). The write tools' wording is unchanged.

Closes amd#8702
@github-actions github-actions Bot added documentation Documentation changes tests Test changes security Security-sensitive changes agents labels Nov 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

On Windows the agent can now read an image it generated, with quoted paths, type, certutil -hashfile or one PowerShell read cmdlet. A refused read also stops saying "Write blocked". The image allowance is narrow and well tested. One change reaches further than the image case and opens a gap that has to close before merge.

🔒 SECURITY CONCERN: hiding single-quoted text from the PowerShell read-only check lets some lines that write a file run without asking, where main asked first. @kovtcharov-amd, please take a look. Details are below and kept general.

  • What to do: keep hiding quoted file names from the cmdlet check, but treat any line that could run a command named by a quoted string as uninspectable, in every position and not only at the start of the line. Add a test that fails on this branch today.

Real-world evidence

N/A. No evidence bundle was produced, and the changed surface (cmd.exe and PowerShell on Windows) can't run on this Linux runner. The unit tests weren't run in this job either, because the Python dependencies aren't installed. This verdict rests on static review alone. The PR's own manual Windows check (dir "<path>", Get-FileHash '<path>') is still unchecked.

🔍 Technical details

🔴 Single-quoted literals are hidden from the cmdlet allowlist for every PowerShell line, not just image reads (src/gaia/agents/tools/shell_tools.py:8340)

_ps_code_outside_literals(ps_cmd) now feeds both the per-segment head check and the re.findall(r"[a-z]+-[a-z]+", …) sweep inside _validate_command. That sweep was the only thing that saw a cmdlet name sitting inside a single-quoted string. Two other guards still read the full body:

  • DANGEROUS_PS_PATTERNS lists remove-, set- and similar, but not every writing cmdlet. The out-* / tee-* family is missing, for example.
  • _PS_BODY_ESCAPES catches &, and catches dot-invocation only at the start of the body or right after a |.

So a string-named command invoked by dot-invocation inside a subexpression or a script block, with a cmdlet that isn't on the dangerous list, no longer trips anything. main returned TIER_CONFIRM for it. This branch returns no refusal, so it runs unasked. The PR's "same verdict as main" cases all put the call operator at command position, which is why they still pass.

The smallest fix is to treat dot-invocation of a quoted name as uninspectable wherever it appears:

    (re.compile(r"(?:^|\|)\s*\.\s+"), "dot-sourcing (. script.ps1)"),
    (
        re.compile(r"(?:^|[\s|({;])\.\s*['\"]"),
        "running a command named by a string (. 'name')",
    ),

(at shell_tools.py:1544). Then add a test_a_cmdlet_outside_single_quotes_is_still_seen case where the dot call sits inside ( … ) and inside { … }. A sturdier alternative is to blank a literal only when it is in argument position, meaning a parameter value or a positional path, and never right after ., &, ( or {.

🟢 Write refusals reached through "No approval can grant it" lose their advice (src/gaia/security.py:1570)

_unaskable_reason now returns only why, so a refused write to, for example, a credential folder no longer ends with "Edit it yourself if you need to." That's fine for reads. For writes it drops the one line that tells the user what to do. If that's intended, ignore this.

Checked and fine

  • is_write_blocked output is byte-identical for every branch. completion.py's "Write blocked:" marker and the existing tests that assert on it still match.
  • The _POWERSHELL_READ fast path is a fullmatch over literal-only paths (no $, backtick, ; or call parentheses), and windows_reads is used only for media_reads. Command policy is unchanged, as the PR says.
  • may_write=not reads_only still applies every read-block. Only the write-only protections drop, and only for a line already proven read-only.
  • _CMD_QUOTED_LINE rejects any \", so GAIA and CommandLineToArgvW can't split a backslash-quote differently. Redirects can't match the character class.
  • Docs: docs/sdk/security.mdx is updated. No other doc describes the old "unquoted only" rule.

Strengths

  • Each read case is checked against the same command on a file in an allowed folder, so the tests prove the image path isn't the reason for a refusal, not just that something passed.
  • Splitting _write_block into a neutral reason plus write-only advice fixes the misleading "Write blocked" on reads (Wording and display: blocked commands, raw ids and error text (v0.27.0-rc4 sweep) #8697 item 2) without changing any write message.
  • The broad set of negative tests (deletes, renames, redirects, chained and piped PowerShell, curly quotes, backticks) is the right shape. It's missing only the subexpression case above.

Hiding single-quoted text from the PowerShell cmdlet check let a line
that dot-calls a string-named command inside ( ) or { } run unasked
where main asked. Dot-invocation of a quoted or bracketed name, and a
method named by a quoted string, now count as code the allowlist cannot
inspect, wherever they sit in the line.
@kovtcharov-amd
kovtcharov-amd merged commit 6072d12 into amd:main Nov 22, 2026
39 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes security Security-sensitive changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: the agent can't read its own generated image from the shell when the path is quoted

2 participants