Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.
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…
What is CWE-1321?
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.
Parcours de l'attaquant étape par étape
- 1
This function sets object attributes based on a dot-separated path.
- 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
By using a denylist of dangerous attributes, this weakness can be eliminated.
Vulnerable JavaScript
This function sets object attributes based on a dot-separated path.
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;
} Secure JavaScript
By using a denylist of dangerous attributes, this weakness can be eliminated.
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;
} 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.
How to detect CWE-1321
Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.
Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.
Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.
Plexicus détecte automatiquement CWE-1321 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.
Frequently asked questions
Qu'est-ce que 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.
Quelle est la gravité de CWE-1321 ?
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-1321 ?
MITRE lists the following affected platforms: JavaScript.
Comment puis-je prévenir 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.
Comment Plexicus détecte et corrige CWE-1321 ?
Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-1321 à 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-1321 ?
MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/1321.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.
Weaknesses related to CWE-1321
Improperly Controlled Modification of Dynamically-Determined Object Attributes
This vulnerability occurs when an application accepts user input that specifies which object attributes or fields to create or update, but…
Modification of Assumed-Immutable Data (MAID)
This vulnerability occurs when an application fails to protect data it assumes cannot be changed, allowing an attacker to alter it.
Further reading
- MITRE — CWE-1321 officiel https://cwe.mitre.org/data/definitions/1321.html
- Prototype pollution attack in NodeJS application https://github.com/HoLyVieR/prototype-pollution-nsec18/blob/master/paper/JavaScript_prototype_pollution_attack_in_NodeJS.pdf
- What is Prototype Pollution? https://codeburst.io/what-is-prototype-pollution-49482fc4b638
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.