Fix symlink sandbox escape in fs path resolver (#47)#57
Draft
TYRMars wants to merge 1 commit into
Draft
Conversation
resolve_under was purely lexical: it rejected absolute paths and ".." components but never resolved symlinks, so a symlink living inside JARVIS_FS_ROOT but pointing outside it was followed transparently. Because the read-side tools (fs.read / fs.list / code.grep) are not approval-gated, this was a no-prompt host-file read path. Canonicalize both the root and the candidate's longest existing prefix (re-appending any not-yet-created tail, which cannot be a symlink) and reject paths that no longer start with the canonical root. Returns the lexical join on success so callers' write targets are unchanged. Fixes #47
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
Fixes #47.
resolve_under(the shared path sandbox used byfs.*,code.grep, andfs.patch) was purely lexical: it rejected absolute paths and..components but never resolved symlinks. A symlink that lives insideJARVIS_FS_ROOTbut points outside it was followed transparently, escaping the sandbox. Because the read-side tools (fs.read/fs.list/code.grep) are not approval-gated, this was a no-prompt host-file read path (e.g. an attacker-plantedlink -> /etcin a dependency checkout the agent merely reads).Fix
After the existing lexical checks and
root.join(rel):fs.writecreating a new file), so canonicalize the longest existing prefix and re-append the not-yet-created tail — those trailing components don't exist on disk and therefore can't be symlinks.starts_withthe canonical root./tmp→/private/tmprewrites on macOS).This matches the canonicalization already done by
shell.rs/workspace.rs.Tests
Added to
sandbox.rs:rejects_symlink_inside_root_pointing_outside— symlink → existing file, → not-yet-existing path, and the symlink dir itself all rejected.accepts_symlink_inside_root_pointing_inside— intra-root symlink still works.accepts_real_nested_path_under_existing_root— sanity for the canonicalize path.cargo test -p harness-tools sandbox::andcargo clippy -p harness-tools --all-targets -- -D warningsare green.Generated by Claude Code