fix(exec): reject shell paths with unresolved home directories

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-15 09:51:53 +08:00
1 parent af6abde2f4
commit 1d43b46e54
2 files changed
+69 -1

No files matched your search

+9 -1
View File
@@ -897,7 +897,15 @@ class ExecTool(Tool):
+ _WORKSPACE_BOUNDARY_NOTE
)
else:
p = Path(expanded).expanduser().resolve()
try:
home_path = Path(expanded).expanduser()
except RuntimeError:
return ToolResult.error(
"Error: Command blocked by safety guard "
"(path outside working dir)"
+ _WORKSPACE_BOUNDARY_NOTE
)
p = home_path.resolve()
# Match against the un-resolved path first. On Linux,
# /dev/stderr is a symlink to /proc/self/fd/2 and
# ``Path.resolve()`` would mask the device-file intent.