🛡️ PyGuard Security Report

Generated: 2026-05-13 10:53:02 · 1 finding(s)
1
Total
0
Critical
1
High
0
Medium
0
Low
HIGH Potential command injection pattern go
📄 samples/go_injection_test.go : line 8
Potential dangerous command execution pattern detected.
exec.Command("sh", "-c", "id").Run() // should trigger injection pattern
🤖 AI Analysis
RiskThis finding indicates a potential for command injection. If the 'id' argument in `exec.Command` were derived from user input without proper sanitization, an attacker could inject malicious commands. For example, if the input was something like `'; rm -rf / --no-preserve-root'`, the `rm` command would be executed with devastating consequences, leading to data loss or system compromise. Even if the current 'id' is hardcoded, the pattern itself is flagged as dangerous because it allows for arbitrary command execution and is a common vulnerability vector.
FixAvoid using `exec.Command` with `sh -c` when possible. Instead, use the `exec` package's functions that take the command and its arguments as separate strings. This prevents the shell from interpreting special characters in the arguments. If you must use `sh -c`, ensure that any user-supplied input is rigorously sanitized and validated to remove or escape shell metacharacters. Using `exec.Command` directly with the command and its arguments is generally safer.
Example
Instead of:
exec.Command("sh", "-c", "echo " + userInput).Run()

Use:
exec.Command("echo", userInput).Run()
NotesThe current code `exec.Command("sh", "-c", "id").Run()` is likely a false positive in terms of immediate risk, as 'id' is a fixed string and not derived from user input. However, the static analysis tool correctly identifies the *pattern* of using `sh -c` for command execution as inherently risky because it opens the door to command injection if any part of the command string originates from an untrusted source. The tool is flagging the *potential* for misuse.