CWE-78 is a weakness class for command injection through unsafe construction of operating system commands. It covers failures to neutralise shell metacharacters, so attacker-controlled input can alter the command, append arguments, or run additional commands with the privileges of the calling process.
What Improper Neutralization Means in an OS Command Context
CWE-78 is a weakness in how software builds operating system commands. The danger is not just “bad input,” but input that reaches a shell or command interpreter without proper neutralisation, so metacharacters, delimiters or extra arguments change what the process actually runs.
This weakness is especially important because the command executes with the privileges of the calling application. If that application can reach sensitive files, internal services or administrative tools, the injected command inherits that reach.
How Command Injection Happens
Command injection usually appears when developers concatenate user-controlled values into a string passed to a shell, script runner or system utility. Even when the intended command is safe, a crafted value can terminate the original command, append a second one, or alter an argument in a way the author did not expect.
The vulnerability is broader than a single delimiter character. Quoting mistakes, unsafe escaping, mixed encoding, argument splitting, and using shell features when a direct process execution API would suffice can all create the opening. One unsafe wrapper can affect many code paths if it is reused across an application or deployment pipeline.
For practical background on the weakness family and its relationship to other CWE entries, see the CWE Top 25 Guide and the Command Injection Guide.
Why It Is Dangerous
CWE-78 is dangerous because it converts input handling into execution control. A successful injection can read or modify files, launch child processes, pivot into internal systems, or interfere with automation that was assumed to be trusted.
The impact often scales with privilege. If the vulnerable process runs as a service account, scheduler, deployment worker or administrative daemon, the injected command may inherit enough authority to expose secrets, tamper with configuration, or persist in the environment.
For teams mapping secure coding priorities, the OWASP Top 10 A05 Guide places OS command injection in the broader injection family, while the Web Application Attacks Guide shows how command injection fits into a wider set of web exploitation patterns.
Safe Construction and Review Points
The safest design is to avoid shell interpretation entirely when the platform offers a direct API for the task. Where command execution is unavoidable, command structure should be fixed in code, and untrusted data should be passed as data, not embedded into a shell string.
Reviewers should look closely at process-spawn helpers, wrapper libraries, build scripts, and automation jobs that shell out to the operating system. In Go, for example, the use of Go Secure Coding Guide is a useful reminder that os/exec patterns need careful handling, especially where untrusted input can influence command choice or arguments.
Searches for this weakness should also consider whether the affected command runs in a CI/CD job, scheduled task, or agentic workflow. Those settings often make a one-line injection far more consequential because they sit close to build credentials, deployment rights, or automation tokens.
Testing and Detection
Detection starts with code review, but it should not end there. Static analysis, fuzzing, and targeted security tests can help identify call sites where shell metacharacters or argument boundaries are not handled safely.
At runtime, suspicious child processes, unusual argument patterns, unexpected command-line separators, and errors that appear only when special characters are supplied are all useful signals. If command execution is logged, preserve enough detail to see the actual process invocation without exposing sensitive material in the logs.
For teams that want a broader control catalogue and terminology bridge, the CVE, CWE and CPE Guide helps distinguish weakness classes from exploit records and affected-product tracking.
Risk and Threat Considerations
Command injection is dangerous because it turns ordinary input handling into arbitrary command execution. Attackers often use it to expand from a narrow application flaw into file access, credential theft, service tampering or deeper internal reach, especially when the vulnerable process has elevated privileges.
Failure mechanism: Untrusted input reaches a shell or command interpreter with inadequate neutralisation, so metacharacters, separators or injected arguments change the executed command.
Impact: The attacker may execute arbitrary OS commands in the security context of the process, leading to data exposure, persistence, lateral movement or disruption.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK addresses the attack and risk surface, while OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V4 — API and Web Service | OS command injection often enters through web and API inputs that reach server-side process calls. |
| V15 — Secure Coding and Architecture | CWE-78 is a secure coding weakness caused by unsafe command construction and architecture choices. | |
| Recommendation — Validate server-side inputs before any process invocation and avoid shell-based command construction. Design command execution paths to use direct APIs instead of shell interpretation. | ||
| NIST SP 800-53 Rev 5 | SI-10 — Information Input Validation | Neutralising special elements in command input is an input-validation control problem. |
| SI-2 — Flaw Remediation | CWE-78 is a remediable software weakness that requires tracking and correction in affected code. | |
| Recommendation — Validate and constrain all external input before it can influence OS command syntax. Track command-injection findings to remediation and verify fixes with testing. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | Command injection is an application-security weakness that CIS application safeguards address directly. |
| Recommendation — Review code and testing for unsafe process spawning and command construction. | ||
| MITRE ATT&CK | T1059 — Command and Scripting Interpreter | Command injection enables adversary use of interpreters to execute OS commands. |
| Recommendation — Map observed shell execution to T1059 and hunt for unexpected child-process activity. | ||
Practitioner Guidance
Why practitioners should care: Treat every place where software spawns a command as a security boundary, not just a coding convenience. The key governance decision is whether the task can be done without a shell at all; if it can, that is usually the safer design.
What to watch for: The highest-risk patterns are concatenated command strings, mixed quoting rules, helper functions that hide the underlying process call, and automation that runs with broad privileges. Pay special attention to code paths that handle filenames, hostnames, IDs or free-form user text.
Practitioner takeaway: Prefer fixed-command process APIs, pass untrusted values as separate arguments, and test the exact command surface with adversarial characters rather than assuming normal input validation is enough.
Related resources from NHI Mgmt Group
- Improper Neutralization of Special Elements
- CWE-78
- How do you patch or mitigate CVE-2024-23692 (Rejetto HTTP File Server Improper Neutralization of Special Elements Used in a Template Engine)?
- Is CVE-2024-23692 (Rejetto HTTP File Server Improper Neutralization of Special Elements Used in a Template Engine) being exploited in the wild?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org