Repository navigation
feat(sandbox): add user-configurable read-only paths #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EZotoff
wants to merge
3
commits into
spacedriveapp:main
Choose a base branch
from
EZotoff:feat/read-only-sandbox-paths
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -28,13 +28,7 @@ impl FileContext { | |||||
| Self { workspace, sandbox } | ||||||
| } | ||||||
|
|
||||||
| /// Resolve and validate a path. | ||||||
| /// | ||||||
| /// Relative paths are resolved against the workspace root. When sandbox mode | ||||||
| /// is enabled, absolute paths must fall within the workspace and symlink | ||||||
| /// traversal is blocked. When sandbox is disabled, any readable/writable | ||||||
| /// path is accepted. | ||||||
| fn resolve_path(&self, raw: &str) -> Result<PathBuf, FileError> { | ||||||
| fn resolve_path_inner(&self, raw: &str, require_writable: bool) -> Result<PathBuf, FileError> { | ||||||
| let path = Path::new(raw); | ||||||
| let resolved = if path.is_absolute() { | ||||||
| path.to_path_buf() | ||||||
|
|
@@ -62,6 +56,12 @@ impl FileContext { | |||||
| ))); | ||||||
| } | ||||||
|
|
||||||
| if require_writable && !self.sandbox.is_path_writable(&canonical) { | ||||||
| return Err(FileError( | ||||||
| "ACCESS DENIED: This path is mounted as read-only. You can read files here but cannot write or edit them.".to_string(), | ||||||
| )); | ||||||
| } | ||||||
|
|
||||||
| let workspace_canonical = self | ||||||
| .workspace | ||||||
| .canonicalize() | ||||||
|
|
@@ -90,6 +90,14 @@ impl FileContext { | |||||
| Ok(canonical) | ||||||
| } | ||||||
|
|
||||||
| fn resolve_path(&self, raw: &str) -> Result<PathBuf, FileError> { | ||||||
| self.resolve_path_inner(raw, false) | ||||||
| } | ||||||
|
|
||||||
| fn resolve_writable_path(&self, raw: &str) -> Result<PathBuf, FileError> { | ||||||
| self.resolve_path_inner(raw, true) | ||||||
| } | ||||||
|
EZotoff marked this conversation as resolved.
Resolved
|
||||||
|
|
||||||
| // NOTE: Identity file protection (PROTECTED_FILES) has been removed. | ||||||
| // Identity files (SOUL.md, IDENTITY.md, ROLE.md) now live in the agent | ||||||
| // root directory, outside the workspace sandbox boundary. The sandbox | ||||||
|
|
@@ -218,7 +226,7 @@ impl Tool for FileReadTool { | |||||
| } | ||||||
|
|
||||||
| async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> { | ||||||
| let path = self.context.resolve_path(&args.path)?; | ||||||
| let path = self.context.resolve_writable_path(&args.path)?; | ||||||
|
||||||
| let path = self.context.resolve_writable_path(&args.path)?; | |
| let path = self.context.resolve_readable_path(&args.path)?; |
coderabbitai[bot] marked this conversation as resolved.
Resolved
coderabbitai[bot] marked this conversation as resolved.
Resolved
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.
Uh oh!
There was an error while loading. Please reload this page.