Skip to content

fix(shell): check a Windows path written with backslashes - #5794

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/shell-backslash-paths
Oct 26, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/shell-backslash-paths

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

On Windows, a shell command that named a file with backslashes could skip the check that keeps the agent inside the folders you've approved. Now Windows paths are parsed the way cmd.exe reads them, so they are checked like any other path. Tracked privately in GHSA-5vw6-p8m4-g3j8. cc @kovtcharov-amd

Test plan

  • python -m pytest tests/unit -k shell -n 8 (5169 passed locally)
  • python util/lint.py --black --isort
  • CI green

On Windows the shell tool tokenised commands with POSIX escaping, so the
path check saw C:\Windows\win.ini as C:Windowswin.ini while cmd.exe ran
the real path. Backslashes are now literal when the step runs in cmd.exe.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

On Windows, a command that named a file with backslashes (C:\…) was read by the shell check differently from how cmd.exe runs it, so the path could slip past the approved-folders check. This PR makes the check read backslashes the way cmd.exe does, and the fix is small and correct for that case.

  • 🔒 SECURITY CONCERN: cmd.exe has a second escape character that the check still reads differently, and it may allow the same kind of slip. Worth confirming in the private advisory before closing it. @kovtcharov-amd

Real-world evidence

N/A: no evidence bundle for this run, and the change is a Windows-only parsing fix in the shell tool's guard with no CLI, API or UI surface that changes visibly. The verdict rests on static review alone. The end-to-end refusal test only runs on Windows, and I couldn't run the tests here because pytest isn't installed in this runner.

🔍 Technical details

Issues

🟡 cmd.exe caret escape still disagrees with the tokenizer (src/gaia/agents/tools/shell_tools.py:1696). With escape = "", shlex now keeps \ the way cmd.exe does. But cmd.exe strips ^ outside quotes, and shlex keeps it as data. So a token can name one path to _path_candidate_refusal and another to cmd.exe. That's the same mismatch this PR fixes, just through a different character. I haven't verified it on Windows, so I'm leaving the details for the advisory. Two possible fixes: refuse an unquoted ^ inside path-looking operands in the cmd dialect, or strip carets the way cmd.exe does before the path check. Either way, add a test next to the new parametrized ones.

🟢 Nit: one-time-approval scan still uses raw shlex.split (shell_tools.py:373, _one_time_refusal → _destroys). On Windows it still collapses C:\a\b into C:ab. The verb check isn't affected, but routing it through _tokenize would keep all the guards reading argv the same way.

Strengths

  • The fix sits at the single tokenizer every gate shares, so pipe-cutting, heredoc detection and path scanning all pick it up together. It isn't patched only in the path check.
  • echo a\|rm x moving from "refused as ambiguous" to "split, then rm refused" is a good regression test: it shows the tokenizer and _cmd_pipe_positions now agree.
  • The non-bypass branch is still exactly what shlex.split does (posix, whitespace_split, no commenters), so POSIX behaviour is unchanged.

The path check now also tests the caret-free reading of an operand in the
cmd dialect, and the one-time-approval scan splits argv with the shared
tokenizer.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Both points are addressed:

  • On Windows, the path check also tests each path the way cmd.exe reads it once ^ is dropped, and refuses if either reading leaves the approved folders. Test added.
  • The one-time approval scan now splits commands with the same tokenizer as the other checks, so a backslash path reads whole there too. Test added.

Shell unit tests pass locally (1600 passed, 53 skipped); black and isort are clean.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 26, 2026
Merged via the queue into amd:main with commit 65f5700 Oct 26, 2026
32 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/shell-backslash-paths branch October 26, 2026 10:03
@kovtcharov-amd kovtcharov-amd mentioned this pull request Oct 26, 2026
5 of 9 tasks
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 26, 2026
## Why this matters

v0.25.2 is a bug-fix release on top of v0.25.1: setup and install no
longer stop at the first failed step, shell and file access handle
Windows paths and text encodings, the Agent UI and desktop app stop
showing misleading states, and document search, email and skills each
lose a handful of rough edges. 55 commits since v0.25.1; notes are in
`docs/releases/v0.25.2.mdx` and credit 15 outside contributors.

## Test plan

- [x] `python util/validate_release_notes.py docs/releases/v0.25.2.mdx
--tag v0.25.2` passes
- [x] `mintlify validate` (from `docs/`) passes
- [x] `python util/check_doc_links.py --internal-only`, `python
util/check_doc_versions.py` and `node
installer/version/bump-ui-version.mjs --check` pass
- [x] `python util/check_component_core_api.py --release-version 0.25.2`
passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
tests/unit/test_release_tag.py
tests/unit/test_hub_core_version_gate.py`: 156 passed
- [ ] CI green on the merge commit
- [ ] `release_train_dryrun.yml` passes on that commit before the RC tag

## Evals to re-run on the RC tag

LLM-affecting PRs merged without per-PR evals; run these on
`v0.25.2-rc1`:

- `gaia_shell` and shell/safety (amd#5794, amd#5751, amd#5768)
- `gaia_honesty` (amd#5753)
- `gaia_skills_tasks` and `gaia_skills_lifecycle` (amd#5422, amd#5755)
- `rag_retrieval` and `rag_quality` (amd#5742, amd#5754, amd#5761, amd#5817, amd#5812)
- email scenarios (amd#5767, amd#5811)
- `tool_selection` and `error_recovery` (amd#5732)
- Claude provider thinking replay (amd#5072)
- memory categories (amd#5818 merged; amd#5756 has not)

## Release checklist

- [ ] Freeze main, wait for green CI on the exact commit, pass
`release_train_dryrun.yml`, then push `v0.25.2-rc1`
- [ ] Extend the changelog if main gains commits before the tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants