fix: resolve relative paths correctly in exec tool safety guard#2826
Open
yuxuan-7814 wants to merge 1 commit intosipeed:mainfrom
Open
fix: resolve relative paths correctly in exec tool safety guard#2826yuxuan-7814 wants to merge 1 commit intosipeed:mainfrom
yuxuan-7814 wants to merge 1 commit intosipeed:mainfrom
Conversation
Previously, relative paths in shell commands were resolved using the process's current working directory instead of the command's intended working directory. This caused legitimate relative paths (e.g., skills/file.md) to be evaluated as absolute paths from the process root, triggering false-positive safety blocks. The guardCommand method now correctly distinguishes absolute and relative paths: - Absolute paths are used as-is (cleaned) - Relative paths are joined with the command's cwd before validation This ensures relative paths are resolved relative to the intended working directory. Closes sipeed#2749
afjcjsbx
requested changes
May 8, 2026
Collaborator
afjcjsbx
left a comment
There was a problem hiding this comment.
Hi, the patch doesn't really fix relative paths. In [pkg/tools/shell.go] absolutePathPattern only matches absolute paths, so the new else branch in [pkg/tools/shell.go] is actually dead code.
Forward you are duplicating validation logic instead of reusing the shared validator in [pkg/tools/fs/filesystem.go]. No new tests on a security-sensitive change.
This was referenced May 9, 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.
📝 Description
Fix issue #2749: Bash evaluates relative path as absolute path
When the exec tool (bash) restricts access to the workspace, relative paths in commands were incorrectly resolved using the process's current working directory instead of the command's intended working directory. This caused legitimate relative paths (e.g.,
skills/file.md) to be evaluated as absolute paths from the process root, triggering false-positive safety blocks.The fix modifies the
guardCommandmethod inpkg/tools/shell.goto correctly resolve paths:cwd) before cleaning and validationThis ensures that relative paths are resolved relative to the intended working directory, not the process's global cwd.
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
Fixes #2749
📚 Technical Context (Skip for Docs)
The
absolutePathPatternregex matches paths in commands. The guard validates each matched path to ensure it stays within the workspace boundary. Previously,filepath.Abs(raw)was used for all matched paths, which is incorrect for relative paths because it uses the process's current working directory. The fix distinguishes absolute and relative paths, resolving them correctly against the command's cwd.🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
Manual verification: With workspace restriction enabled, running
execwith a relative path likecat skills/test.mdnow correctly resolves to the workspace subdirectory and is allowed, while attempts to traverse outside (cat ../../etc/passwd) remain blocked.☑️ Checklist