Description
The product receives input that is expected to specify an index, position, or offset into an indexable resource such as a buffer or file, but it does not validate or incorrectly validates that the specified index/position/offset has the required properties.
Often, indexable resources such as memory buffers or files can be accessed using a specific position, index, or offset, such as an index for an array or a position for a file. When untrusted input is not properly validated before it is used as an index, attackers could access (or attempt to access) unauthorized portions of these resources. This could be used to cause buffer overflows, excessive resource allocation, or trigger unexpected failures.
Potential Impact
Other
Varies by Context
Demonstrative Examples
/* capture the sizes of all messages */
int getsizes(int sock, int count, int *sizes) {
...char buf[BUFFER_SIZE];int ok;int num, size;
// read values from socket and added to sizes array
while ((ok = gen_recv(sock, buf, sizeof(buf))) == 0){
// continue read from socket until buf only contains '.'
if (DOTLINE(buf))break;
else if (sscanf(buf, "%d %d", &num, &size) == 2)sizes[num - 1] = size;
}...
}/* capture the sizes of all messages */
int getsizes(int sock, int count, int *sizes) {
...char buf[BUFFER_SIZE];int ok;int num, size;
// read values from socket and added to sizes array
while ((ok = gen_recv(sock, buf, sizeof(buf))) == 0){
// continue read from socket until buf only contains '.'
if (DOTLINE(buf))break;
else if (sscanf(buf, "%d %d", &num, &size) == 2) {
if (num > 0 && num <= (unsigned)count)sizes[num - 1] = size;
else
/* warn about possible attempt to induce buffer overflow */
report(stderr, "Warning: ignoring bogus data for message sizes returned by server.\n");
}
}...
}// Method called from servlet to obtain product information
public String displayProductSummary(int index) {
String productSummary = new String("");
try {String productSummary = getProductSummary(index);
} catch (Exception ex) {...}
return productSummary;
}
public String getProductSummary(int index) {return products[index];}// Method called from servlet to obtain product information
public String displayProductSummary(int index) {
String productSummary = new String("");
try {String productSummary = getProductSummary(index);
} catch (Exception ex) {...}
return productSummary;
}
public String getProductSummary(int index) {
String productSummary = "";
if ((index >= 0) && (index < MAX_PRODUCTS)) {productSummary = products[index];}else {System.err.println("index is out of bounds");throw new IndexOutOfBoundsException();}
return productSummary;
}ArrayList productArray = new ArrayList(MAX_PRODUCTS);...try {productSummary = (String) productArray.get(index);} catch (IndexOutOfBoundsException ex) {...}int main (int argc, char **argv) {char *items[] = {"boat", "car", "truck", "train"};int index = GetUntrustedOffset();printf("User selected %s\n", items[index-1]);}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 High — 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-2005-0369 | large ID in packet used as array index |
| CVE-2001-1009 | negative array index as argument to POP LIST command |
Related Weaknesses
Frequently Asked Questions
What is CWE-1285?
CWE-1285 (Improper Validation of Specified Index, Position, or Offset 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 an index, position, or offset into an indexable resource such as a buffer or file, but it does not validate or incorrectly validates that the spe...
How can CWE-1285 be exploited?
Attackers can exploit CWE-1285 (Improper Validation of Specified Index, Position, or Offset in Input) to varies by context. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-1285?
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-1285?
CWE-1285 is classified as a Base-level weakness (Medium abstraction). It has been observed in 2 real-world CVEs.