npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

git-clone-safe

v1.2.0

Published

Safe drop-in replacement for git-clone package, fixing command injection vulnerability (CVE-2022-25900)

Readme

git-clone-safe

Safe drop-in replacement for git-clone package, fixing command injection vulnerability (CVE-2022-25900)

Purpose

This is a fully functional replacement for the vulnerable [email protected] package. It provides the same API but fixes the command injection vulnerability (CVE-2022-25900) by using child_process.spawn instead of shell-based execution.

Why This Works

  • The original git-clone package has a command injection vulnerability (CVE-2022-25900) due to using shell-based command execution
  • This package uses child_process.spawn which passes arguments directly to the git binary without a shell
  • Uses -- separator before the repository URL to prevent git option injection
  • No command injection is possible because user input is never passed through a shell

API Compatibility

This package provides the same API as the original git-clone:

Callback API

const gitClone = require('git-clone-safe');

gitClone(repo, targetPath, opts, cb)

Promise API

const gitClone = require('git-clone-safe/promise');

await gitClone(repo, targetPath, opts)

Options (matching original git-clone API)

| Option | Type | Description | |--------|------|-------------| | git | String | Path to git executable (default: 'git') | | shallow | Boolean | Clone with depth 1 (shallow clone) | | checkout | String | Branch, tag, or commit SHA to checkout | | args | Array|String | Additional git arguments (array of strings, or space-separated string) | | emit | Boolean | Emit stdio to parent process (default: false) |

Notes:

  • branch is supported as an alias for checkout for backward compatibility
  • depth (numeric) takes precedence over shallow if both are specified
  • checkout performs a separate git checkout after cloning, which works for branches, tags, AND commit SHAs
  • args as an array follows the original API; string format is also accepted for convenience

Setup

Add an override in your project's package.json:

"overrides": {
  "git-clone": "npm:git-clone-safe"
}

Or use a local path:

"overrides": {
  "git-clone": "file:./git-clone-safe"
}

Usage Example

const gitClone = require('git-clone-safe');

// Clone a specific branch
gitClone(
  'https://github.com/user/repo.git',
  './my-repo',
  { checkout: 'main' },
  (err) => {
    if (err) {
      console.error('Clone failed:', err);
    } else {
      console.log('Clone successful!');
    }
  }
);

// Shallow clone
gitClone(
  'https://github.com/user/repo.git',
  './my-repo',
  { shallow: true },
  (err) => { /* ... */ }
);

// With custom git path and extra args (array format - original API)
gitClone(
  'https://github.com/user/repo.git',
  './my-repo',
  { git: '/usr/bin/git', args: ['--verbose'] },
  (err) => { /* ... */ }
);

// Checkout a specific commit SHA
gitClone(
  'https://github.com/user/repo.git',
  './my-repo',
  { checkout: 'a1b2c3d' },
  (err) => { /* ... */ }
);

Security Fix

Vulnerability #1: Shell Command Injection (CVE-2022-25900)

The original git-clone package used child_process.exec() which passes commands through a shell. This allowed attackers to inject arbitrary commands:

// Malicious input
gitClone('https://evil.com/repo.git && rm -rf /', './dest')
// Would execute via shell: git clone 'https://evil.com/repo.git && rm -rf /' './dest'

Fix: Use child_process.spawn() with an array of arguments - no shell involved.

Vulnerability #2: Git Option Injection

Without proper argument separation, a repository name starting with - could be interpreted as a git option:

// Without -- separator
spawn('git', ['clone', '--help', './dest'])  // Shows help instead of cloning

// With -- separator
spawn('git', ['clone', '--', '--help', './dest'])  // Actually clones repo named "--help"

Fix: Always use -- before the repository URL to terminate option parsing.

Vulnerability #3: Unsafe args Parameter

The original package concatenated opts.args directly into the shell command, allowing shell injection.

Fix: Accept opts.args as an array of strings (original API) or a space-separated string. Each element is validated to reject shell metacharacters (;&|$()<>`) before being passed to git.

Verification

Check that the override is active:

npm ls git-clone
# Should show: git-clone@npm:[email protected]

npm audit
# Should NOT report git-clone vulnerability

Impact

  • ✅ Fixes security scanner findings (CVE-2022-25900)
  • ✅ Fully functional git clone capability
  • ✅ Drop-in replacement - same API as original
  • ✅ No additional dependencies
  • ✅ Protected against git option injection via -- separator