CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes

Description:
The product receives input from an upstream component that specifies multiple attributes, properties, or fields that are to be initialized or updated in an object, but it does not properly control which attributes can be modified.

Extended Description:
If the object contains attributes that were only intended for internal use, then their unexpected modification could lead to a vulnerability. 
             This weakness is sometimes known by the language-specific mechanisms that make it possible, such as mass assignment, autobinding, or object injection.

Affected languages: Ruby, ASP.NET, PHP, Python, Not Language-Specific
Affected technologies: Not Technology-Specific
Parent weaknesses: CWE-913

Consequences:
  - Integrity: Modify Application Data
  - Integrity: Execute Unauthorized Code or Commands
  - Other: Varies by Context

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 havin

Mitigations:
  - [Implementation] If available, use features of the language or framework that allow specification of allowlists of attributes or fields that are allowed to be modified. If possible, prefer allowlists over denylists. 
                   For applications written with Ruby on Rails, use the attr_accessible (allowlist) 
  - [Architecture and Design] If available, use the signing/sealing features of the programming language to assure that deserialized data has not been tainted. For example, a hash-based message authentication code (HMAC) could be used to ensure that data has not been modified.
  - [Implementation] For any externally-influenced input, check the input against an allowlist of internal object attributes or fields that are allowed to be modified.
  - [Implementation] Refactor the code so that object attributes or fields do not need to be dynamically identified, and only expose getter/setter functionality for the intended attributes.

Demonstrative examples:
This function sets object attributes based on a dot-separated path.
This function does not check if the attribute resolves to the object prototype. These codes can be used to add "isAdmin: true" to the object prototype.
function setValueByPath (object, path, value) { 
	        
		 const pathArray = path.split("."); 
		 const attributeToSet = pathArray.pop(); 
		 let objectToModify = object; 
		 for (const attr of pathArray) { 
		  if (typeof objectToModify[attr] !== 'object') { 
		  objectToModify[attr] = {}; 
		 } 
		 objectToModify = objectToModify[attr]; 
		 } 
		 objectToModify[attributeToSet] = value; 
		 return object; 
		 }
setValueByPath({}, "__proto__.isAdmin", true) 
		 setValueByPath({}, "constructor.prototype.isAdmin", true)

Real-world examples:
  - CVE-2024-3283: Application for using LLMs allows modification of a sensitive variable using mass assignment.
  - CVE-2012-2054: Mass assignment allows modification of arbitrary attributes using modified URL.
  - CVE-2012-2055: Source version control product allows modification of trusted key using mass assignment.
  - CVE-2008-7310: Attackers can bypass payment step in e-commerce product.
  - CVE-2013-1465: Use of PHP unserialize function on untrusted input allows attacker to modify application configuration.