This vulnerability occurs when software validates that a number is within an acceptable range by only checking that it's less than or equal to a maximum value, but fails to also verify that it is greater than or equal to a required minimum. This oversight can allow negative or otherwise invalid low values to pass the check, leading to unexpected behavior.
Developers often use signed data types like integers or floats for values that should logically only be positive or zero. When input validation only enforces an upper limit, a negative value can slip through. This becomes dangerous when that negative number is used in operations like memory allocation, array indexing, or buffer calculations, potentially causing buffer overflows, memory corruption, or application crashes. Beyond memory issues, this flaw can impact application logic in surprising ways. For instance, an e-commerce system that checks 'item count <= 10' but not 'item count >= 0' might process an order for -3 items. This could trigger faulty calculations, like crediting money to an attacker's account instead of charging it. Always validate both the lower and upper bounds to ensure data integrity and security.
Impact: Modify Application DataExecute Unauthorized Code or Commands
An attacker could modify the structure of the message or data being sent to the downstream component, possibly injecting commands.
Impact: DoS: Resource Consumption (Other)
in some contexts, a negative value could lead to resource consumption.
Impact: Modify MemoryRead Memory
If a negative value is used to access memory, buffers, or other indexable structures, it could access memory outside the bounds of the buffer.
Strategy: Enforcement by Conversion
Strategy: Input Validation
ccc
// check that the array index is less than the maximum*
c
cc
// check that the array index is within the correct*
cjava
// variable for bank account balance* private double accountBalance;
java
java
// other methods for accessing the BankAccount object* ...}
java
// method to withdraw amount from BankAccount* public void withdraw(double withdrawAmount) { ``` if (withdrawAmount < MAXIMUM_WITHDRAWAL_LIMIT && withdrawAmount > MINIMUM_WITHDRAWAL_LIMIT) { ...