Repository navigation
feat(permissions): ask before the file tools read or write outside the project - #316
Merged
Merged
Conversation
read_files, list_files, search_files, glob_files, view_images and view_documents refused any path leaving the project (absolute, `..`, or a symlink), whatever the permission tier. They now ask the user instead, once per call for all such paths: allow once, always for the session, or deny. A session grant covers all of these tools. Where no frontend can ask, the access is still rejected. Tools reach the session's ToolPermissions through ToolContext, and ToolContext::request_escalation asks for and remembers such grants.
write_file, edit, replace_in_file and delete_files refused any path leaving the project. Like the reading tools, they now ask the user instead. Reads and writes are asked and granted separately: the permission reason is now OutsideProject with a FileAccess of Read or Write, and a session grant for reads does not allow writes. Files written outside the project get no format-on-save (its command runs in the project) and no resource events.
Address review findings on the outside-project permission: - Tools use the path resolved before the question, so a symlink changed while it is open cannot redirect the access (resolve_and_approve) - search_files asks before it says whether an outside path exists - Absolute glob patterns inside the project match; the literal base is split by path components, so Windows separators work - Absolute paths inside the project are made relative for format-on-save and resource events - Outside explorers come from explorer_for everywhere; read_files no longer resolves paths again for its resource events - Parallel calls ask one after another, so an "always" answer covers the calls waiting behind it
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.
Summary
The file tools refused every path that leaves the project (absolute,
.., or through a symlink), whatever the permission tier. Now they ask the user instead.read_files,list_files,search_files,glob_files,view_images,view_documents) and writing (write_file,edit,replace_in_file,delete_files) ask before they reach such a path. Each call asks once, covering all of its outside paths: allow once, always (session) or deny.bypass-allincluded. Reads and writes are asked and granted separately: the reason isPermissionRequestReason::OutsideProjectwith aFileAccessofReadorWrite, and a session grant for reads does not allow writes.ToolPermissions. Tools reach it throughToolContext::request_escalation.read_filesrecords what it saw for outside files too.Shared helper:
tools::impls::outside_project. Docs:docs/permission-tiers.md.Test plan
cargo test,cargo clippy --all-targets --all-features -- -D warnings,cargo fmt --check