CVE-2019-10795 (published 2020-02-18T16:15Z)

undefsafe before 2.0.3 is vulnerable to Prototype Pollution. The 'a' function could be tricked into adding or modifying properties of Object.prototype using a __proto__ payload.

Severity: MEDIUM
CVSS v2 base score: 6.5 (AV:N/AC:L/Au:S/C:P/I:P/A:P)
CVSS v3 base score: 6.3, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L)

Weakness information:
cwe_id: CWE-74
cwe_name: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
description: The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
extended_description: Software or other automated logic has certain assumptions about what constitutes data and control respectively. It is the lack of verification of these assumptions for user-controlled input that leads to injection problems. Injection problems encompass a wide variety of issues -- all mitigated in very different ways and usually attempted in order to alter the control flow of the process. For this reason, the most effective way to discuss these weaknesses is to note the distinct features that classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed.
         

Fix information:
repo_url: https://github.com/remy/undefsafe
commit_details: repo_url: https://github.com/remy/undefsafe
author: Remy Sharp
author_date: 2020-02-17 18:47:54+00:00
msg: fix: prevent changes in prototype chain
repository: repo_url: https://github.com/remy/undefsafe
repo_name: remy/undefsafe
description: Simple *function* for retrieving deep object properties without getting "Cannot read property 'X' of undefined"
repo_language: JavaScript
owner: remy
file_changes: filename: undefsafe.js
change_type: ModificationType.MODIFY
diff: @@ -99,6 +99,10 @@ function undefsafe(obj, path, value, __res) {
       return res;
     }
 
+    if (Object.getOwnPropertyNames(obj).indexOf(key) == -1) {
+      return undefined;
+    }
+
     obj = obj[key];
     if (obj === undefined || obj === null) {
       break;

programming_language: JavaScript
filename: misc.test.js
change_type: ModificationType.ADD
diff: @@ -0,0 +1,11 @@
+var test = require('tap').test;
+var undefsafe = require('../lib/undefsafe');
+
+test('cannot modify prototype chain', function(t) {
+  const pre = {}.__proto__.toString;
+  var payload = '__proto__.toString';
+  undefsafe({ a: 'b' }, payload, 'JHU');
+  t.notEqual({}.toString, 'JHU');
+  ({}.__proto__.toString = pre); // restore
+  t.end();
+});

programming_language: JavaScript