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

bodymen before 1.1.1 is vulnerable to Prototype Pollution. The handler 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/diegohaz/bodymen
commit_details: repo_url: https://github.com/diegohaz/bodymen
author: Haz
author_date: 2020-02-16 19:10:48-03:00
msg: Fix prototype pollution vulnerability (#23)

* Fix prototype pollution vulnerability

* Update .travis.yml
repository: repo_url: https://github.com/diegohaz/bodymen
repo_name: diegohaz/bodymen
description: Body parser middleware for MongoDB, Express and Nodejs (MEN)
repo_language: JavaScript
owner: diegohaz
file_changes: filename: .travis.yml
change_type: ModificationType.MODIFY
diff: @@ -1,7 +1,5 @@
 language: node_js
 node_js:
   - v6
-  - v5
-  - v4
 after_script:
   - 'npm run coveralls'

programming_language: SQL
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -18,6 +18,14 @@ export const handlers = {
  * @param {Function} [fn] - Set the handler method.
  */
 export function handler (type, name, fn) {
+  if (
+    type === 'constructor' ||
+    type === '__proto__' ||
+    name === 'constructor' ||
+    name === '__proto__'
+  ) {
+    return
+  }
   if (arguments.length > 2) {
     handlers[type][name] = fn
   }

programming_language: TypeScript
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -116,3 +116,18 @@ test('Bodymen middleware', (t) => {
       t.same(res.body, {links: [{icon: 'path to icon'}]}, 'should respond with correct object')
     })
 })
+
+test('Prototype pollution', (t) => {
+  const { toString } = {}
+
+  bodymen.handler('__proto__', 'toString', 'JHU')
+  t.ok({}.toString === toString, 'should not be vulnerable to prototype pollution')
+
+  bodymen.handler('formatters', '__proto__', { toString: 'JHU' })
+  t.ok({}.toString === toString, 'should not be vulnerable to prototype pollution')
+
+  bodymen.handler('validators', '__proto__', { toString: 'JHU' })
+  t.ok({}.toString === toString, 'should not be vulnerable to prototype pollution')
+
+  t.end()
+})

programming_language: CoffeeScript