CWE-1285 Base Incomplet

Improper Validation of Specified Index, Position, or Offset in Input

This vulnerability occurs when software accepts user input to determine a location—like an array index, file position, or memory offset—but fails to properly check if that location is safe and valid…

Définition

What is CWE-1285?

This vulnerability occurs when software accepts user input to determine a location—like an array index, file position, or memory offset—but fails to properly check if that location is safe and valid before using it.
Many software resources, like arrays in memory or files on disk, are accessed using numerical positions. When an application trusts user-supplied numbers for these positions without rigorous checks, attackers can supply crafted values that point outside the intended boundaries. This can lead directly to severe consequences like reading or corrupting adjacent memory (buffer overflows), forcing the allocation of huge amounts of resources, or causing the application to crash. To prevent this, developers must treat all input that defines a position as untrusted. Always validate that the specified index or offset falls within the exact, current bounds of the target resource before any access is performed. Implementing strict range checking is a critical first line of defense to ensure the software only interacts with authorized sections of data.
Impact réel

Real-world CVEs caused by CWE-1285

Comment les attaquants l'exploitent

Parcours de l'attaquant étape par étape

  1. 1

    The following example retrieves the sizes of messages for a pop3 mail server. The message sizes are retrieved from a socket that returns in a buffer the message number and the message size, the message number (num) and size (size) are extracted from the buffer and the message size is placed into an array using the message number for the array index.

  2. 2

    In this example the message number retrieved from the buffer could be a value that is outside the allowable range of indices for the array and could possibly be a negative number. Without proper validation of the value to be used for the array index an array overflow could occur and could potentially lead to unauthorized access to memory addresses and system crashes. The value of the array index should be validated to ensure that it is within the allowable range of indices for the array as in the following code.

  3. 3

    In the following example the method displayProductSummary is called from a Web service servlet to retrieve product summary information for display to the user. The servlet obtains the integer value of the product number from the user and passes it to the displayProductSummary method. The displayProductSummary method passes the integer value of the product number to the getProductSummary method which obtains the product summary from the array object containing the project summaries using the integer value of the product number as the array index.

  4. 4

    In this example the integer value used as the array index that is provided by the user may be outside the allowable range of indices for the array which may provide unexpected results or cause the application to fail. The integer value used for the array index should be validated to ensure that it is within the allowable range of indices for the array as in the following code.

  5. 5

    An alternative in Java would be to use one of the collection objects such as ArrayList that will automatically generate an exception if an attempt is made to access an array index that is out of bounds.

Exemple de code vulnérable

Vulnerable C

The following example retrieves the sizes of messages for a pop3 mail server. The message sizes are retrieved from a socket that returns in a buffer the message number and the message size, the message number (num) and size (size) are extracted from the buffer and the message size is placed into an array using the message number for the array index.

Vulnérable C
```
/* 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;
  		}
  			...
  }
Exemple de code sécurisé

Secure C

In this example the message number retrieved from the buffer could be a value that is outside the allowable range of indices for the array and could possibly be a negative number. Without proper validation of the value to be used for the array index an array overflow could occur and could potentially lead to unauthorized access to memory addresses and system crashes. The value of the array index should be validated to ensure that it is within the allowable range of indices for the array as in the following code.

Sécurisé C
```
/* 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");}}
  		```
  			...
  }
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Liste de contrôle de prévention

How to prevent CWE-1285

  • Implementation 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.
Signaux de détection

How to detect CWE-1285

SAST High

Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.

DAST Moderate

Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.

Runtime Moderate

Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.

Code review Moderate

Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.

Correction automatique Plexicus

Plexicus détecte automatiquement CWE-1285 et ouvre une PR de correction en moins de 60 secondes.

Codex Remedium analyse chaque commit, identifie cette faiblesse précise et livre une pull request prête à être relue avec le correctif. Pas de tickets. Pas de transferts.

Questions fréquentes

Frequently asked questions

Qu'est-ce que CWE-1285 ?

This vulnerability occurs when software accepts user input to determine a location—like an array index, file position, or memory offset—but fails to properly check if that location is safe and valid before using it.

Quelle est la gravité de CWE-1285 ?

MITRE n'a pas publié de note de probabilité d'exploitation pour cette faiblesse. Traitez-la comme un impact moyen jusqu'à ce que votre modèle de menace prouve le contraire.

Quels langages ou plateformes sont affectés par CWE-1285 ?

MITRE n'a pas spécifié les plateformes affectées pour ce CWE — il peut s'appliquer à la plupart des stacks applicatives.

Comment puis-je prévenir CWE-1285 ?

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…

Comment Plexicus détecte et corrige CWE-1285 ?

Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-1285 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.

Où puis-je en savoir plus sur CWE-1285 ?

MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/1285.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.

Faiblesses associées

Weaknesses related to CWE-1285

CWE-20 Parent

Improper Input Validation

This vulnerability occurs when an application accepts data from an external source but fails to properly verify that the data is safe and…

CWE-102 Frère

Struts: Duplicate Validation Forms

This vulnerability occurs when an application defines multiple Struts validation forms with identical names. The framework then…

CWE-103 Frère

Struts: Incomplete validate() Method Definition

This vulnerability occurs in a Struts application when a validator form either completely omits a validate() method or includes one but…

CWE-104 Frère

Struts: Form Bean Does Not Extend Validation Class

This vulnerability occurs in Apache Struts applications when a form bean class does not properly extend the framework's validation class.…

CWE-105 Frère

Struts: Form Field Without Validator

This vulnerability occurs when a Struts application form contains an input field that lacks a corresponding validator, leaving it open to…

CWE-106 Frère

Struts: Plug-in Framework not in Use

This weakness occurs when a Java application, particularly one using the Struts framework, does not implement a structured input…

CWE-107 Frère

Struts: Unused Validation Form

This vulnerability occurs when a Struts application contains validation form definitions that are no longer linked to any active form or…

CWE-108 Frère

Struts: Unvalidated Action Form

In Apache Struts, every Action Form that processes user input must have a corresponding validation form configured. Missing this…

CWE-109 Frère

Struts: Validator Turned Off

This vulnerability occurs when an application built with Apache Struts intentionally disables its built-in validation framework. By…

Prêt quand vous l'êtes

Arrêtez de payer par développeur.
Commencez à fermer la boucle.

Plexicus est l'ASPM natif IA qui scanne, filtre, corrige, penteste et explique — de façon autonome. Développeurs illimités, dépôts illimités, actions IA à usage équitable. Vrai niveau gratuit, €269/mo annuel quand vous êtes prêt.