Summary
Agent shell command arguments lack validation for shell expansion patterns, allowing potential code execution via glob patterns, variable expansion, and command substitution.
Impact
- Severity: High
- Type: Security vulnerability
- CWE: CWE-78 (OS Command Injection)
Affected Files
Vulnerability Details
The current validation only checks for path traversal but doesn't block shell expansion patterns:
- Glob patterns:
*, ?, [...]
- Variable expansion:
$VAR, ${VAR}, $(cmd)
- Tilde expansion:
~/path
- Windows variables:
%USERPROFILE%
These can expand unexpectedly or execute commands when passed to shell.
Recommended Fix
Add comprehensive pattern blocking in denyShellArgsOutsideWorkDir():
func denyShellArgsOutsideWorkDir(workdir string, args []string) error {
for _, arg := range args {
// Block shell variable expansion (Unix and Windows)
dangerousPatterns := []string{
"$", // Unix: $HOME, $(cmd), ${VAR}
"`", // Command substitution
"%", // Windows: %USERPROFILE%
}
for _, pattern := range dangerousPatterns {
if strings.Contains(arg, pattern) {
return PolicyDeniedError{
Kind: PolicyKindPathEscape,
Reason: fmt.Sprintf("shell arg contains forbidden pattern %q", pattern),
}
}
}
// Block glob patterns
if strings.ContainsAny(arg, "*?[") {
return PolicyDeniedError{
Kind: PolicyKindPathEscape,
Reason: "shell arg contains glob pattern",
}
}
// Existing path validation...
}
return nil
}
References
Summary
Agent shell command arguments lack validation for shell expansion patterns, allowing potential code execution via glob patterns, variable expansion, and command substitution.
Impact
Affected Files
agent/core/policy.goVulnerability Details
The current validation only checks for path traversal but doesn't block shell expansion patterns:
*,?,[...]$VAR,${VAR},$(cmd)~/path%USERPROFILE%These can expand unexpectedly or execute commands when passed to shell.
Recommended Fix
Add comprehensive pattern blocking in
denyShellArgsOutsideWorkDir():References