fix(gerrit): prevent path traversal in publish_code_suggestions#2314
fix(gerrit): prevent path traversal in publish_code_suggestions#2314
Conversation
Sanitize the `relevant_file` path before writing to prevent directory traversal attacks. The path is resolved and verified to stay within `repo_path` before any file write occurs. Suggestions with suspicious paths are skipped with a warning log. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Review Summary by QodoPrevent path traversal in Gerrit code suggestions publishing
WalkthroughsDescription• Sanitize file paths in publish_code_suggestions() to prevent directory traversal attacks • Resolve target path and verify it stays within repository bounds • Skip suggestions with suspicious paths and log warnings Diagramflowchart LR
A["suggestion['relevant_file']"] --> B["Resolve to absolute path"]
B --> C{"Path within repo_root?"}
C -->|No| D["Log warning and skip"]
C -->|Yes| E["Write suggestion to file"]
File Changes1. pr_agent/git_providers/gerrit_provider.py
|
Code Review by Qodo
|
|
Persistent review updated to latest commit a9332a2 |
| for suggestion in code_suggestions: | ||
| # Validate suggestion structure before accessing keys | ||
| if not isinstance(suggestion, dict) or not isinstance(suggestion.get("relevant_file"), str): | ||
| get_logger().warning(f"Skipping malformed suggestion: missing or invalid 'relevant_file'") |
There was a problem hiding this comment.
1. Useless f-string in warning 📘 Rule violation ⚙ Maintainability
get_logger().warning(f"...") is an f-string with no interpolation, which will trigger Ruff’s F541 and can fail CI linting. This introduces a repository lint/format violation in newly added code.
Agent Prompt
## Issue description
A new `warning()` call uses an f-string without any interpolation (`f"..."`), which Ruff flags (F541) and may fail CI.
## Issue Context
This line logs a static message and does not need f-string formatting.
## Fix Focus Areas
- pr_agent/git_providers/gerrit_provider.py[349-349]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Persistent review updated to latest commit 1dcc22e |
Summary
relevant_filepath inpublish_code_suggestions()to prevent directory traversalrepo_pathbefore writingProblem
suggestion['relevant_file']comes from AI output and is used directly inPath(repo_path) / relevant_filewithout validation. A path like../../etc/passwdcould write outside the repo directory.Test plan
../paths are rejected with a warning log🤖 Generated with Claude Code