Security weaknessCWE Top 25 · #9
CWE-78 OS command injection
Untrusted input reaches a system command your server runs, letting attackers execute their own commands on it.
- Senior security engineers
- 540+ projects delivered
- Reply within one business day
Quick answer
What is CWE-78?
Improper Neutralization of Special Elements used in an OS Command: The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command before it is sent to a downstream component.
Business impact
What CWE-78 could cost your business
MITRE documents what this weakness can do. Here is what that means for a website, store or app.
Confidentiality
Private data exposed
Customer records, credentials, orders or internal files can be read by people who should never see them.
- Execute Unauthorized Code or Commands
- DoS: Crash, Exit, or Restart
- Read Files or Directories
Integrity
Data, pages or code changed
Prices, orders, content or the code your site runs can be altered without your approval.
- Execute Unauthorized Code or Commands
- DoS: Crash, Exit, or Restart
- Read Files or Directories
Availability
Downtime and lost sales
Crashes, slowdowns or exhausted resources can take your site, store or app offline.
- Execute Unauthorized Code or Commands
- DoS: Crash, Exit, or Restart
- Read Files or Directories
Non-Repudiation
Actions you cannot trace
Changes can happen without a reliable record, which slows incident response and compliance work.
- Execute Unauthorized Code or Commands
- DoS: Crash, Exit, or Restart
- Read Files or Directories
In plain English
What OS command injection means for your business
- 540+projects delivered
- 9+years in business
- 23+certified experts
A senior engineer replies within one business day.
Some applications ask the operating system to run other programs, for example to resize an image, convert a document, send mail or check a network address. OS command injection happens when the command line is built from text a user supplied. The system shell treats certain characters as instructions, such as the ones that separate or chain commands. If those characters are in the input, the shell runs extra commands the developer never intended.
Those extra commands run with the same permissions as your website. That usually means access to your files, your configuration and your database credentials. An attacker may read or change data, install malicious software, or use your server to reach other systems. For a business, this is close to the worst case: the attacker is no longer limited to your application’s features. They are operating the server itself.
Where it shows up
- Image, video and PDF conversion features that call a command-line tool and include an uploaded file name or user-chosen option in the command.
- Network tools in admin panels, hosting dashboards and device interfaces that run ping, DNS lookup or similar utilities on a supplied address.
- Backup, export and deployment plugins that build shell commands for archiving or database dumps using settings or request values.
- Mail and automation scripts in PHP, Python or Node.js that pass form fields to a system call such as exec, system or child_process.
Free security check
Is CWE-78 hiding in your site?
A senior engineer checks your site, store or app for this weakness and the rest of the CWE Top 25, then sends a prioritized fix plan within one business day. No obligation.
Official definition
How MITRE defines CWE-78
Improper Neutralization of Special Elements used in an OS Command
The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command before it is sent to a downstream component.
Also known as: Shell injection, Shell metacharacters, OS Command Injection
Fix it
How to fix OS command injection
Practical steps in priority order. Share them with your developer or agency.
Avoid the shell where possible
Use a library or built-in API in your language to do the job instead of calling an external program. For example, use an image library or a mail library. No shell means no shell syntax to inject.
Pass arguments as an array
When you must run a program, call it directly with an argument list, such as execFile in Node.js or subprocess with a list and shell disabled in Python. Never build one command string through concatenation.
Allowlist every input value
Validate each value against a strict pattern or a fixed list of options before it goes near a command. Map user choices to predefined arguments on the server. Reject anything unexpected instead of trying to clean it.
Escape as a last resort
If a shell string is unavoidable, quote each argument with the platform’s escaping function, such as escapeshellarg in PHP. Treat this as a fallback. Escaping is easy to get wrong and differs between shells.
Limit privileges and sandbox
Run the web application and any helper programs as a low-privilege user inside a container or sandbox. Restrict file system and network access. This contains the damage if a command is ever injected.
Signs you may be affected
- Your code calls shell functions and includes request data, file names or settings in the command.
- Unknown processes, scheduled tasks or files appear on the server without a deployment.
- A feature fails or behaves strangely when input contains spaces, quotes or punctuation.
Questions to ask your developer
- Where does our code run system commands, and what input reaches them?
- Can those features use a library instead of calling the shell?
- What user account does the website run as, and what can it access?
Prevention
What MITRE recommends, phase by phase
Every mitigation from the CWE entry, in the order a project runs: plan, build, test, operate.
- 01
Architecture and Design
- If at all possible, use library calls rather than external processes to recreate the desired functionality.
- Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software. OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide.
- For any data that will be used to generate a command to be executed, keep as much of that data out of external control as possible. For example, in web applications, this may require storing the data locally in the session’s state instead of sending it out to the client in a hidden form field.
Show 4 more recommendations
- For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the.
- Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, consider using the ESAPI Encoding control [REF-45] or a similar tool, library, or framework. These will help the programmer encode outputs in a manner less prone to error.
- If available, use structured mechanisms that automatically enforce the separation between data and code. These mechanisms may be able to provide the relevant quoting, encoding, and validation automatically, instead of relying on the developer to provide this capability at every point where output is generated. Some languages offer multiple functions that can be used to invoke.
- When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.
- 02
Implementation
- While it is risky to use dynamically-generated query strings, code, or commands that mix control and data together, sometimes it may be unavoidable. Properly quote arguments and escape any special characters within those arguments. The most conservative approach is to escape or filter all characters that do not pass an extremely strict allowlist (such as everything that is not.
- If the program to be executed allows arguments to be specified within an input file or from standard input, then consider using that mode to pass arguments instead of the command line.
- Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of.
Detection and evidence
How CWE-78 is found, and where it has hit
The testing methods MITRE recommends, and real vulnerabilities this weakness has caused.
How it is detected
- Automated Static AnalysisThis weakness can often be detected using automated static analysis tools. Many modern tools use data flow analysis or constraint-based techniques to minimize the number of false positives. Automated static analysis might not be able to recognize when proper input validation is being performed.
- Automated Dynamic AnalysisThis weakness can be detected using dynamic tools and techniques that interact with the product using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The product’s operation may slow down, but it should not become unstable, crash.
- Manual Static AnalysisSince this weakness does not typically appear frequently within a single software package, manual white box techniques may be able to provide sufficient code coverage and reduction of false positives if all potentially-vulnerable operations can be assessed within limited time constraints.
- Automated Static Analysis – Binary or BytecodeAccording to SOAR [REF-1479], the following detection techniques may be useful: Bytecode Weakness Analysis – including disassembler + source code weakness analysis Binary Weakness Analysis – including disassembler + source code weakness analysis
- Dynamic Analysis with Automated Results InterpretationAccording to SOAR [REF-1479], the following detection techniques may be useful: Web Application Scanner Web Services Scanner Database Scanners
Real vulnerabilities it caused
- CVE-2024-53899Virtual environment builder does not correctly quote "magic" template strings, allowing OS command injection using a directory whose name contains shell metacharacters
- CVE-2025-44844file upload functionality in wireless access point allows OS command injection via shell metacharacters through the file name in a Content-Disposition header
- CVE-2024-6091Chain: AI agent platform does not restrict pathnames containing internal "/./" sequences (CWE-55), leading to an incomplete denylist (CWE-184) that does not prevent OS command injection (CWE-78)
- CVE-2024-41316Lua application in network device allows OS command injection into os.execute()
- CVE-2024-44335Chain: filter only checks for some shell-injection characters (CWE-184), enabling OS command injection (CWE-78)
- CVE-2024-52803Platform for handling LLMs has OS command injection during training due to insecure use of the "Popen" function
How we fix it
From finding to fixed: how Codefreex closes CWE-78
Scan and confirm
We test your site, store or app for this weakness and the rest of the CWE Top 25 with automated scanning and manual review, and confirm what is actually exploitable.
Fix at the source
We change the code, configuration or dependency that causes it, not just the symptom, and plan the changes to avoid downtime.
Verify the fix
We retest every finding, check that nothing else broke and hand you a short report you can share with your team, client or auditor.
Keep it fixed
Updates, monitoring and maintenance so the weakness does not return with the next plugin, theme, app or code change.
Website SecurityPenetration TestingMalware Removal & Hack RepairWordPress Maintenance
Related weaknesses
Weaknesses related to CWE-78
FAQ
CWE-78: FAQs
Short answers for owners and developers. Not sure whether your site is affected? Ask us to check.
How dangerous is OS command injection?
It is one of the most serious weaknesses a web application can have. The attacker’s commands run on your server with your application’s permissions, so they can read files, change data and install software. MITRE rates the likelihood of exploitation as high. Limiting the application’s privileges reduces the damage, but the flaw itself must be removed.
How is command injection different from SQL injection?
Both mix untrusted input into a command. SQL injection targets the database query language, so the attacker is working inside the database. OS command injection targets the operating system shell, so the attacker is running programs on the server. The principle behind the fix is shared: keep data separate from the command.
How do I prevent OS command injection?
First, avoid calling the shell at all by using libraries. If you must run a program, pass arguments as a list and never as a single string. Validate each value against an allowlist. Run the application with minimal privileges in an isolated environment. Review plugins and scripts that call exec-style functions, since they are frequent sources.
What is CWE-78?
CWE-78, “Improper Neutralization of Special Elements used in an OS Command”, is a software weakness catalogued by MITRE in the Common Weakness Enumeration. The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command before it is sent to a downstream component.
How serious is CWE-78?
MITRE rates the likelihood of exploit as High. It can affect confidentiality, integrity, availability, non-repudiation, with impacts such as execute unauthorized code or commands, dos: crash, exit, or restart, read files or directories. It ranks number 9 on the 2025 CWE Top 25 Most Dangerous Software Weaknesses. The real risk depends on where the weakness sits and what data or functions it exposes.
How do you prevent CWE-78?
If at all possible, use library calls rather than external processes to recreate the desired functionality. Run the code in a “jail” or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a.
Can Codefreex check my site for CWE-78?
Yes. A senior engineer reviews your site, store or app for CWE-78 and the rest of the CWE Top 25, confirms what is exploitable and sends a prioritized fix plan within one business day. Start with the free security check form on this page.
Free security check
Find out if CWE-78 affects your site
Send your URL. A senior engineer checks for this weakness and the rest of the CWE Top 25, and replies within one business day with what to fix first.
- A senior strategist reviews your request, not a sales bot
- Clear scope, timeline and estimate within one business day
- Free 30-minute discovery call, no obligation
- NDA available on request
- Emailhello@codefreex.com
- CallUSA +1 (209) 375-3475 · India +91 790 3375 530
- Prefer to talk?Book a 30-minute call
Weakness data from the Common Weakness Enumeration (CWE®) version 5.0, Copyright © 2006–2026, The MITRE Corporation. CWE is free to use by any organization or individual for any research, development, and/or commercial purposes under the CWE Terms of Use. CWE is a registered trademark of The MITRE Corporation. The business impact, risk profile and plain-English guidance on this page are written by Codefreex and are general information, not a security assessment of your system.