Details
Remediation
Treat run_id and agent_id as logical identifiers, not path components.
Recommended fixes:
- Reject absolute paths, path separators, and traversal components in
run_idandagent_id. - Build candidate paths, call
.resolve(), and reject any path that is not underself.base_dir.resolve(). - Apply the same containment helper to history append/read/search/clear/export and terminal log/read/search/clear/export paths.
- Prefer opaque server-generated run and agent IDs in tool schemas.
- Add regression tests for absolute
run_id,../inrun_id, and../inagent_idfor history and terminal tool factories.
Minimal containment shape:
def _safe_child(self, *parts: str) -> Path:
candidate = self.base_dir.joinpath(*parts).resolve()
base = self.base_dir.resolve()
try:
candidate.relative_to(base)
except ValueError as exc:
raise PermissionError("Context path is outside configured base_dir") from exc
return candidate
Pair this with an identifier allowlist, because run_id and agent_id should
not need filesystem syntax.