igbuend/grimbard/command-injection-anti-pattern
Claude Code and agent skill by igbuend/grimbard
- community
Checking that the SKILL.md file is still in the repository.
Security anti-pattern for OS Command Injection vulnerabilities (CWE-78). Use when generating or reviewing code that executes shell commands, runs system processes, or handles user input in command-line operations. Detects shell string concatenation and recommends argument arrays.
Install
npx vskill@latest install igbuend/grimbard/command-injection-anti-patternSKILL.md
Command Injection Anti-Pattern
Severity: Critical
Summary
Command injection allows attackers to execute arbitrary OS commands by manipulating user input. This anti-pattern occurs when applications concatenate user input into shell command strings. Common in AI-generated code. Enables complete system compromise, data exfiltration, malware installation, and lateral movement.
The Anti-Pattern
User input embedded in shell command strings enables command injection. The shell cannot distinguish between intended commands and attacker-injected commands.
BAD Code Example
GOOD Code Example
JavaScript/Node.js Examples
BAD:
GOOD:
Java Examples
BAD:
GOOD:
Detection
Python:
os.system()with any user inputsubprocess.run()orsubprocess.Popen()withshell=True- String concatenation:
"command " + user_input - f-strings:
f"command {user_input}"
JavaScript/Node.js:
child_process.exec()with user input- Template literals: `
command ${userInput}` - String concatenation:
"command " + userInput
Java:
Runtime.getRuntime().exec()with string concatenation- Single string argument to
exec()instead of string array
PHP:
exec(),system(),shell_exec(),passthru()with user input- String concatenation:
"command " . $userInput
Search Patterns:
- Grep:
shell=True|exec\(|system\(|child_process\.exec - Look for user input variables in command construction
- Check for string concatenation or interpolation with command functions
Prevention
- [ ] Use argument arrays instead of shell strings (e.g.,
subprocess.run(["command", "arg1", "arg2"], shell=False)). - [ ] Never pass `shell=True` with user-controlled input to execution functions.
- [ ] Validate all input against a strict allowlist of known-good values or formats.
- [ ] Use language-specific libraries or APIs instead of external shell commands whenever possible.
- [ ] Apply the Principle of Least Privilege to the process executing the command, restricting its permissions to the absolute minimum required.
Testing for Command Injection
Manual Testing:
- Test shell metacharacters:
;,|,&,$(), ``,&&,||` - Input payloads:
; ls,| whoami,& cat /etc/passwd, `id` - Verify commands execute safely without shell interpretation
- Confirm metacharacters treated as literal strings
Automated Testing:
- Static Analysis: Semgrep, Bandit (Python), ESLint security plugins, SpotBugs (Java)
- DAST: Burp Suite, OWASP ZAP with command injection payloads
- Code Review: Search for detection patterns above
Example Test:
Remediation Steps
- Identify vulnerable code - Use detection patterns above
- Validate necessity - Can you avoid shell commands entirely?
- Replace with safe API - Use language-specific libraries when possible
- Convert to argument arrays - Replace string concatenation
- Remove shell=True - Never use with user input
- Add input validation - Allowlist known-good patterns
- Test the fix - Verify shell metacharacters are literal
- Review similar code - Check for pattern across codebase
Related Security Patterns & Anti-Patterns
- SQL Injection Anti-Pattern: A similar injection pattern targeting databases.
- Path Traversal Anti-Pattern: Often combined with command injection to access or create files in unintended locations.
- Missing Input Validation Anti-Pattern: A fundamental weakness that enables command injection.
References
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/command-injection-anti-pattern/SKILL.md
Popularity
- Repository stars
- 4
- Repository forks
- 1
- 7-day trend score
- 8
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 8 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/igbuend/grimbard/command-injection-anti-pattern)