fix: enforce exact Dream memory file writes

maintainer edit: Dream write tools used file paths as directory roots, so a missing canonical memory file could be treated as a parent directory. Add exact-file allowlist support and keep skills/ as the only Dream write directory.
This commit is contained in:
chengyongru
2026-06-18 00:03:26 +08:00
committed by Xubin Ren
parent 732992df4f
commit 15f218e918
8 changed files with 129 additions and 15 deletions
+24
View File
@@ -67,3 +67,27 @@ def test_resolve_allowed_path_allows_extra_root(tmp_path: Path) -> None:
)
assert resolved == image.resolve()
def test_resolve_allowed_path_allows_extra_file_only_exactly(tmp_path: Path) -> None:
workspace = tmp_path / "workspace"
workspace.mkdir()
outside = tmp_path / "outside"
outside.mkdir()
allowed = outside / "allowed.txt"
resolved = resolve_allowed_path(
allowed,
workspace=workspace,
allowed_root=workspace,
extra_allowed_files=[allowed],
)
assert resolved == allowed.resolve()
with pytest.raises(WorkspaceBoundaryError, match="outside allowed directory"):
resolve_allowed_path(
allowed / "child.txt",
workspace=workspace,
allowed_root=workspace,
extra_allowed_files=[allowed],
)