fix(tools): sandbox glob and grep to project directory #8754
+42
−32
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.
Summary
Adds path containment checks to glob and grep tools to prevent searches outside the project directory.
Problem
When an AI agent provides a path parameter that resolves outside the project directory (e.g.,
~,/Users/username, or../), the glob and grep tools would happily traverse the entire filesystem. On macOS, this triggers permission dialogs for protected directories like:~/Library~/Music~/Photos~/PicturesThis is both a security concern and a poor UX (permission dialog spam).
Solution
Mirror the existing sandboxing pattern from
bash.ts(line 88) which usesFilesystem.contains()to validate paths:Changes
Filesystemimport and containment check after path resolutionpathimport,Filesystemimport, resolve relative paths, and add containment checkTesting
Verified the logic correctly:
$HOMEdirectory../escape attemptsRelated
This fixes the same class of issue that bash tool already handles, bringing glob/grep tools to parity.