CWE-20: Improper Input Validation
Description
The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly.
- Abstraction
- ClassAn abstract weakness, independent of any specific language or technology.
- Likelihood of exploit
- High
- Status
- Stable
Common consequences
- Availability
DoS: Crash, Exit, or Restart; DoS: Resource Consumption (CPU); DoS: Resource Consumption (Memory)
An attacker could provide unexpected values and cause a program crash or arbitrary control of resource allocation, leading to excessive consumption of resources such as memory and CPU.
- Confidentiality
Read Memory; Read Files or Directories
An attacker could read confidential data if they are able to control resource references.
- IntegrityConfidentialityAvailability
Modify Memory; Execute Unauthorized Code or Commands
An attacker could use malicious input to modify data or possibly alter control flow in unexpected ways, including arbitrary command execution.
Potential mitigations
- Architecture and DesignAttack Surface Reduction
Consider using language-theoretic security (LangSec) techniques that characterize inputs using a formal language and build recognizers for that language. This effectively requires parsing to be a distinct layer that effectively enforces a boundary between raw input and internal data representations, instead of allowing parser code to be scattered throughout the program, where it could be subject to errors or inconsistencies that create weaknesses.
- Architecture and DesignLibraries or Frameworks
Use an input validation framework such as Struts or the OWASP ESAPI Validation API. Note that using a framework does not automatically address all input validation problems; be mindful of weaknesses that could arise from misusing the framework itself (CWE-1173).
- Architecture and DesignImplementationAttack Surface Reduction
Understand all the potential areas where untrusted inputs can enter the product, including but not limited to: parameters or arguments, cookies, anything read from the network, environment variables, reverse DNS lookups, query results, request headers, URL components, e-mail, files, filenames, databases, and any external systems that provide data to the application. Remember that such inputs may be obtained indirectly through API calls.
- ImplementationInput ValidationEffectiveness: High
Assume all input is malicious. Use an accept known good input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, boat may be syntactically valid...
- Architecture and Design
For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server. Even though client-side checks provide minimal benefits with respect to server-side security, they are still useful. First, they can support intrusion detection. If the server receives input that should have been...
- Implementation
When your application combines data from multiple sources, perform the validation after the sources have been combined. The individual data elements may pass the validation step but violate the intended restrictions after they have been combined.
- Implementation
Be especially careful to validate all input when invoking code that crosses language boundaries, such as from an interpreted language to native code. This could create an unexpected interaction between the language boundaries. Ensure that you are not violating any of the expectations of the language with which you are interfacing. For example, even though Java may not be susceptible to buffer overflows, providing a large argument in a call to native code might trigger an overflow.
- Implementation
Directly convert your input type into the expected data type, such as using a conversion function that translates a string into a number. After converting to the expected data type, ensure that the input's values fall within the expected range of allowable values and that multi-field consistencies are maintained.
MITRE lists 2 more mitigations on the official entry.
Related weaknesses
Parent weaknesses
Child weaknesses
- CWE-179Incorrect Behavior Order: Early Validation
- CWE-622Improper Validation of Function Hook Arguments
- CWE-1173Improper Use of Validation Framework
- CWE-1284Improper Validation of Specified Quantity in Input
- CWE-1285Improper Validation of Specified Index, Position, or Offset in Input
- CWE-1286Improper Validation of Syntactic Correctness of Input
- CWE-1287Improper Validation of Specified Type of Input
- CWE-1288Improper Validation of Consistency within Input
- CWE-1289Improper Validation of Unsafe Equivalence in Input
Can lead to
- CWE-22Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
- CWE-41Improper Resolution of Path Equivalence
- CWE-74Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
- CWE-119Improper Restriction of Operations within the Bounds of a Memory Buffer
- CWE-770Allocation of Resources Without Limits or Throttling
CAPEC attack patterns that exploit it
- CAPEC-3Using Leading 'Ghost' Character Sequences to Bypass Input Filters
- CAPEC-7Blind SQL Injection
- CAPEC-8Buffer Overflow in an API Call
- CAPEC-9Buffer Overflow in Local Command-Line Utilities
- CAPEC-10Buffer Overflow via Environment Variables
- CAPEC-13Subverting Environment Variable Values
- CAPEC-14Client-side Injection-induced Buffer Overflow
- CAPEC-22Exploiting Trust in Client
- CAPEC-23File Content Injection
- CAPEC-24Filter Failure through Buffer Overflow
- CAPEC-28Fuzzing
- CAPEC-31Accessing/Intercepting/Modifying HTTP Cookies
- CAPEC-42MIME Conversion
- CAPEC-43Exploiting Multiple Input Interpretation Layers
- CAPEC-45Buffer Overflow via Symbolic Links
- CAPEC-46Overflow Variables and Tags
- CAPEC-47Buffer Overflow via Parameter Expansion
- CAPEC-52Embedding NULL Bytes
- CAPEC-53Postfix, Null Terminate, and Backslash
- CAPEC-63Cross-Site Scripting (XSS)
- CAPEC-64Using Slashes and URL Encoding Combined to Bypass Validation Logic
- CAPEC-67String Format Overflow in syslog()
- CAPEC-71Using Unicode Encoding to Bypass Validation Logic
- CAPEC-72URL Encoding
- CAPEC-73User-Controlled Filename
- CAPEC-78Using Escaped Slashes in Alternate Encoding
- CAPEC-79Using Slashes in Alternate Encoding
- CAPEC-80Using UTF-8 Encoding to Bypass Validation Logic
- CAPEC-81Web Server Logs Tampering
- CAPEC-83XPath Injection
- CAPEC-85AJAX Footprinting
- CAPEC-88OS Command Injection
- CAPEC-101Server Side Include (SSI) Injection
- CAPEC-104Cross Zone Scripting
- CAPEC-108Command Line Execution through SQL Injection
- CAPEC-109Object Relational Mapping Injection
- CAPEC-110SQL Injection through SOAP Parameter Tampering
- CAPEC-120Double Encoding
- CAPEC-135Format String Injection
- CAPEC-136LDAP Injection
- CAPEC-153Input Data Manipulation
- CAPEC-182Flash Injection
- CAPEC-209XSS Using MIME Type Mismatch
- CAPEC-230Serialized Data with Nested Payloads
- CAPEC-231Oversized Serialized Data Payloads
- CAPEC-250XML Injection
- CAPEC-261Fuzzing for garnering other adjacent user/sensitive data
- CAPEC-267Leverage Alternate Encoding
- CAPEC-473Signature Spoof
- CAPEC-588DOM-Based XSS
- CAPEC-664Server Side Request Forgery