Nullify

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Product Security Terms›
Command Injection

Product Security Terms

Command Injection

NT
Tim Thacker
November 26, 2026

What Is
Command Injection
?

Command injection is a vulnerability in which an application builds a system or shell command from external input without neutralizing special characters, so an attacker can change the command or add commands of their own. The injected commands run with the privileges of the vulnerable process, which often leads to remote code execution.

Also known as:

OS command injection, shell injection, CWE-78, CWE-77

What Command Injection Means

Command injection happens when untrusted data crosses from being data into being part of a command. MITRE tracks the general weakness as CWE-77, where an application builds any command from external input, and the most common form as CWE-78, OS command injection, where that command goes to the operating system shell. A closely related weakness, argument injection (CWE-88), lets an attacker add options or arguments to a command even when they can't start a new one.

How a Command Injection Attack Works

Shells treat characters such as ;, &&, |, backticks and $( ) as instructions, not text. If an application pastes user input into a command string and hands it to a shell, those characters let an attacker end the intended command and start another. For example, a diagnostics endpoint might run os.system("ping -c 1 " + host). A request with a host value that ends in a semicolon and a second command makes the server run both. The safer version skips the shell and passes arguments as a list, so the input stays a single argument: subprocess.run(["ping", "-c", "1", host]).

Where Command Injection Shows Up

  • Web handlers that wrap system tools. Image converters, archive tools, network diagnostics and PDF renderers are common places where input reaches a shell.
  • Network and edge devices. Management interfaces often call shell scripts, which is why CISA published a Secure by Design Alert urging manufacturers to eliminate OS command injection.
  • Build and deployment scripts. CI/CD pipelines that interpolate pull request titles, branch names or other attacker-controlled values into a shell step can run an attacker's commands with access to pipeline secrets.
  • AI agents and tools. Agents that turn model output into shell commands create the same risk when that output is shaped by untrusted content.

Why Command Injection Is So Severe

A successful injection gives the attacker whatever the vulnerable process can do: read files and environment variables, steal credentials, change data, reach internal services and install persistence. That is why command injection is one of the most common root causes behind remote code execution CVEs, and why exploited command injection flaws regularly appear in the CISA Known Exploited Vulnerabilities catalog.

How to Prevent Command Injection

  • Avoid calling the shell. Use built-in library functions for the task instead of external programs where you can.
  • When you must run a program, use APIs that take the program and its arguments separately, such as a list of arguments with no shell, so input can't change the command's structure.
  • Validate input against a strict allowlist of expected values, such as known hostnames or file names, and reject everything else.
  • Treat escaping as a last resort. Escaping shell metacharacters is easy to get wrong and doesn't stop argument injection.
  • Run services and CI jobs with least privilege, so an injected command can reach as little as possible.

How Nullify Finds Command Injection

Nullify code analysis covers both command injection (CWE-77) and OS command injection (CWE-78). It detects unsanitized command construction in shell runners, build tooling and deployment scripts, and finds user-controlled data reaching operating system calls such as exec, Runtime.exec, subprocess and ProcessBuilder. For pipelines, Nullify flags CI script injection, where an attacker-controlled variable is interpolated into a shell step. Nullify pentests then test injection flaws, including command injection, against a running application. Explore Nullify Code Security.

Key Takeaways

  • Command injection lets an attacker change or add commands that an application runs on the system.
  • It is tracked as CWE-77, with OS command injection as CWE-78 and argument injection as CWE-88.
  • Injected commands run with the privileges of the vulnerable process and often lead to remote code execution.
  • Avoiding the shell and passing arguments separately is the strongest defense, with allowlist validation and least privilege as backups.

Read More About
Command Injection

Code Security

See Nullify in Action

Find user input reaching shells and OS calls before it ships.

Explore Code Security

Reduce your vulnerability backlog and lower your MTTR

The AI harness that finds, proves and fixes vulnerabilities across your codebase.

Book a demo