Skip to content

The agent that grows with you

fix(file-tools): gate ~/.ssh/config writes on the task-resolved path

teknium10f6b5c33d4ee
diff --git a/tests/tools/test_file_tools.py b/tests/tools/test_file_tools.py
index 9988a64dc81..b3595c62136 100644
--- a/tests/tools/test_file_tools.py
+++ b/tests/tools/test_file_tools.py
@@ -918,6 +918,20 @@ class TestSSHConfigWriteGate:
assert "single-query" in result["error"]
assert not ssh_config.exists()
+ def test_relative_path_is_gated_from_the_task_cwd_not_the_process_cwd(self, ssh_config, tmp_path,
+ monkeypatch):
+ """A gateway-hosted turn's workspace is not the process cwd: the gate must judge the path
+ the write will actually land on, or a relative spelling skips approval."""
+ ws, elsewhere = tmp_path / "ws", tmp_path / "elsewhere"
+ for d in (ws, elsewhere, ssh_config.parent):
+ d.mkdir()
+ (ws / "sshdir").symlink_to(ssh_config.parent, target_is_directory=True)
+ monkeypatch.setenv("TERMINAL_CWD", str(ws))
+ monkeypatch.chdir(elsewhere)
+ from tools.file_tools_write_guards import _check_approval_required_write
+
+ assert "BLOCKED" in (_check_approval_required_write(["sshdir/config"], "ssh-gate-task") or "")
+
class TestSecretFileReadRedaction:
"""#110567: read_file / search_files must classify the RESOLVED path and run the
diff --git a/tools/file_tools_write_guards.py b/tools/file_tools_write_guards.py
index 59f8e1c4677..f7cfa3c2d8e 100644
--- a/tools/file_tools_write_guards.py
+++ b/tools/file_tools_write_guards.py
@@ -353,7 +353,9 @@ def _check_approval_required_write(paths: list[str], task_id: str = "default") -
except Exception:
return None
- targets = [p for p in paths if is_write_approval_required(p)]
+ # Resolve against the task's cwd, not the process's: a gateway-hosted turn runs in a
+ # process whose cwd is not the session workspace, so a relative path would miss the gate.
+ targets = [p for p in paths if is_write_approval_required(_resolved_or_raw(p, task_id))]
if not targets:
return None