Injection & Code Execution

InjectionCode InjectionCommand ExecutionRCE

Injection & Code Execution vulnerabilities at a glance

What it is: Vulnerabilities where untrusted user input is interpreted as code or commands, allowing attackers to execute arbitrary queries, system commands, or code in the application context.
Why it happens: Injection vulnerabilities most often occur when user input isn't sanitized and is directly concatenated into an operation.
How to fix: Use parameterized queries and prepared statements. Never concatenate user input into code or commands. Apply input validation and sanitization with allowlists. Use safe APIs that separate data from code

Overview

Injection vulnerabilities occur when an application sends untrusted data to an interpreter (SQL database, system shell, template engine, etc.) without proper validation or escaping. The interpreter treats the malicious input as part of a command or query, allowing attackers to execute unintended operations.

These vulnerabilities are among the most dangerous because they often provide complete control over the affected system. SQL injection can dump entire databases, command injection can execute system commands, template injection can achieve remote code execution, and other injection variants can compromise application logic, authentication, and data integrity.

sequenceDiagram participant Attacker participant App as App Server participant DB as Database Attacker->>App: GET /users?id=1' OR '1'='1 App->>App: Build SQL: SELECT * FROM users WHERE id='1' OR '1'='1' App->>DB: Execute injected query DB-->>App: All user records App-->>Attacker: 200 OK (all users data) Note over App: Missing: Parameterized queries<br/>Missing: Input validation
A potential flow for a Injection & Code Execution exploit

Where it occurs

Injection flaws commonly occur when building database queries by string concatenation, executing system commands with user-supplied input, evaluating templates with untrusted data, deserializing user-controlled data, dynamically evaluating code based on user input, and constructing XML, JSON, or other structured data without proper escaping. These issues arise when developers trust user input or fail to use safe APIs that properly separate data from code.

Impact

Injection vulnerabilities can lead to complete data breaches with theft of sensitive information, authentication bypass and unauthorized access, data manipulation or destruction, remote code execution on application servers, lateral movement to internal systems, denial of service through resource exhaustion, and compliance violations with severe penalties.

Prevention

Prevention varies by scenario, but generally use parameterized queries for database access, avoid string-built SQL, and replace shell commands with secure API calls.

Specific Vulnerabilities

Explore specific vulnerability types within this category:

Detect These Vulnerabilities in Your Code

Sourcery automatically identifies injection & code execution and related vulnerabilities in your codebase.

Scan Your Code for Free