Skip to content

Security: Unsafe Path Traversal in File Operations#1753

Open
tomaioo wants to merge 1 commit into
MarketSquare:mainfrom
tomaioo:fix/security/unsafe-path-traversal-in-file-operations
Open

Security: Unsafe Path Traversal in File Operations#1753
tomaioo wants to merge 1 commit into
MarketSquare:mainfrom
tomaioo:fix/security/unsafe-path-traversal-in-file-operations

Conversation

@tomaioo
Copy link
Copy Markdown

@tomaioo tomaioo commented May 26, 2026

Summary

Security: Unsafe Path Traversal in File Operations

Problem

Severity: Medium | File: src/robocop/linter/reports/text_file.py:L56

Multiple locations in the codebase construct file paths without proper validation. In tests/formatter/formatters/GenerateDocumentation/test_formatter.py, template_path is constructed from Path(__file__).parent / "source" / "template_with_defaults.txt" and passed to configuration. In src/robocop/linter/reports/text_file.py, the output_path is configurable and used directly with Path(value) and open(). While mkdir(parents=True, exist_ok=True) is used, there's no validation that the path doesn't escape intended directories. The json_report.py similarly uses configurable paths.

Solution

Validate that configured output paths are within allowed directories. Use path.resolve().relative_to(base_dir) checks to prevent path traversal. Consider adding a safe_path utility that rejects paths containing .. or absolute paths when user-configurable.

Changes

  • src/robocop/linter/reports/text_file.py (modified)

Multiple locations in the codebase construct file paths without proper validation. In `tests/formatter/formatters/GenerateDocumentation/test_formatter.py`, `template_path` is constructed from `Path(__file__).parent / "source" / "template_with_defaults.txt"` and passed to configuration. In `src/robocop/linter/reports/text_file.py`, the `output_path` is configurable and used directly with `Path(value)` and `open()`. While `mkdir(parents=True, exist_ok=True)` is used, there's no validation that the path doesn't escape intended directories. The `json_report.py` similarly uses configurable paths.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant