CWE-1321 Variant Incomplete

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…

Definition

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.
Auswirkungen in der Praxis

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.

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

  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.

Verwundbares Codebeispiel

Vulnerable JavaScript

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

Verwundbar 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;
  	 }
Sicheres Codebeispiel

Secure JavaScript

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

Sicher 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.
Präventions-Checkliste

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.
Erkennungssignale

How to detect CWE-1321

SAST High

Führe statische Analyse (SAST) auf der Codebasis aus und suche im Datenfluss nach dem unsicheren Muster.

DAST Moderate

Führe dynamische Application-Security-Tests gegen den Live-Endpoint aus.

Runtime Moderate

Beobachte Runtime-Logs auf ungewöhnliche Exception-Traces, fehlerhafte Eingaben oder Versuche, Autorisierung zu umgehen.

Code review Moderate

Code Review: Markiere jeden neuen Code, der Eingaben von dieser Oberfläche ohne validierte Framework-Helper verarbeitet.

Plexicus Auto-Fix

Plexicus erkennt CWE-1321 automatisch und öffnet in unter 60 Sekunden einen Fix-PR.

Codex Remedium scannt jeden Commit, identifiziert genau diese Schwachstelle und liefert einen reviewer-ready Pull Request mit dem Patch. Keine Tickets. Keine Hand-offs.

Häufig gestellte Fragen

Frequently asked questions

Was ist 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.

Wie gravierend ist CWE-1321?

MITRE hat für diese Schwachstelle keine Exploit-Wahrscheinlichkeit veröffentlicht. Behandle sie als mittlere Auswirkung, bis dein Threat Model anderes belegt.

Welche Sprachen oder Plattformen sind von CWE-1321 betroffen?

MITRE lists the following affected platforms: JavaScript.

Wie kann ich CWE-1321 verhindern?

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.

Wie erkennt und behebt Plexicus CWE-1321?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-1321 bei jedem Commit. Bei einem Treffer öffnet unser Codex-Remedium-Agent einen Fix-PR mit korrigiertem Code, Tests und einer einzeiligen Zusammenfassung für den Reviewer.

Wo erfahre ich mehr über CWE-1321?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/1321.html. Für ergänzende Hinweise kannst du auch die OWASP- und NIST-Dokumentation heranziehen.

Bereit, wenn du es bist

Schluss mit dem Bezahlen pro Entwickler.
Schließ den Kreislauf.

Plexicus ist die KI-native ASPM, die scannt, filtert, fixt, pentestet und erklärt — autonom. Unbegrenzte Entwickler, unbegrenzte Repos, Fair-Use-KI-Aktionen. Echter kostenloser Tarif, €269/mo jährlich, wenn du bereit bist.