[Bug] git_diff passes "base" to git unchecked, so --output=<file> lets a read-only tool write files
Description
git_diff appends the model-supplied base value to the git command line. A value like --output=<path> makes git write the diff to that path. git_diff is marked readOnly and has no approval rule, so it runs without asking. git_log already blocks this (source/tools/git/git-log.tsx:37); git_diff does not.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at f92cce9c)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
- Create a git repo with one modified file.
- From that folder run the built tool (from
dist/tools/git/git-diff.js):await gitDiffTool.tool.execute({base: '--output=<absolute path outside the repo>/outside.txt'}, {toolCallId: 'x', messages: []}) - Look for the file.
Expected Behavior
The call is rejected, for example Error: Invalid base: --output=.... No file is created.
Actual Behavior
The tool answers "No differences with --output=..." and the file outside the repo exists and contains the full patch. A prompt injection (or a model mistake) can overwrite any file the user can write, with no approval prompt.
Logs/Screenshots
No differences with --output=C:/Users/.../tmp.zYPgDofmuS/outside.txt
outside.txt now exists:
diff --git a/f.txt b/f.txt
index 5626abf..f719efd 100644
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/tools/git/git-diff.tsx:43(if (args.base) gitArgs.push(args.base)): reject values that start with-, likegit-log.tsx:37does. Better, put--end-of-optionsbefore the revision, or validate it as a ref name.- Review every other model-controlled value in the
git_*tools the same way. source/tools/approval-policy.ts:82treatsreadOnlytools as safe to run unattended, which is why this skips approval.- Add tests with
baseset to--output=...and--ext-diff.
Related: #1933 / PR #1945 (git_add without --).
I'd like to take this one and will fix it following the suggested approach .