🔒 Fix command injection vulnerability in command_exists function#68
🔒 Fix command injection vulnerability in command_exists function#68badMade wants to merge 2 commits into
Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Pull request overview
Fixes a command injection risk in the Rust tools crate by avoiding direct interpolation of untrusted input into a sh -c command string.
Changes:
- Updates
command_existsto pass the command name as a positional parameter ($1) rather than interpolating into the shell script. - Adds a unit test intended to ensure malicious strings are not treated as valid commands.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fn command_exists(command: &str) -> bool { | ||
| std::process::Command::new("sh") | ||
| .arg("-c") | ||
| .arg(format!("command -v {command} >/dev/null 2>&1")) | ||
| .arg("command -v \"$1\" >/dev/null 2>&1") | ||
| .arg("--") | ||
| .arg(command) | ||
| .status() |
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Pull request overview
This PR mitigates a command injection risk in the Rust tools crate by changing how command_exists invokes sh -c, ensuring user-supplied command strings are not interpolated into shell source.
Changes:
- Reworked
command_existsto pass the command name as a positional parameter ($1) instead of interpolating it into the shell script. - Added a unit test covering both normal command names and an injection-like string (
ls; echo injected).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codex Review: Didn't find any major issues. Can't wait for the next one! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@gemini-code-assist, what are the steps and line numbers to make this fix? |
|
The fix for the command injection vulnerability has already been implemented in 1. Modifying
|
🎯 What: The
command_existsfunction insiderust/crates/tools/src/lib.rshad a command injection vulnerability where a user-provided string was directly injected intosh -cusingformat!().commandinto the format string ofsh -c, a maliciously crafted string such asls; rm -rf /could execute unintended logic, compromising the host system or container environment.🛡️ Solution: Modified the call to pass the user input as a distinct positional argument (
$1) to theshscript by injecting"command -v \"$1\" >/dev/null 2>&1", followed by--and the originalcommandargument. Added a unit test to verify that standard commands (likels) returntrue, while malicious strings (likels; echo injected) are safely handled and returnfalse.PR created automatically by Jules for task 4207213518264608965 started by @badMade