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.
Projecthongdangmoo49/Trinity
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
| 49 | 49 | """Return the managed home path for an agent.""" | |
| 50 | 50 | return self.agents_dir / agent_name / "provider-state" | |
| 51 | 51 | ||
| 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 | + | ||
| 52 | 59 | def setup(self, agent_name: str, provider: str | None = None) -> Path: | |
| 53 | 60 | """Create an isolated home directory for the agent. | |
| 54 | 61 | ||
| ⋯ | |||
| 172 | 179 | home = self._agent_home(agent_name) | |
| 173 | 180 | home.mkdir(parents=True, exist_ok=True) | |
| 174 | 181 | ||
| 175 | - | file_path = home / filename | |
| 182 | + | file_path = self._validate_path_within_home(home, filename) | |
| 176 | 183 | file_path.parent.mkdir(parents=True, exist_ok=True) | |
| 177 | 184 | file_path.write_text(content, encoding="utf-8") | |
| 178 | 185 | ||
| ⋯ | |||
| 186 | 193 | File content, or None if not found. | |
| 187 | 194 | """ | |
| 188 | 195 | home = self._agent_home(agent_name) | |
| 189 | - | file_path = home / filename | |
| 196 | + | file_path = self._validate_path_within_home(home, filename) | |
| 190 | 197 | ||
| 191 | 198 | if not file_path.exists(): | |
| 192 | 199 | return None | |
The check that tells the two apart
fail→pass·tests/test_managed_home.py::TestManagedHomeSecurity::test_read_config_rejects_path_traversal
fail→pass·tests/test_managed_home.py::TestManagedHomeSecurity::test_write_config_rejects_absolute_path
fail→pass·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
- 2026-06-17fix: avoid missing workflow events traceback
- 2026-06-06fix: reuse target workspace for workflow followups
- 2026-06-05fix(tui): address code quality review for SacredGeometryAnimator
- 2026-06-03fix: make rotation/warning thresholds configurable instead of hardcoded
- 2026-06-02fix: sanitize surrogate characters in SharedContextEngine.write()