OWASPTop 10 2021
A03:2021 Injection
- Edition
- OWASP Top 10 2021
- Rank
- 3
- CWEs Mapped
- 33
- Max Incidence Rate
- 19.09%
- Avg Incidence Rate
- 3.37%
- Avg Weighted Exploit
- 7.25
- Avg Weighted Impact
- 7.15
- Max Coverage
- 94.04%
- Avg Coverage
- 47.90%
- Total Occurrences
- 274,228
- Total CVEs
- 32,078
Overview
Injection slides down to the third position. 94% of the applications
were tested for some form of injection with a max incidence rate of 19%, an average incidence rate of 3%, and 274k occurrences. Notable Common Weakness Enumerations (CWEs) included are
*CWE-79: Cross-site Scripting*, *CWE-89: SQL Injection*, and *CWE-73:
External Control of File Name or Path*.
Description
An application is vulnerable to attack when:
• User-supplied data is not validated, filtered, or sanitized by the
application.
• Dynamic queries or non-parameterized calls without context-aware
escaping are used directly in the interpreter.
• Hostile data is used within object-relational mapping (ORM) search
parameters to extract additional, sensitive records.
• Hostile data is directly used or concatenated. The SQL or command
contains the structure and malicious data in dynamic queries,
commands, or stored procedures.
Some of the more common injections are SQL, NoSQL, OS command, Object
Relational Mapping (ORM), LDAP, and Expression Language (EL) or Object
Graph Navigation Library (OGNL) injection. The concept is identical
among all interpreters. Source code review is the best method of
detecting if applications are vulnerable to injections. Automated
testing of all parameters, headers, URL, cookies, JSON, SOAP, and XML
data inputs is strongly encouraged. Organizations can include
static (SAST), dynamic (DAST), and interactive (IAST) application security testing tools into the CI/CD
pipeline to identify introduced injection flaws before production
deployment.
How to Prevent
Preventing injection requires keeping data separate from commands and queries:
• The preferred option is to use a safe API, which avoids using the
interpreter entirely, provides a parameterized interface, or
migrates to Object Relational Mapping Tools (ORMs).
Note: Even when parameterized, stored procedures can still introduce
SQL injection if PL/SQL or T-SQL concatenates queries and data or
executes hostile data with EXECUTE IMMEDIATE or exec().
• Use positive server-side input validation. This is
not a complete defense as many applications require special
characters, such as text areas or APIs for mobile applications.
• For any residual dynamic queries, escape special characters using
the specific escape syntax for that interpreter.
Note: SQL structures such as table names, column names, and so on
cannot be escaped, and thus user-supplied structure names are
dangerous. This is a common issue in report-writing software.
Example Attack Scenarios
Scenario #1: An application uses untrusted data in the construction
of the following vulnerable SQL call:
```
String query = "SELECT \* FROM accounts WHERE custID='" + request.getParameter("id") + "'";
```
Scenario #2: Similarly, an application’s blind trust in frameworks
may result in queries that are still vulnerable, (e.g., Hibernate Query
Language (HQL)):
```
Query HQLQuery = session.createQuery("FROM accounts WHERE custID='" + request.getParameter("id") + "'");
```
In both cases, the attacker modifies the ‘id’ parameter value in their
browser to send: ' UNION SLEEP(10);--. For example:
```
http://example.com/app/accountView?id=' UNION SELECT SLEEP(10);--
```
This changes the meaning of both queries to return all the records from
the accounts table. More dangerous attacks could modify or delete data
or even invoke stored procedures.
References
• OWASP Proactive Controls: Secure Database Access
• OWASP ASVS: V5 Input Validation and Encoding
• OWASP Testing Guide: SQL Injection, Command Injection,
and ORM Injection
• OWASP Cheat Sheet: Injection Prevention
• OWASP Cheat Sheet: SQL Injection Prevention
• OWASP Cheat Sheet: Injection Prevention in Java
• OWASP Cheat Sheet: Query Parameterization
• OWASP Automated Threats to Web Applications – OAT-014
• PortSwigger: Server-side template injection
List of Mapped CWEs
• CWE-20 Improper Input Validation
• CWE-74 Improper Neutralization of Special Elements in Output Used by a
• [CWE-75 Failure to Sanitize Special Elements into a Different Plane
• [CWE-77 Improper Neutralization of Special Elements used in a Command
• [CWE-78 Improper Neutralization of Special Elements used in an OS Command
• [CWE-79 Improper Neutralization of Input During Web Page Generation
• [CWE-80 Improper Neutralization of Script-Related HTML Tags in a Web Page
• [CWE-83 Improper Neutralization of Script in Attributes in a Web Page
• CWE-87 Improper Neutralization of Alternate XSS Syntax
• CWE-88 Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')
• CWE-89 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
• CWE-90 Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection')
• CWE-91 XML Injection (aka Blind XPath Injection)
• CWE-93 Improper Neutralization of CRLF Sequences ('CRLF Injection')
• CWE-94 Improper Control of Generation of Code ('Code Injection')
• CWE-95 Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')
• CWE-96 Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
• CWE-97 Improper Neutralization of Server-Side Includes (SSI) Within a Web Page
• CWE-98 Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion')
• CWE-99 Improper Control of Resource Identifiers ('Resource Injection')
• CWE-100 Deprecated: Was catch-all for input validation issues
• CWE-113 Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting')
• CWE-116 Improper Encoding or Escaping of Output
• CWE-138 Improper Neutralization of Special Elements
• CWE-184 Incomplete List of Disallowed Inputs
• CWE-470 Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')
• CWE-471 Modification of Assumed-Immutable Data (MAID)
• CWE-564 SQL Injection: Hibernate
• CWE-610 Externally Controlled Reference to a Resource in Another Sphere
• CWE-643 Improper Neutralization of Data within XPath Expressions ('XPath Injection')
• CWE-644 Improper Neutralization of HTTP Headers for Scripting Syntax
• CWE-652 Improper Neutralization of Data within XQuery Expressions ('XQuery Injection')
• CWE-917 Improper Neutralization of Special Elements used in an Expression Language Statement ('Expression Language Injection')
Related
Mapped cwe · not in database (1)
Mapped cwe · CWE (33)
- CWE-113 Improper Neutralization of CRLF Sequences in HTTP Headers weakness
- CWE-116 Improper Encoding or Escaping of Output weakness
- CWE-138 Improper Neutralization of Special Elements weakness
- CWE-184 Incomplete List of Disallowed Inputs weakness
- CWE-20 Improper Input Validation weakness
- CWE-470 Use of Externally-Controlled Input to Select Classes or Code weakness
- CWE-471 Modification of Assumed-Immutable Data (MAID) weakness
- CWE-564 Use of Hibernate with HQL/SQL Query String Containing External Input weakness
- CWE-610 Externally Controlled Reference to a Resource in Another Sphere weakness
- CWE-643 Improper Neutralization of Data within XPath Expressions weakness
- CWE-644 Improper Neutralization of HTTP Headers for Scripting Syntax weakness
- CWE-652 Improper Neutralization of Data within XQuery Expressions weakness
- CWE-73 External Control of File Name or Path weakness
- CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component weakness
- CWE-75 Failure to Sanitize Special Elements into a Different Plane weakness
- CWE-77 Improper Neutralization of Special Elements used in a Command weakness
- CWE-78 Improper Neutralization of Special Elements used in an OS Command weakness
- CWE-79 Improper Neutralization of Input During Web Page Generation weakness
- CWE-80 Improper Neutralization of Script-Related HTML Tags in a Web Page weakness
- CWE-83 Improper Neutralization of Script in Attributes in a Web Page weakness
- CWE-87 Improper Neutralization of Alternate XSS Syntax weakness
- CWE-88 Improper Neutralization of Argument Delimiters in a Command weakness
- CWE-89 Improper Neutralization of Special Elements used in an SQL Command weakness
- CWE-90 Improper Neutralization of Special Elements used in an LDAP Query weakness
- CWE-91 XML Injection weakness
- CWE-917 Improper Neutralization of Special Elements used in an Expression Language Statement weakness
- CWE-93 Improper Neutralization of CRLF Sequences weakness
- CWE-94 Improper Control of Generation of Code weakness
- CWE-95 Improper Neutralization of Directives in Dynamically Evaluated Code weakness
- CWE-96 Improper Neutralization of Directives in Statically Saved Code weakness
Cheat sheet · OWASP (3)
- CS-Injection_Prevention Injection Prevention Cheat Sheet Cheat Sheet
- CS-Query_Parameterization Query Parameterization Cheat Sheet Cheat Sheet
- CS-SQL_Injection_Prevention SQL Injection Prevention Cheat Sheet Cheat Sheet