CVE-2020-28441 (published 2022-07-25T14:15Z)

This affects the package conf-cfg-ini before 1.2.2. If an attacker submits a malicious INI file to an application that parses it with decode, they will pollute the prototype on the application. This can be exploited further depending on the context.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-1321
cwe_name: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')
description: The product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype.
extended_description: 
				By adding or modifying attributes of an object prototype, it is possible to create attributes that exist on every object, or replace critical attributes with malicious ones. This can be problematic if the product depends on existence or non-existence of certain attributes, or uses pre-defined attributes of object prototype (such as hasOwnProperty, toString or valueOf).
				This weakness is usually exploited by using a special attribute of objects called proto,  constructor or prototype. Such attributes give access to the object prototype. This weakness is often found in code that assigns object attributes based on user input, or merges or clones objects recursively.
			
			

Fix information:
repo_url: https://github.com/loge5/conf-cfg-ini
commit_details: repo_url: https://github.com/loge5/conf-cfg-ini
author: Rolf Loges
author_date: 2020-12-09 17:53:16+01:00
msg: fix: prevent prototype pollution attack
repository: repo_url: https://github.com/loge5/conf-cfg-ini
repo_name: loge5/conf-cfg-ini
description: Encode and decode conf/cfg/ini-Files with Node.js
repo_language: JavaScript
owner: loge5
file_changes: filename: conf-cfg-ini.js
change_type: ModificationType.MODIFY
diff: @@ -35,6 +35,7 @@ Config.prototype.decode = function(data){
             throw new Error('expecting string but got '+typeof data);
         }
     }
+    var protectedKeys = ['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__'];
     var result = {};
     var currentSection = undefined;
     var lines = data.split(this.options.lineEnding);
@@ -51,7 +52,7 @@ Config.prototype.decode = function(data){
         var newSection = line.match(sectionRegExp);
         if(newSection !== null){
             currentSection = newSection[1];
-            if(typeof result[currentSection] === 'undefined'){
+            if(typeof result[currentSection] === 'undefined' && !protectedKeys.includes(currentSection)){
                 result[currentSection] = {};
             }
             continue;
@@ -78,6 +79,9 @@ Config.prototype.decode = function(data){
         if (typeof this.options.valueIdentifier === 'string') {
             value = this.valueTrim(value, this.options.valueIdentifier);
         }
+        if (protectedKeys.includes(currentSection) || protectedKeys.includes(key)) {
+            continue;
+        }
         if(typeof currentSection === 'undefined'){
             result[key] = value;
         } else {

programming_language: JavaScript
filename: conf-cfg-ini.spec.js
change_type: ModificationType.MODIFY
diff: @@ -112,6 +112,16 @@ describe('Config', function() {
         expect(result.Section.foo).to.equal("bar");
     });
 
+    it('decode should prevent prototype pollution attacks', function () {
+        var config = new Config();
+        config.options.lineEnding = "\n";
+        config.options.assignIdentifier = ":";
+        var result = config.decode("[__proto__]\nfoo:bar\n");
+        should.not.exist(result.__proto__.foo);
+        result = config.decode("[Section]\n__proto__:bar\n");
+        expect(result.Section.__proto__).to.not.equal("bar");
+    });
+
     it('valueTrim should trim custom chars', function () {
         var config = new Config();
         expect(config.valueTrim('"Te"s"t"', '"')).to.equal('Te"s"t');

programming_language: JavaScript