Improper Validation of Specified Quantity in Input

Incomplete Base
Structure: Simple
Description

The product receives input that is expected to specify a quantity (such as size or length), but it does not validate or incorrectly validates that the quantity has the required properties.

Extended Description

Specified quantities include size, length, frequency, price, rate, number of operations, time, and others. Code may rely on specified quantities to allocate resources, perform calculations, control iteration, etc. When the quantity is not properly validated, then attackers can specify malicious quantities to cause excessive resource allocation, trigger unexpected failures, enable buffer overflows, etc.

Common Consequences 1
Scope: Other

Impact: Varies by Context

Since quantities are used so often to affect resource allocation or process financial data, they are often present in many places in the code.

Potential Mitigations 1
Phase: Implementation

Strategy: Input Validation

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 because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.

Effectiveness: High

Demonstrative Examples 2

ID : DX-135

This example demonstrates a shopping interaction in which the user is free to specify the quantity of items to be purchased and a total is calculated.

Code Example:

Bad
Java
java
The user has no control over the price variable, however the code does not prevent a negative value from being specified for quantity. If an attacker were to provide a negative value, then the user would have their account credited instead of debited.

ID : DX-136

This example asks the user for a height and width of an m X n game board with a maximum dimension of 100 squares.

Code Example:

Bad
C
c

/* board dimensions /

c
While this code checks to make sure the user cannot specify large, positive integers and consume too much memory, it does not check for negative values supplied by the user. As a result, an attacker can perform a resource consumption (Uncontrolled Resource Consumption) attack against this program by specifying two, large negative values that will not overflow, resulting in a very large memory allocation (Memory Allocation with Excessive Size Value) and possibly a system crash. Alternatively, an attacker can provide very large negative values which will cause an integer overflow (Integer Overflow or Wraparound) and unexpected behavior will follow depending on how the values are treated in the remainder of the program.
Observed Examples 3
CVE-2019-19911Chain: Python library does not limit the resources used to process images that specify a very large number of bands (Improper Validation of Specified Quantity in Input), leading to excessive memory consumption (Memory Allocation with Excessive Size Value) or an integer overflow (Integer Overflow or Wraparound).
CVE-2008-1440lack of validation of length field leads to infinite loop
CVE-2008-2374lack of validation of string length fields allows memory consumption or buffer over-read
Applicable Platforms
Languages:
Not Language-Specific : Often
Modes of Introduction
Implementation
Notes
MaintenanceThis entry is still under development and will continue to see updates and content improvements.