fix: enforce workspace boundary for file tools - #114
Draft
aryansk wants to merge 1 commit into
Draft
Conversation
Fixes shauryagangrade#57 File tools (read_file, write_file, edit_file, list_dir) operated on arbitrary paths with no check that they stay inside the project workspace. A model with a bad prompt could read or overwrite anything. Define workspace root as the session cwd (honors --cwd) and check each path via Path.resolve() (handles .., absolute paths, and symlinks). For paths outside the workspace, reuse the existing y/n permission gate (and non-interactive EOF handling) from execute_bash: prompt "Path ... outside workspace ... Allow? (y/n)"; in non-interactive mode reject unless --yes/AUTO_APPROVE, mirroring execute_bash. In-workspace paths proceed unchanged. Validation: py_compile passes, git diff --check clean; boundary helper handles symlink/.. via resolve() and is_relative_to.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #57
Problem
read_file,write_file,edit_file, andlist_diroperate on arbitrary paths (os.path,open(...)) with no check that they stay inside the project/workspace directory. A model with a bad prompt — or a malicious session — can read or overwrite anything the user can on the machine, with onlywrite_file's force flag as a mild guard.Issue #57 proposes defining a "workspace root" (the
--cwd/ session cwd) and requiring explicit confirmation or rejection for paths resolving outside it, handling symlinks/..viaPath.resolve().Change
gcode/tools.py:_workspace_root()(session cwd viaPath(os.getcwd()).resolve(), honors--cwd),_is_within_workspace(path)(viaPath.resolve()+is_relative_to, handles.., absolute paths, symlinks), and_check_workspace_boundary(path)(returns error string if outside and not confirmed)read_file,write_file,edit_file,list_dir: if_check_workspace_boundaryreturns error, return it; otherwise proceed. For outside paths, reuse the existingexecute_bashy/n gate: promptPath '...' is outside workspace '...'. Allow? (y/n):; in non-interactive mode (EOF) reject unlessAUTO_APPROVE(--yes), mirroringexecute_bashnon-tty handlingWhy this approach
Reuses the existing permission-gate pattern from
_run_tool/execute_bash, so the UX is consistent: interactive users get a y/n prompt for outside access, CI/non-tty gets a safe rejection unless--yes.Path.resolve()correctly handles..and symlinks, andis_relative_tois the stdlib way to test containment.Testing
Documentation and release impact
Review notes