fix: enforce workspace boundary for file tools - #114
Merged
shauryagangrade merged 1 commit intoAug 29, 2026
Conversation
… workspace-aware tests
shauryagangrade
force-pushed
the
feat-workspace-boundary-57
branch
from
August 29, 2026 16:50
aace718 to
a561e73
Compare
shauryagangrade
marked this pull request as ready for review
August 29, 2026 16:50
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