fix(dotnet): prevent shell command injection in CLI Agent (fixes #636)#647
fix(dotnet): prevent shell command injection in CLI Agent (fixes #636)#647kuangmi-bit wants to merge 1 commit into
Conversation
Replace shell-based command execution (/bin/bash -c / cmd.exe /c) with direct process invocation using ProcessStartInfo.ArgumentList. Root cause: ParseCommand only allowlisted the first token, then interpolated the entire string into a shell command line. Shell metacharacters (;, |, &&, $(), backticks) in the argument portion bypassed the allowlist entirely. Changes: - Execute allowlisted commands directly — no shell, no /bin/bash -c - Parse arguments into a List<string>, pass via ArgumentList (argv) - ArgumentList handles platform-specific quoting, metacharacters arrive as literal argv entries — never interpreted by a shell - Remove interpreters (python, node, npm, dotnet) from default allowlist — they accept arbitrary code as arguments - Add security warning: this sample should not be exposed to untrusted clients UseShellExecute = false is not a mitigation here — it only stops .NET from using the OS shell to resolve FileName. The code was explicitly invoking /bin/bash -c (and cmd.exe /c), so a shell parsed the string regardless. Credit to @chopmob-cloud for the detailed root-cause analysis and fix direction. Fixes a2aproject#636
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Verified this against the branch. The sink from #636 is closed, and it is the right shape of fix rather than an escaping patch: there is no shell process left to interpret metacharacters, Three things the change leaves behind. Five allowlist entries only worked because of the shell.
The rest of the list divides cleanly by platform and is unaffected either way. The README now documents the design this PR removes. It still states "Windows: Uses Minor: Worth naming what the change deliberately does not cover, because the added remarks get this right: |
Summary
Fixes the shell command injection vulnerability reported in #636.
Root cause:
ParseCommandonly allowlisted the first token, then interpolated the entire string into/bin/bash -c "{command} {arguments}". Shell metacharacters (;,|,&&,$(), backticks) in the argument portion bypassed the allowlist entirely.Fix: Replace shell-based execution with direct process invocation:
ProcessStartInfo, never through/bin/bash -corcmd.exe /cList<string>, pass viaArgumentList(argv).ArgumentListhandles platform-specific quoting; metacharacters arrive as literal argv entriespython,node,npm,dotnet) — they accept arbitrary code as argumentsCredit to @chopmob-cloud for the detailed root-cause analysis and fix direction in #636.