Skip to content

Commit

Permalink
test: add test case for command injection vector
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal committed Apr 6, 2022
1 parent 2f795ed commit 4f8b9ba
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const gitPullOrClone = require('../')
const path = require('path')
const rimraf = require('rimraf')
const test = require('tape')
const fs = require('fs')
const noop = () => {}

const TMP_PATH = path.join(__dirname, '..', 'tmp')
Expand Down Expand Up @@ -41,3 +42,53 @@ test('git pull with invalid depth', (t) => {
/The "depth" option must be greater than 0/
)
})

test('git clone shouldnt allow command injection, via attack vector one', (t) => {
t.plan(2)

// clean up the tmp folder from prior tests
rimraf.sync(TMP_PATH)
// clone a repo into the tmp folder
gitPullOrClone(REPO_URL, OUT_PATH, (err) => {
t.error(err)
})

const OUT_TEST_FILE = '/tmp/pwn3'
const REPO_LOCAL_PATH = `file://${OUT_PATH}`
const OUT_PATH_INJECTION = `--upload-pack=touch ${OUT_TEST_FILE}`

console.log(REPO_LOCAL_PATH)

gitPullOrClone(REPO_LOCAL_PATH, OUT_PATH_INJECTION, () => {
const exploitSucceeded = !!fs.existsSync(OUT_TEST_FILE)
t.error(exploitSucceeded, `${OUT_TEST_FILE} should not exist, potential security vulnerability detected`)

// cleanup the command injection test data
exploitSucceeded && rimraf.sync(OUT_TEST_FILE)
})
})

test('git clone shouldnt allow command injection, via attack vector two', (t) => {
t.plan(2)

// clean up the tmp folder from prior tests
rimraf.sync(TMP_PATH)
// clone a repo into the tmp folder
gitPullOrClone(REPO_URL, OUT_PATH, (err) => {
t.error(err)
})

const OUT_TEST_FILE = '/tmp/pwn4'
const OUT_PATH_INJECTION = `file://${OUT_PATH}`
const REPO_LOCAL_PATH = `--upload-pack=touch ${OUT_TEST_FILE}`

console.log(REPO_LOCAL_PATH)

gitPullOrClone(REPO_LOCAL_PATH, OUT_PATH_INJECTION, () => {
const exploitSucceeded = !!fs.existsSync(OUT_TEST_FILE)
t.error(exploitSucceeded, `${OUT_TEST_FILE} should not exist, potential security vulnerability detected`)

// cleanup the command injection test data
exploitSucceeded && rimraf.sync(OUT_TEST_FILE)
})
})

0 comments on commit 4f8b9ba

Please # to comment.