fix(tools): prevent filesystem tools from escaping workDir#75
Draft
danielebarbaro wants to merge 1 commit into
Draft
fix(tools): prevent filesystem tools from escaping workDir#75danielebarbaro wants to merge 1 commit into
danielebarbaro wants to merge 1 commit into
Conversation
pachecocordovamoiseseduardo-byte
approved these changes
Apr 22, 2026
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.
All filesystem tools (list_files, read_file, write_file, update_file) use a shared helper called resolvePath.
Before this change, it returned absolute paths as-is and joined relative paths without checking that they stayed within the intended directory.
As a result, the agent could access or write files outside the allowed scope (e.g., /etc/hosts or /tmp/pwn.txt), despite the README claiming it was “safe by design.”
Change
resolvePathnow returns(string, error).workDirand the target viafilepath.EvalSymlinks, then verifies containment viafilepath.Rel.canonicalPath, which walks up to the nearest existing ancestor, resolves its symlinks, and re-appends the non-existent tail. This keepswrite_fileworking for new files and new parent directories.path "/etc/passwd" escapes working directory.Rejected
workDir(e.g./etc/hosts)..(e.g.../../etc/hosts)workDirthat point outsideStill allowed
workDirworkDirwrite_file