BUG-HUNT: [Security] Path traversal vulnerability in session import/export #1789

Open
opened 2026-04-02 23:50:07 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/security-path-traversal-session-import-export
  • Commit Message: fix(tui): sanitize file paths in session import/export to prevent path traversal
  • Milestone: v3.6.0
  • Parent Epic: #400

Bug Report: [Security] — Path traversal vulnerability in session import/export

Severity Assessment

  • Impact: A malicious user could read or write files outside the intended directory, potentially leading to information disclosure or remote code execution.
  • Likelihood: High, if a user can be tricked into importing a malicious session file.
  • Priority: Critical

Location

  • File: src/cleveragents/tui/commands.py
  • Function/Class: TuiCommandRouter._session_import, TuiCommandRouter._session_export
  • Lines: 125-150, 152-173

Description

The _session_import and _session_export methods in the TuiCommandRouter class do not properly sanitize the file paths provided by the user. This could allow a malicious user to read or write files outside the intended directory by crafting a malicious path (e.g., ../../../../etc/passwd).

Evidence

def _session_export(self, tokens: list[str], *, session_id: str) -> str:
    ...
    path: str | None = None
    ...
    if path is not None:
        out = Path(path)
        out.parent.mkdir(parents=True, exist_ok=True)
        out.write_text(content, encoding="utf-8")
        return f"Session exported to {path}"
    ...

def _session_import(self, tokens: list[str]) -> str:
    ...
    path = Path(tokens[0])
    if not path.exists():
        return f"File not found: {path}"
    ...

Expected Behavior

The file paths should be validated to ensure they are within the expected directory. The resolve_import_path and resolve_export_path methods from persona.registry should be used to sanitize the paths.

Actual Behavior

The file paths are used directly without proper validation, leading to a path traversal vulnerability.

Suggested Fix

Use the resolve_import_path and resolve_export_path methods from the PersonaRegistry to sanitize the file paths before using them.

Category

security

Subtasks

  • Audit TuiCommandRouter._session_import (lines 152-173) for unsanitized path usage
  • Audit TuiCommandRouter._session_export (lines 125-150) for unsanitized path usage
  • Implement path sanitization using resolve_import_path from persona.registry in _session_import
  • Implement path sanitization using resolve_export_path from persona.registry in _session_export
  • Add validation to reject paths that resolve outside the permitted base directory (raise or return error)
  • Tests (Behave): Add scenarios for path traversal attempts in session import/export
  • Tests (Behave): Add scenarios for valid paths within the permitted directory
  • Tests (Robot): Add integration test for session import/export path validation
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • _session_import and _session_export reject any path that resolves outside the permitted base directory.
  • No path traversal sequences (e.g., ../) can be used to access files outside the intended directory.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass.
  • Coverage >= 97%.

Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/security-path-traversal-session-import-export` - **Commit Message**: `fix(tui): sanitize file paths in session import/export to prevent path traversal` - **Milestone**: v3.6.0 - **Parent Epic**: #400 ## Bug Report: [Security] — Path traversal vulnerability in session import/export ### Severity Assessment - **Impact**: A malicious user could read or write files outside the intended directory, potentially leading to information disclosure or remote code execution. - **Likelihood**: High, if a user can be tricked into importing a malicious session file. - **Priority**: Critical ### Location - **File**: `src/cleveragents/tui/commands.py` - **Function/Class**: `TuiCommandRouter._session_import`, `TuiCommandRouter._session_export` - **Lines**: 125-150, 152-173 ### Description The `_session_import` and `_session_export` methods in the `TuiCommandRouter` class do not properly sanitize the file paths provided by the user. This could allow a malicious user to read or write files outside the intended directory by crafting a malicious path (e.g., `../../../../etc/passwd`). ### Evidence ```python def _session_export(self, tokens: list[str], *, session_id: str) -> str: ... path: str | None = None ... if path is not None: out = Path(path) out.parent.mkdir(parents=True, exist_ok=True) out.write_text(content, encoding="utf-8") return f"Session exported to {path}" ... def _session_import(self, tokens: list[str]) -> str: ... path = Path(tokens[0]) if not path.exists(): return f"File not found: {path}" ... ``` ### Expected Behavior The file paths should be validated to ensure they are within the expected directory. The `resolve_import_path` and `resolve_export_path` methods from `persona.registry` should be used to sanitize the paths. ### Actual Behavior The file paths are used directly without proper validation, leading to a path traversal vulnerability. ### Suggested Fix Use the `resolve_import_path` and `resolve_export_path` methods from the `PersonaRegistry` to sanitize the file paths before using them. ### Category security ## Subtasks - [ ] Audit `TuiCommandRouter._session_import` (lines 152-173) for unsanitized path usage - [ ] Audit `TuiCommandRouter._session_export` (lines 125-150) for unsanitized path usage - [ ] Implement path sanitization using `resolve_import_path` from `persona.registry` in `_session_import` - [ ] Implement path sanitization using `resolve_export_path` from `persona.registry` in `_session_export` - [ ] Add validation to reject paths that resolve outside the permitted base directory (raise or return error) - [ ] Tests (Behave): Add scenarios for path traversal attempts in session import/export - [ ] Tests (Behave): Add scenarios for valid paths within the permitted directory - [ ] Tests (Robot): Add integration test for session import/export path validation - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - `_session_import` and `_session_export` reject any path that resolves outside the permitted base directory. - No path traversal sequences (e.g., `../`) can be used to access files outside the intended directory. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass. - Coverage >= 97%. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.6.0 milestone 2026-04-02 23:51:19 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Critical — Path traversal vulnerability in session import/export. This is a security issue that could allow unauthorized file access.
  • Milestone: v3.6.0 (already assigned — milestone is past due)
  • MoSCoW: Must Have — Security vulnerabilities are always Must Have. The specification requires safety and security hardening (Epic #362: Security & Safety Hardening). Path traversal in session import/export could allow an attacker to read or write arbitrary files on the system.

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified ✅ - **Priority**: Critical — Path traversal vulnerability in session import/export. This is a security issue that could allow unauthorized file access. - **Milestone**: v3.6.0 (already assigned — milestone is past due) - **MoSCoW**: Must Have — Security vulnerabilities are always Must Have. The specification requires safety and security hardening (Epic #362: Security & Safety Hardening). Path traversal in session import/export could allow an attacker to read or write arbitrary files on the system. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#400 Epic: Post-MVP Security
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#1789
No description provided.