fix: prevent safety guard from blocking relative paths in exec tool

This commit is contained in:
Re-bin 2026-02-10 07:39:15 +00:00
parent caf7a1a532
commit 8626caff74

View File

@ -128,14 +128,17 @@ class ExecTool(Tool):
cwd_path = Path(cwd).resolve() cwd_path = Path(cwd).resolve()
win_paths = re.findall(r"[A-Za-z]:\\[^\\\"']+", cmd) win_paths = re.findall(r"[A-Za-z]:\\[^\\\"']+", cmd)
posix_paths = re.findall(r"/[^\s\"']+", cmd) # Only match absolute paths — avoid false positives on relative
# paths like ".venv/bin/python" where "/bin/python" would be
# incorrectly extracted by the old pattern.
posix_paths = re.findall(r"(?:^|[\s|>])(/[^\s\"'>]+)", cmd)
for raw in win_paths + posix_paths: for raw in win_paths + posix_paths:
try: try:
p = Path(raw).resolve() p = Path(raw.strip()).resolve()
except Exception: except Exception:
continue continue
if cwd_path not in p.parents and p != cwd_path: if p.is_absolute() and cwd_path not in p.parents and p != cwd_path:
return "Error: Command blocked by safety guard (path outside working dir)" return "Error: Command blocked by safety guard (path outside working dir)"
return None return None