Rules / Rust
SHIELD-RUST-004
Command injection via interpolated argument
What it detects
Passing a format!-built string as a process argument can inject commands or flags.
How to fix
Pass fixed arguments as separate .arg() values; never build args from untrusted input.
Vulnerable — Shield flags thismain.rs
use std::process::Command;
fn convert_image(user_file: &str) -> std::io::Result<()> {
let status = Command::new("convert")
.arg(format!("--input={}", user_file))
.arg("out.png")
.status()?;
println!("convert exited: {}", status);
Ok(())
}
Fixed — scans cleanmain.rs
use std::process::Command;
fn convert_image(user_file: &str) -> std::io::Result<()> {
let status = Command::new("convert")
.arg("--input")
.arg(user_file)
.arg("out.png")
.status()?;
println!("convert exited: {}", status);
Ok(())
}
Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-RUST-004, the fixed one does not.