HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
session files: a put refuses the base's own protected machinery, as delete, mkdir and move do (#553)
Rudy Mizrahi Celekli58d10bf3b0ff
diff --git a/gateway/app.py b/gateway/app.pyindex c4b79851..5e037d78 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -11914,10 +11914,12 @@ async def write_session_file(sid: str, path: str, body: WorkspaceWrite, request:if ok:_ws_changed(sid)if not ok:- # The only ways to get here are a path that tried to leave the workspace and a storage- # failure. Both are the caller's problem to see, not something to swallow.+ # A path that tried to leave the workspace, one of the agent's own files (the runner refuses+ # those as it does for delete, mkdir and move), or a storage failure. All are the caller's+ # problem to see, not something to swallow, and the answer names both path rules.raise uhp_error(400, "write_failed",- "Could not write that path. It must be inside the session workspace.")+ "Could not write that path. It must be inside the session workspace, and not "+ "one of the agent's own files.")return {"session_id": sid, "path": path, "bytes": len(data), "written": True}diff --git a/gateway/tests/test_session_file_changes.py b/gateway/tests/test_session_file_changes.pyindex e3bfb61c..a2ced7b4 100644--- a/gateway/tests/test_session_file_changes.py+++ b/gateway/tests/test_session_file_changes.py@@ -393,6 +393,10 @@ class _Fake:self.calls.append(("mkdir", path))return self.outcome+ async def write(self, sid, path, data):+ self.calls.append(("write", path))+ return self.outcome == B.WS_OK+async def move(self, sid, path, to):self.calls.append(("move", path, to))return self.outcome@@ -456,6 +460,19 @@ async def test_routes_refuse_escapes_and_internal_paths(routes, path):assert routes["fake"].calls == []+async def test_a_put_the_runner_refuses_says_which_paths_it_may_write(routes):+ """The runner refuses a PUT to the base's own machinery as it refuses delete, mkdir and move, and the+ backing answers that as a failed write: the answer names that rule beside the workspace rule, so a+ caller writing AGENTS.md on a base that keeps it is not told the path left the workspace."""+ routes["fake"].outcome = B.WS_BAD_PATH+ with pytest.raises(Exception) as e:+ await A.write_session_file("s", "AGENTS.md", A.WorkspaceWrite(content="x"), request=None)+ assert e.value.status_code == 400 and e.value.detail["code"] == "write_failed"+ assert "not one of the agent's own files" in e.value.detail["message"]+ assert routes["fake"].calls == [("write", "AGENTS.md")] and "changed" not in routes++@pytest.mark.asyncioasync def test_a_leading_slash_names_the_same_workspace_path(routes):"""The PUT next door treats `/a.txt` as `a.txt` (_safe_member strips it); these do the same."""diff --git a/runner/server.py b/runner/server.pyindex 662ad734..f58dd456 100644--- a/runner/server.py+++ b/runner/server.py@@ -13164,6 +13164,7 @@ async def put_file(request: Request, path: str, identifier: str = "") -> dict:inside = _safe_join(vis, path)if inside is not None:dest = inside+ _refuse_protected(ws, dest)data = await request.body()pathlib.Path(ws).mkdir(parents=True, exist_ok=True)_isolate_session(ws)diff --git a/runner/tests/test_file_changes.py b/runner/tests/test_file_changes.pyindex bf3886d5..acba8b5e 100644--- a/runner/tests/test_file_changes.py+++ b/runner/tests/test_file_changes.py@@ -163,16 +163,25 @@ def test_the_nesting_base_s_own_directory_is_not_a_user_path(ws, c):@pytest.mark.parametrize("call", [("delete", {"path": "skills"}), ("delete", {"path": "AGENTS.md"}),("delete", {"path": "skills/s/SKILL.md"}), ("move", {"path": "skills", "to": "s2"}),- ("move", {"path": "deck.json", "to": "skills/deck.json"}), ("mkdir", {"path": "memory/new"})])+ ("move", {"path": "deck.json", "to": "skills/deck.json"}), ("mkdir", {"path": "memory/new"}),+ # PUT is the fourth route into the workspace and belongs in this table: `AGENTS.md` replaces the+ # base's own instructions where the agent reads them, and `memory/notes.txt` lands at the session+ # root, which the next turn adopts into the excluded directory.+ ("put", {"path": "AGENTS.md"}), ("put", {"path": "memory/notes.txt"})])def test_the_base_s_excluded_machinery_is_refused(ws, c, call):_nanobot(ws)op, params = callif op == "delete":r = c.delete("/file", params={"identifier": "s", **params})+ elif op == "put":+ r = c.put("/file", params={"identifier": "s", **params}, content=b"OVERWRITTEN BY AN APP")else:r = c.post(f"/file/{op}", params={"identifier": "s", **params})assert r.status_code == 400- assert (ws / "workspace" / "skills" / "s" / "SKILL.md").exists() and (ws / "workspace" / "AGENTS.md").exists()+ # the contents, not just the names: a put that was let through leaves the file there, overwritten+ assert (ws / "workspace" / "skills" / "s" / "SKILL.md").read_text() == "skill"+ assert (ws / "workspace" / "AGENTS.md").read_text() == "doc"+ assert not list(ws.rglob("notes.txt")) and not (ws / "workspace" / "memory").exists()def test_a_flat_base_s_excluded_files_are_refused(ws, c):@@ -181,8 +190,14 @@ def test_a_flat_base_s_excluded_files_are_refused(ws, c):(ws / "SOUL.md").write_text("s")(ws / "notes.md").write_text("n")assert c.delete("/file", params={"identifier": "s", "path": "SOUL.md"}).status_code == 400+ assert c.put("/file", params={"identifier": "s", "path": "SOUL.md"},+ content=b"OVERWRITTEN BY AN APP").status_code == 400+ assert c.put("/file", params={"identifier": "s", "path": "memory/notes.txt"},+ content=b"in").status_code == 400+ # and an ordinary workspace path still writes: the refusal reaches the base's machinery only+ assert c.put("/file", params={"identifier": "s", "path": "notes.md"}, content=b"ok").status_code == 200assert c.delete("/file", params={"identifier": "s", "path": "notes.md"}).status_code == 200- assert (ws / "SOUL.md").exists()+ assert (ws / "SOUL.md").read_text() == "s" and not (ws / "memory").exists()def test_a_file_written_at_the_root_between_turns_is_still_reachable(ws, c):