CVE-2022-0944 (published 2022-03-15T01:15Z)

Template injection in connection test endpoint leads to RCE in GitHub repository sqlpad/sqlpad prior to 6.10.1.

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

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which 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. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/sqlpad/sqlpad
commit_details: repo_url: https://github.com/sqlpad/sqlpad
author: Rick Bergfalk
author_date: 2022-03-13 19:55:40-05:00
msg: Use mustache to process connection template (#1110)
repository: repo_url: https://github.com/sqlpad/sqlpad
repo_name: sqlpad/sqlpad
description: Web-based SQL editor. Legacy project in maintenance mode.
repo_language: JavaScript
owner: sqlpad
file_changes: filename: render-connection.js
change_type: ModificationType.MODIFY
diff: @@ -1,4 +1,9 @@
-const _ = require('lodash');
+const mustache = require('mustache');
+
+// Disable HTML escaping. We're not using it for HTML
+mustache.escape = function (text) {
+  return text;
+};
 
 /**
  * Iterates over connection object, replacing any template strings with values from user
@@ -19,9 +24,7 @@ function renderConnection(connection, user) {
     } else {
       const value = connection[key];
       if (typeof value === 'string') {
-        _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
-        const compiled = _.template(value);
-        replaced[key] = compiled({ user });
+        replaced[key] = mustache.render(value, { user });
       } else {
         replaced[key] = value;
       }

programming_language: JavaScript
filename: package-lock.json
change_type: ModificationType.MODIFY
diff: @@ -4097,6 +4097,11 @@
         "tedious": "^14.0.0"
       }
     },
+    "mustache": {
+      "version": "4.2.0",
+      "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
+      "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="
+    },
     "mysql": {
       "version": "2.18.1",
       "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz",

programming_language: TypeScript
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -69,6 +69,7 @@
     "mkdirp": "^1.0.4",
     "moment": "^2.29.1",
     "mssql": "^8.0.2",
+    "mustache": "^4.2.0",
     "mysql": "^2.18.1",
     "mysql2": "^2.3.3",
     "node-crate": "^2.0.6",

programming_language: Python