Skip to content
Vol. 1 · Ed. 2026
CyberGlossary
Entry № 220

Code Injection

Reviewed byCybersecurity entrepreneur & security researcher

What is Code Injection?

Code InjectionA class of vulnerabilities where attacker-supplied data is interpreted and executed as code by an application, leading to arbitrary execution in its context.


Code injection (CWE-94) is the broad family of flaws in which untrusted input is incorporated into something the application later treats as program code, causing the runtime to execute it. Unlike command injection (which reaches the OS shell), code injection runs inside the application's own interpreter. Concrete instances include eval-based injection in JavaScript and Python, server-side template injection, expression-language injection (OGNL, SpEL), insecure deserialization that triggers gadget chains, and dynamic class loading from user data. Successful exploitation typically yields remote code execution under the application's identity — often a stepping stone to full host or cluster compromise.

Three landmark cases show the impact. Apache Struts CVE-2017-5638 allowed OGNL expressions in a malformed Content-Type header to execute; an unpatched instance caused the 2017 Equifax breach exposing ~147 million records. Log4Shell (CVE-2021-44228), CVSS 10.0, turned any logged string containing a JNDI lookup into a remote Java class load. Spring4Shell (CVE-2022-22965) abused Spring's data-binding to manipulate the ClassLoader and drop a web shell.

flowchart TD
  A[Untrusted input] --> B{Reaches a code-evaluating sink?}
  B -->|eval / template / OGNL / deserialize| C[Interpreter executes attacker code]
  B -->|Validated / parameterized| D[Treated as inert data]
  C --> E[RCE as app identity]
  E --> F[Host / cluster compromise]
  D --> G[Safe]

Defences: never build code, templates, or expressions from input; use parameterized and allow-listed APIs; disable or sandbox dynamic evaluation and deserialization; patch frameworks promptly; and run with least privilege so RCE yields the smallest possible blast radius.

Examples

  1. 01

    eval(request.body.expr) running attacker-controlled JavaScript in a Node service.

  2. 02

    Java application calling ScriptEngine.eval on a user-supplied script.

Frequently asked questions

What is Code Injection?

A class of vulnerabilities where attacker-supplied data is interpreted and executed as code by an application, leading to arbitrary execution in its context. It belongs to the Attacks & Threats category of cybersecurity.

What does Code Injection mean?

A class of vulnerabilities where attacker-supplied data is interpreted and executed as code by an application, leading to arbitrary execution in its context.

How do you defend against Code Injection?

Defences for Code Injection typically combine technical controls and operational practices, as detailed in the full definition above.

What are other names for Code Injection?

Common alternative names include: Remote code execution, Arbitrary code execution.

Related terms

See also