CWE-1321 Variante Incompleto

Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')

Prototype pollution occurs when an application takes user-supplied input and uses it to improperly modify the properties of a JavaScript object's prototype. This allows attackers to inject key-value…

Definición

What is CWE-1321?

Prototype pollution occurs when an application takes user-supplied input and uses it to improperly modify the properties of a JavaScript object's prototype. This allows attackers to inject key-value pairs into the base object, potentially altering the application's logic, crashing it, or escalating privileges.
This vulnerability typically arises in JavaScript when functions like `Object.assign()`, `merge()`, or `deepClone()` recursively combine objects without properly validating the source keys. Attackers can send crafted input containing special keys like `__proto__` or `constructor.prototype`. If this input is merged unsafely, the polluted properties are added to the global prototype chain, affecting every object that inherits from it. To prevent prototype pollution, developers should adopt security-focused practices. These include using objects without prototypes (e.g., `Object.create(null)`), employing safe merge functions that reject prototype-related keys, and validating all external input before processing. Freezing the `Object.prototype` in critical environments can also serve as a defensive measure against this type of attack.
Vulnerability Diagram CWE-1321
Prototype Pollution Attacker JSON { "__proto__": { "isAdmin": true } } Object.prototype deepMerge(obj, input) ↓ writes to __proto__ isAdmin = true on the prototype → inherited by every {} Every object o.isAdmin === true auth bypass / RCE Writing to __proto__ taints every object that inherits from Object.prototype.
Impacto en el mundo real

Real-world CVEs caused by CWE-1321

  • Prototype pollution by merging objects.

  • Prototype pollution by setting default values to object attributes recursively.

  • Prototype pollution by merging objects recursively.

  • Prototype pollution by setting object attributes based on dot-separated path.

Cómo lo explotan los atacantes

Ruta del atacante paso a paso

  1. 1

    This function sets object attributes based on a dot-separated path.

  2. 2

    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.

  3. 3

    By using a denylist of dangerous attributes, this weakness can be eliminated.

Ejemplo de código vulnerable

Vulnerable JavaScript

This function sets object attributes based on a dot-separated path.

Vulnerable JavaScript
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;
  	 }
Ejemplo de código seguro

Secure JavaScript

By using a denylist of dangerous attributes, this weakness can be eliminated.

Seguro JavaScript
function setValueByPath (object, path, value) {
  	 const pathArray = path.split(".");
  	 const attributeToSet = pathArray.pop();
  	 let objectToModify = object;
  	 for (const attr of pathArray) {
```
// Ignore attributes which resolve to object prototype* 
  		 if (attr === "__proto__" || attr === "constructor" || attr === "prototype") {
  		
  		```
  			 continue;
  			 }
  		 if (typeof objectToModify[attr] !== "object") {
  			 objectToModify[attr] = {};
  			 }
  		 objectToModify = objectToModify[attr];
  		 }
  	 objectToModify[attributeToSet] = value;
  	 return object;
  	 }
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Lista de prevención

How to prevent CWE-1321

  • Implementation By freezing the object prototype first (for example, Object.freeze(Object.prototype)), modification of the prototype becomes impossible.
  • Architecture and Design By blocking modifications of attributes that resolve to object prototype, such as proto or prototype, this weakness can be mitigated.
  • Implementation When handling untrusted objects, validating using a schema can be used.
  • Implementation By using an object without prototypes (via Object.create(null) ), adding object prototype attributes by accessing the prototype via the special attributes becomes impossible, mitigating this weakness.
  • Implementation Map can be used instead of objects in most cases. If Map methods are used instead of object attributes, it is not possible to access the object prototype or modify it.
Señales de detección

How to detect CWE-1321

SAST High

Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.

DAST Moderate

Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.

Runtime Moderate

Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.

Code review Moderate

Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.

Auto-corrección de Plexicus

Plexicus detecta automáticamente CWE-1321 y abre un PR de corrección en menos de 60 segundos.

Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.

Preguntas frecuentes

Frequently asked questions

¿Qué es CWE-1321?

Prototype pollution occurs when an application takes user-supplied input and uses it to improperly modify the properties of a JavaScript object's prototype. This allows attackers to inject key-value pairs into the base object, potentially altering the application's logic, crashing it, or escalating privileges.

¿Qué gravedad tiene CWE-1321?

MITRE no ha publicado una calificación de probabilidad de explotación para esta debilidad. Trátala como de impacto medio hasta que tu modelo de amenazas demuestre lo contrario.

¿Qué lenguajes o plataformas se ven afectados por CWE-1321?

MITRE lists the following affected platforms: JavaScript.

¿Cómo puedo prevenir CWE-1321?

By freezing the object prototype first (for example, Object.freeze(Object.prototype)), modification of the prototype becomes impossible. By blocking modifications of attributes that resolve to object prototype, such as proto or prototype, this weakness can be mitigated.

¿Cómo detecta y corrige Plexicus CWE-1321?

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-1321 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.

¿Dónde puedo aprender más sobre CWE-1321?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/1321.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.

Listo cuando tú lo estés

Deja de pagar por desarrollador.
Empieza a cerrar el bucle.

Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.