Skip to content
RCE Advisory Intermediate

GHSL-2020-122: Command injection in git-diff-apply

The diff function in git-diff-apply passed user-supplied tag names into a shell command, allowing an attacker to inject arbitrary commands. An attacker who controls the startTag or endTag values could execute code on the host running the library.

kevinbackhouse Follow

Originally disclosed on GitHub Security Lab

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.

kevinbackhouse, on GitHub Security Lab

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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 library used child_process.exec with a command string built from the startTag and endTag values, so shell metacharacters in those values were interpreted by the shell.

Impact

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

What the attacker needed

Client passes untrusted input to diff

The fix

The library was fixed in v0.22.9 by avoiding an API that interprets a string as a shell command, such as using child_process.execFile instead of child_process.exec.

How it was found

  1. Install git-diff-apply and create a simple git repository.
  2. Create a JavaScript file that calls diff with a crafted startTag value.
  3. Run the file with node.
  4. Observe that a file named /tmp/exploit has been created.

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 library builds a shell command from strings you give it, such as tag names. If those strings contain shell metacharacters, the shell runs extra commands. Here, a crafted tag name caused a file to be created, showing that arbitrary commands can run.

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 kevinbackhouse

View all

47 more disclosed reports, best first.

More from GitHub Security Lab

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.