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.
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.
Potential Impact
Other, Integrity, Availability
Varies by Context, DoS: Resource Consumption (CPU), Modify Memory, Read Memory
Demonstrative Examples
...public static final double price = 20.00;int quantity = currentUser.getAttribute("quantity");double total = price * quantity;chargeUser(total);......#define MAX_DIM 100...
/* board dimensions */
int m,n, error;board_square_t *board;printf("Please specify the board height: \n");error = scanf("%d", &m);if ( EOF == error ){die("No integer passed: Die evil hacker!\n");}printf("Please specify the board width: \n");error = scanf("%d", &n);if ( EOF == error ){die("No integer passed: Die evil hacker!\n");}if ( m > MAX_DIM || n > MAX_DIM ) {die("Value too large: Die evil hacker!\n");}board = (board_square_t*) malloc( m * n * sizeof(board_square_t));...name: Deploy Preview
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 'Download artifact'
uses: actions/github-script
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchPrArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var downloadPr = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchPrArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(downloadPr.data));
- run: |
unzip pr.zip
echo "pr_number=$(cat NR)" >> $GITHUB_ENV\nNODE_OPTIONS="--experimental-modules --experiments-loader=data:text/javascript,console.log('injected code');//"The code could be modified to validate that the NR
file only contains a numeric value, or the code could
retrieve the PR number from a more trusted source.$discount = $_POST['discount'];
$originalPrice = 100.00;
$finalPrice = $originalPrice - ($originalPrice * $discount / 100);
processPayment($finalPrice);$original_price = 100.00;
$allowed_discounts = [0, 10, 20, 50]; // only these discounts are valid
$discount = (int) ($_POST['discount'] ?? 0);
if (!in_array($discount, $allowed_discounts, true)) {
http_response_code(400);
exit('Invalid discount.');
}
$final_price = $original_price - ($original_price * $discount / 100);
if ($final_price <= 0) {
http_response_code(400);
exit('Invalid final price.');
}
processPayment($final_price);Mitigations & Prevention
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 relat
Detection Methods
- Automated Static Analysis — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2025-4037 | ATM simulator does not check for negative values with deposits or withdrawals, allowing attackers to increase their balance |
| CVE-2025-46687 | Chain: Javascript engine code does not perform a length check (CWE-1284) leading to integer overflow (CWE-190) causing allocation of smaller buffer than expected (CWE-131) resulting in a heap-based bu |
| CVE-2019-19911 | Chain: Python library does not limit the resources used to process images that specify a very large number of bands (CWE-1284), leading to excessive memory consumption (CWE-789) or an integer overflow |
| CVE-2008-1440 | lack of validation of length field leads to infinite loop |
| CVE-2008-2374 | lack of validation of string length fields allows memory consumption or buffer over-read |
Related Weaknesses
Frequently Asked Questions
What is CWE-1284?
CWE-1284 (Improper Validation of Specified Quantity in Input) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. 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.
How can CWE-1284 be exploited?
Attackers can exploit CWE-1284 (Improper Validation of Specified Quantity in Input) to varies by context, dos: resource consumption (cpu), modify memory, read memory. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-1284?
Key mitigations include: 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 stric
What is the severity of CWE-1284?
CWE-1284 is classified as a Base-level weakness (Medium abstraction). It has been observed in 5 real-world CVEs.