This vulnerability occurs when an application builds executable code using unvalidated external input, such as user data. Because the application fails to properly filter or escape this input, an attacker can inject special characters or commands that alter the intended code's logic or syntax.

Code injection happens when user-supplied data is directly incorporated into dynamically generated code, like SQL queries, OS commands, or script blocks. Attackers exploit this by crafting inputs containing command delimiters or code syntax, tricking the application into executing unintended instructions. This can lead to data theft, system takeover, or complete compromise of the application's environment. To prevent this, developers must strictly separate code from data. Use parameterized queries for databases, prepared statements, or safe API calls that automatically handle escaping. Never concatenate raw user input into executable strings. Input validation is also critical, but it should be a secondary defense, as proper use of secure coding interfaces is the most reliable way to neutralize injection risks.
Impact: Bypass Protection Mechanism
In some cases, injectable code controls authentication; this may lead to a remote vulnerability.
Impact: Gain Privileges or Assume Identity
Injected code can access resources that the attacker is directly prevented from accessing.
Impact: Execute Unauthorized Code or Commands
When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. As a result, code injection can often result in the execution of arbitrary code. Code injection attacks can also lead to loss of data integrity in nearly all cases, since the control-plane data injected is always incidental to data recall or writing.
Impact: Hide Activities
Often the actions performed by injected control code are unlogged.
Strategy: Input Validation
Strategy: Compilation or Build Hardening
Strategy: Environment Hardening
Effectiveness: Discouraged Common Practice
phpbashbashperl
perl
perl
perl
perlbashbashpythonbashpythonMedium