Skip to content
RCE Disclosed report Beginner

[commit-msg] RCE via insecure command formatting

The commit-msg npm package builds a shell command by inserting user-supplied input without validation, so a crafted commit message can run arbitrary commands on the victim's machine. The reporter shows that a message containing a shell separator causes a reboot and can create files on the host.

mik317 Follow

Originally disclosed on HackerOne

Medium 6.4 View original
  • Triaged in 5 days
  • Fixed in 3 months
  • Disclosed after 4 months

I would like to report a RCE issue in the commit-msg module. It allows to execute arbitrary commands remotely inside the victim's PC

Module

module name: commit-msg version: 0.2.3 npm page: https://www.npmjs.com/package/commit-msg

Module Description

commit-msg is a customizable git commit message parser and validator written in Node.js. It validates a given string based on best practices and can be used as a git hook, command line tool and/or directly through the API.

Module Stats

[103] downloads in the last week

Vulnerability Description

The issue occurs because a user input is formatted inside a command that will be executed without any check. The issue arises here: https://github.com/clns/node-commit-msg/blob/master/bin/validate#L128

Steps To Reproduce:

  1. Check there aren't files called HACKED
  2. Execute the following commands in another terminal:
Bash
npm i commit-msg -g # Install affected module
git init # Init the current dir as *git*
echo "test||reboot" | commit-msg stdin # Your machine will be rebooted because `reboot` command is injected
node poc.js #  Run the PoC
  1. Recheck the files: now HACKED has been created :)

Patch

Don't format commands using insecure user's inputs :)

Supporting Material/References:

  • [OPERATING SYSTEM VERSION]: Kali Linux

Wrap up

  • I contacted the maintainer to let them know: [N]
  • I opened an issue in the related repository: [N]

Impact

RCE via command formatting on commit-msg

The original report as published on HackerOne, by mik317. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

Likely the module concatenates untrusted commit message text into a shell command string instead of passing it as a separate argument or escaping it.

Impact

An attacker who can influence the commit message could execute arbitrary commands on the victim's machine, potentially rebooting it or creating files.

What the attacker needed

Commit-msg installed; attacker controls commit message

How it was found

  1. Install the affected module globally and initialise a git repository in the current directory.
  2. Pipe a commit message containing a shell separator and a system command into the tool's stdin mode.
  3. Run the proof-of-concept script and check that a file named HACKED now exists.

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 tool reads a commit message and checks it, but it passes that message into a system command. Because the message is not cleaned, characters that the shell treats as instructions let an attacker run their own programs on the computer. That is called remote code execution, meaning someone else can make your machine do things.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by mik317

View all

23 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.