Security: Potential Path Traversal in Log File Path Resolution#28
Open
MMQ99 wants to merge 1 commit intotang-vu:mainfrom
Open
Security: Potential Path Traversal in Log File Path Resolution#28MMQ99 wants to merge 1 commit intotang-vu:mainfrom
MMQ99 wants to merge 1 commit intotang-vu:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security: Potential Path Traversal in Log File Path Resolution
Problem
Severity:
Medium| File:crates/contribai-rs/src/core/logging.rs:L36In
crates/contribai-rs/src/core/logging.rs, theinit_json_loggingfunction accepts alog_file: Option<&Path>parameter and passes it directly totracing::info!(file = %path.display(), ...). If an attacker can control the config's log file path (e.g., via a malicious config.yaml withlog.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::canonicalizeandstarts_withchecks before using the path.Changes
crates/contribai-rs/src/core/logging.rs(modified)Testing
Generated by ContribAI v6.0.0