[last-commit-log] Command Injection
The last-commit-log npm module builds a shell command by inserting the value of the GIT_DIR environment variable without quoting it. An attacker who can set that variable can run arbitrary commands on the host.
- Triaged in 11 hours
- Fixed in 5 months
- Disclosed after 6 months
I would like to report Command Injection in last-commit-log
It allows execution of arbitrary commands
Module
module name: last-commit-log
version: [email protected]
npm page: https://www.npmjs.com/package/last-commit-log
Module Description
Node.js module to get the last git commit information - mostly to be used by CI/CD and building phase.
Module Stats
[3,253] downloads in the last week
Vulnerability
The value of the GIT_DIR env variable is added to the command here on line 10 and here on line 25 and finally the command is executed on line 36.
Vulnerability Description
Steps To Reproduce:
npm i last-commit-log cat > test.js const LCL = require('last-commit-log'); const lcl = new LCL('.'); // or
new LCL(dir)dir is process.cwd() by default lcl .getLastCommit() .then(commit => console.log(commit));
Export malicious GIT_DIR string
export GIT_DIR=". ;touch xxx;"
Run
node test.js

Patch
Fix: enclose --git-dir flag in quotes on line 10 like so
this.gitDirStr = GIT_DIR ? `--git-dir="${GIT_DIR}/.git"` : '';
Supporting Material/References:
- [OPERATING SYSTEM VERSION] Ubuntu 18.04.4 LTS
- [NODEJS VERSION] v14.0.0
- [NPM VERSION] 6.14.4
Wrap up
- I contacted the maintainer to let them know: [Y/N] No
- I opened an issue in the related repository: [Y/N] No
Impact
Ability to run any command available for attacker.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The GIT_DIR environment variable is concatenated into a shell command string without quoting or escaping, so shell metacharacters in it are interpreted.
Impact
An attacker who controls the GIT_DIR variable could run any command available to the process.
What the attacker needed
Ability to set the GIT_DIR env variable
The fix
The fix is to wrap the --git-dir value in quotes so the shell treats it as a single argument; the report does not say whether this was applied.
How it was found
- Install the last-commit-log package.
- Write a small script that creates an instance and calls getLastCommit.
- Set the GIT_DIR environment variable to a value containing shell metacharacters and a command.
- Run the script with node and observe the injected command execute.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This package runs a git command in a shell to read the last commit. It pastes the GIT_DIR environment variable straight into that command, so characters like a semicolon end the git command and start a new one. Anyone who can control that variable can make the machine run their own commands.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.