CVE-2023-26135 (published 2023-06-30T05:15Z)

All versions of the package flatnest are vulnerable to Prototype Pollution via the nest() function in the flatnest/nest.js file.

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/brycebaril/node-flatnest
commit_details: repo_url: https://github.com/brycebaril/node-flatnest
author: Bryce B. Baril
author_date: 2023-12-21 15:36:55-08:00
msg: Prevent prototype pollution reported in issue #4
repository: repo_url: https://github.com/brycebaril/node-flatnest
repo_name: brycebaril/node-flatnest
description: Flatten/Nest Javascript objects
repo_language: JavaScript
owner: brycebaril
file_changes: filename: flatten.js
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,5 @@
+'use strict'
+
 module.exports = flatten
 
 function flatten(obj) {

programming_language: CoffeeScript
filename: nest.js
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,5 @@
+'use strict'
+
 module.exports = nest
 
 var seek = require("./seek")
@@ -37,6 +39,8 @@ function insert(target, path, value) {
   var len = pathBits.length
   for (var i = 0; i < len; i += 2) {
     var key = pathBits[i]
+    if (key === "__proto__") continue
+    if (key === "constructor" && typeof target[key] == "function") continue
     var type = pathBits[i + 1]
 
     if (type == null && key) parent[key] = value

programming_language: CoffeeScript
filename: seek.js
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,5 @@
+'use strict'
+
 module.exports = seek
 
 var nestedRe = /(\.|\[)/

programming_language: CoffeeScript
filename: flatten.js
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,5 @@
+'use strict'
+
 var test = require("tape").test
 
 var flatten = require("../flatten")

programming_language: JavaScript
filename: nest.js
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,5 @@
+'use strict'
+
 var test = require("tape").test
 
 var nest = require("../nest")
@@ -139,3 +141,11 @@ test("nest empty", function (t) {
   t.deepEquals(nest(struct), expect, "empty object is still empty")
   t.end()
 })
+
+test("no prototype pollution", function (t) {
+  nest({'constructor.prototype.fail': true})
+  nest({'__proto__.bad': true})
+  t.false({}.fail, "constructor.prototype not polluted")
+  t.false({}.bad, "__proto__ not polluted")
+  t.end()
+})

programming_language: JavaScript