OS command injection from unsanitized shell calls

Last updated November 12, 2026
Steps
- Search the generated project for child_process.exec, execSync, spawn with shell:true, os.system, subprocess with shell=True, Runtime.exec that builds a string, backticks in Ruby/PHP, and similar “run this command” helpers.
- For each hit, list every value that ends up in the command string: request params, uploaded filenames, env overrides from clients, AI-generated paths, webhook payloads.
- Replace shelling out with a native library or SDK when possible (image libraries, zip libraries, cloud SDKs) so no OS shell is involved.
- If you must run an external binary, use an argv array / spawn without a shell, keep the executable path hard-coded, and pass user data only as separate arguments—never via string concatenation or shell interpolation.
- Validate and constrain arguments: allowlists for subcommands and flags, reject path traversal and shell metacharacters, and keep working directories fixed.
- Run the process with least privilege (dedicated service user, no unnecessary network or filesystem rights) and capture exit codes without reflecting raw stderr to clients.
- Add a regression test or CI check that refuses builds containing shell:true / shell=True / exec(string) patterns on request-handling paths.
- Retest defensively: confirm trusted inputs still work through the safe API path, and that previously string-built shell calls no longer exist on those routes.
Why it matters
MITRE CWE-78 covers software that constructs an operating system command using externally influenced input without neutralizing special elements. The result can be execution of unintended commands with the privileges of the vulnerable process. OWASP’s OS Command Injection Defense Cheat Sheet recommends avoiding OS commands when a library API exists, and when a command is unavoidable, separating arguments from the program name and never building a shell string from untrusted data. This maps to injection-class failures in the OWASP Top Ten (A03:2021 Injection).
Sources
MITRE CWE-78: Improper Neutralization of Special Elements used in an OS Command — https://cwe.mitre.org/data/definitions/78.html
OWASP Cheat Sheet: OS Command Injection Defense — https://cheatsheetseries.owasp.org/cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.html
Checked at the source on November 5, 2026.
Related patterns
- SQL built from strings in raw queries (SQL injection)
- Running AI or user output with eval, exec or new Function (code injection)
- Prompt injection in your app's AI chatbot or AI features
- API routes with no auth check
- Hard-coded credentials left in vibe-coded apps
- Server-side template injection from unsanitized template strings
- CSV exports that run formulas when opened in a spreadsheet (CSV injection)
Found a problem you'd rather not fix yourself?
Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.
Get it fixed by StorenTechVibe Security Weekly
One email a week with new failure patterns and how to fix them.
By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.