CWE-471 – Modification of Assumed-Immutable Data (MAID)

Read Time:53 Second

Description

The software does not properly protect an assumed-immutable element from being modified by an attacker.

This occurs when a particular input is critical enough to the functioning of the application that it should not be modifiable at all, but it is. Certain resources are often assumed to be immutable when they are not, such as hidden form fields in web applications, cookies, and reverse DNS lookups.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-664

 

Consequences

Integrity: Modify Application Data

Common data types that are attacked are environment variables, web application parameters, and HTTP headers.

Integrity: Unexpected State

 

Potential Mitigations

Phase: Architecture and Design, Operation, Implementation

Description: 

When the data is stored or transmitted through untrusted sources that could modify the data, implement integrity checks to detect unauthorized modification, or store/transmit the data in a trusted location that is free from external influence.

CVE References

  • CVE-2005-1905
    • Gain privileges by modifying assumed-immutable code addresses that are accessed by a driver.

CWE-470 – Use of Externally-Controlled Input to Select Classes or Code (‘Unsafe Reflection’)

Read Time:1 Minute, 50 Second

Description

The application uses external input with reflection to select which classes or code to use, but it does not sufficiently prevent the input from selecting improper classes or code.

If the application uses external inputs to determine which class to instantiate or which method to invoke, then an attacker could supply values to select unexpected classes or methods. If this occurs, then the attacker could create control flow paths that were not intended by the developer. These paths could bypass authentication or access control checks, or otherwise cause the application to behave in an unexpected manner. This situation becomes a doomsday scenario if the attacker can upload files into a location that appears on the application’s classpath (CWE-427) or add new entries to the application’s classpath (CWE-426). Under either of these conditions, the attacker can use reflection to introduce new, malicious behavior into the application.

Modes of Introduction:

– Architecture and Design

 

 

Related Weaknesses

CWE-913
CWE-913
CWE-610
CWE-20

 

Consequences

Integrity, Confidentiality, Availability, Other: Execute Unauthorized Code or Commands, Alter Execution Logic

The attacker might be able to execute code that is not directly accessible to the attacker. Alternately, the attacker could call unexpected code in the wrong place or the wrong time, possibly modifying critical system state.

Availability, Other: DoS: Crash, Exit, or Restart, Other

The attacker might be able to use reflection to call the wrong code, possibly with unexpected arguments that violate the API (CWE-227). This could cause the application to exit or hang.

Confidentiality: Read Application Data

By causing the wrong code to be invoked, the attacker might be able to trigger a runtime error that leaks sensitive information in the error message, such as CWE-536.

 

Potential Mitigations

Phase: Architecture and Design

Description: 

Refactor your code to avoid using reflection.

Phase: Architecture and Design

Description: 

Do not use user-controlled inputs to select and load classes or code.

Phase: Implementation

Description: 

Apply strict input validation by using allowlists or indirect selection to ensure that the user is only selecting allowable classes or code.

CVE References

  • CVE-2004-2331
    • Database system allows attackers to bypass sandbox restrictions by using the Reflection APi.

CWE-47 – Path Equivalence: ‘ filename’ (Leading Space)

Read Time:20 Second

Description

A software system that accepts path input in the form of leading space (‘ filedir’) without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-41

 

Consequences

Confidentiality, Integrity: Read Files or Directories, Modify Files or Directories

 

Potential Mitigations

CVE References

CWE-469 – Use of Pointer Subtraction to Determine Size

Read Time:40 Second

Description

The application subtracts one pointer from another in order to determine size, but this calculation can be incorrect if the pointers do not exist in the same memory chunk.

Modes of Introduction:

– Implementation

 

Likelihood of Exploit: Medium

 

Related Weaknesses

CWE-682

 

Consequences

Access Control, Integrity, Confidentiality, Availability: Modify Memory, Read Memory, Execute Unauthorized Code or Commands, Gain Privileges or Assume Identity

There is the potential for arbitrary code execution with privileges of the vulnerable program.

 

Potential Mitigations

Phase: Implementation

Description: 

Save an index variable. This is the recommended solution. Rather than subtract pointers from one another, use an index variable of the same size as the pointers in question. Use this variable to “walk” from one pointer to the other and calculate the difference. Always validate this number.

CVE References

CWE-468 – Incorrect Pointer Scaling

Read Time:35 Second

Description

In C and C++, one may often accidentally refer to the wrong memory due to the semantics of when math operations are implicitly scaled.

Modes of Introduction:

– Implementation

 

Likelihood of Exploit: Medium

 

Related Weaknesses

CWE-682

 

Consequences

Confidentiality, Integrity: Read Memory, Modify Memory

Incorrect pointer scaling will often result in buffer overflow conditions. Confidentiality can be compromised if the weakness is in the context of a buffer over-read or under-read.

 

Potential Mitigations

Phase: Architecture and Design

Description: 

Use a platform with high-level memory abstractions.

Phase: Implementation

Description: 

Always use array indexing instead of direct pointer manipulation.

Phase: Architecture and Design

Description: 

Use technologies for preventing buffer overflows.

CVE References

CWE-467 – Use of sizeof() on a Pointer Type

Read Time:49 Second

Description

The code calls sizeof() on a malloced pointer type, which always returns the wordsize/8. This can produce an unexpected result if the programmer intended to determine how much memory has been allocated.

The use of sizeof() on a pointer can sometimes generate useful information. An obvious case is to find out the wordsize on a platform. More often than not, the appearance of sizeof(pointer) indicates a bug.

Modes of Introduction:

– Implementation

 

Likelihood of Exploit: High

 

Related Weaknesses

CWE-682
CWE-131

 

Consequences

Integrity, Confidentiality: Modify Memory, Read Memory

This error can often cause one to allocate a buffer that is much smaller than what is needed, leading to resultant weaknesses such as buffer overflows.

 

Potential Mitigations

Phase: Implementation

Description: 

Use expressions such as “sizeof(*pointer)” instead of “sizeof(pointer)”, unless you intend to run sizeof() on a pointer type to gain some platform independence or if you are allocating a variable on the stack.

CVE References

CWE-464 – Addition of Data Structure Sentinel

Read Time:1 Minute, 6 Second

Description

The accidental addition of a data-structure sentinel can cause serious programming logic problems.

Data-structure sentinels are often used to mark the structure of data. A common example of this is the null character at the end of strings or a special sentinel to mark the end of a linked list. It is dangerous to allow this type of control data to be easily accessible. Therefore, it is important to protect from the addition or modification of sentinels.

Modes of Introduction:

– Architecture and Design

 

Likelihood of Exploit: High

 

Related Weaknesses

CWE-138

 

Consequences

Integrity: Modify Application Data

Generally this error will cause the data structure to not work properly by truncating the data.

 

Potential Mitigations

Phase: Implementation, Architecture and Design

Description: 

Encapsulate the user from interacting with data sentinels. Validate user input to verify that sentinels are not present.

Phase: Implementation

Description: 

Proper error checking can reduce the risk of inadvertently introducing sentinel values into data. For example, if a parsing function fails or encounters an error, it might return a value that is the same as the sentinel.

Phase: Architecture and Design

Description: 

Use an abstraction library to abstract away risky APIs. This is not a complete solution.

Phase: Operation

Description: 

Use OS-level preventative functionality. This is not a complete solution.

CVE References

CWE-463 – Deletion of Data Structure Sentinel

Read Time:1 Minute, 7 Second

Description

The accidental deletion of a data-structure sentinel can cause serious programming logic problems.

Often times data-structure sentinels are used to mark structure of the data structure. A common example of this is the null character at the end of strings. Another common example is linked lists which may contain a sentinel to mark the end of the list. It is dangerous to allow this type of control data to be easily accessible. Therefore, it is important to protect from the deletion or modification outside of some wrapper interface which provides safety.

Modes of Introduction:

– Architecture and Design

 

 

Related Weaknesses

CWE-707
CWE-464

 

Consequences

Availability, Other: Other

Generally this error will cause the data structure to not work properly.

Authorization, Other: Other

If a control character, such as NULL is removed, one may cause resource access control problems.

 

Potential Mitigations

Phase: Architecture and Design

Description: 

Use an abstraction library to abstract away risky APIs. Not a complete solution.

Phase: Build and Compilation

Effectiveness: Defense in Depth

Description: 

This is not necessarily a complete solution, since these mechanisms can only detect certain types of overflows. In addition, an attack could still cause a denial of service, since the typical response is to exit the application.

Phase: Operation

Description: 

Use OS-level preventative functionality. Not a complete solution.

CVE References

CWE-462 – Duplicate Key in Associative List (Alist)

Read Time:38 Second

Description

Duplicate keys in associative lists can lead to non-unique keys being mistaken for an error.

A duplicate key entry — if the alist is designed properly — could be used as a constant time replace function. However, duplicate key entries could be inserted by mistake. Because of this ambiguity, duplicate key entries in an association list are not recommended and should not be allowed.

Modes of Introduction:

– Architecture and Design

 

Likelihood of Exploit: Low

 

Related Weaknesses

CWE-694

 

Consequences

Other: Quality Degradation, Varies by Context

 

Potential Mitigations

Phase: Architecture and Design

Description: 

Use a hash table instead of an alist.

Phase: Architecture and Design

Description: 

Use an alist which checks the uniqueness of hash keys with each entry before inserting the entry.

CVE References