Skip to content

Security: Potential Path Traversal in Log File Path Resolution#28

Open
MMQ99 wants to merge 1 commit intotang-vu:mainfrom
MMQ99:contribai/fix/security/potential-path-traversal-in-log-file-pat
Open

Security: Potential Path Traversal in Log File Path Resolution#28
MMQ99 wants to merge 1 commit intotang-vu:mainfrom
MMQ99:contribai/fix/security/potential-path-traversal-in-log-file-pat

Conversation

@MMQ99
Copy link
Copy Markdown

@MMQ99 MMQ99 commented Apr 20, 2026

Summary

Security: Potential Path Traversal in Log File Path Resolution

Problem

Severity: Medium | File: crates/contribai-rs/src/core/logging.rs:L36

In crates/contribai-rs/src/core/logging.rs, the init_json_logging function accepts a log_file: Option<&Path> parameter and passes it directly to tracing::info!(file = %path.display(), ...). If an attacker can control the config's log file path (e.g., via a malicious config.yaml with log.file: "../../etc/passwd"), this could lead to unintended file writes or information disclosure. Additionally, there is no validation that the path is within an allowed directory.

Solution

Validate and sanitize the log file path: ensure it is absolute, resides within a designated log directory (e.g., ~/.contribai/logs/), and does not contain directory traversal sequences. Use Path::canonicalize and starts_with checks before using the path.

Changes

  • crates/contribai-rs/src/core/logging.rs (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

Generated by ContribAI v6.0.0

In `crates/contribai-rs/src/core/logging.rs`, the `init_json_logging` function accepts a `log_file: Option<&Path>` parameter and passes it directly to `tracing::info!(file = %path.display(), ...)`. If an attacker can control the config's log file path (e.g., via a malicious config.yaml with `log.file: "../../etc/passwd"`), this could lead to unintended file writes or information disclosure. Additionally, there is no validation that the path is within an allowed directory.

Affected files: logging.rs

Signed-off-by: MMQ99 <277782550+MMQ99@users.noreply.github.com>
@MMQ99 MMQ99 requested a review from tang-vu as a code owner April 20, 2026 15:40
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