Advisory

PYSEC-2026-3499

Details, part 2 of 2. The advisory

Details

Remediation

Treat run_id and agent_id as logical identifiers, not path components.

Recommended fixes:

  1. Reject absolute paths, path separators, and traversal components in run_id and agent_id.
  2. Build candidate paths, call .resolve(), and reject any path that is not under self.base_dir.resolve().
  3. Apply the same containment helper to history append/read/search/clear/export and terminal log/read/search/clear/export paths.
  4. Prefer opaque server-generated run and agent IDs in tool schemas.
  5. Add regression tests for absolute run_id, ../ in run_id, and ../ in agent_id for 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.

Sources & licences