Whole file

hongdangmoo49/Trinity

The author described this change as fix(security): prevent path traversal in ManagedHome read/write_config. It counts as a record because the checks below fail on the code as it stood at 6fb53517c and pass on ff19f4206, with nothing else changed between the two runs.

Fix saved2026-06-03
Sharing licenceMIT · LICENSE
Change size+9 2

What the code was meant to do, written into the code itself as a save note

fix(security): prevent path traversal in ManagedHome read/write_config

The change

4949 """Return the managed home path for an agent."""
5050 return self.agents_dir / agent_name / "provider-state"
5151
52+ def _validate_path_within_home(self, home: Path, filename: str) -> Path:
53+ """Resolve filename within home, raising ValueError on path traversal."""
54+ resolved = (home / filename).resolve()
55+ if not resolved.is_relative_to(home.resolve()):
56+ raise ValueError(f"Path traversal detected: {filename}")
57+ return resolved
58+
5259 def setup(self, agent_name: str, provider: str | None = None) -> Path:
5360 """Create an isolated home directory for the agent.
5461
172179 home = self._agent_home(agent_name)
173180 home.mkdir(parents=True, exist_ok=True)
174181
175- file_path = home / filename
182+ file_path = self._validate_path_within_home(home, filename)
176183 file_path.parent.mkdir(parents=True, exist_ok=True)
177184 file_path.write_text(content, encoding="utf-8")
178185
186193 File content, or None if not found.
187194 """
188195 home = self._agent_home(agent_name)
189- file_path = home / filename
196+ file_path = self._validate_path_within_home(home, filename)
190197
191198 if not file_path.exists():
192199 return None

The check that tells the two apart

failpass·tests/test_managed_home.py::TestManagedHomeSecurity::test_read_config_rejects_path_traversal
failpass·tests/test_managed_home.py::TestManagedHomeSecurity::test_write_config_rejects_absolute_path
failpass·tests/test_managed_home.py::TestManagedHomeSecurity::test_write_config_rejects_path_traversal

Check file tests/test_managed_home.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it6fb53517c4e4caefdd7704880cebff3eca954179
Broken version dated2026-06-03
Moduletrinity.workspace.managed_home
Units changedManagedHome
Fingerprint6fa98967e06e49a1
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in hongdangmoo49/Trinity