Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1066 from dritter/add_vcs_vulnerability_tests
Browse files Browse the repository at this point in the history
Add tests for branch name vulnerability
  • Loading branch information
dritter authored Nov 16, 2018
2 parents b430a21 + b8b0bb4 commit 1a82717
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/segments/vcs_git.spec
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,19 @@ function testDetectingUntrackedFilesInCleanSubdirectoryWorks() {
assertEquals "%K{002} %F{000}? %f%F{000} master ? %k%F{002}%f " "$(__p9k_build_left_prompt)"
}

function testBranchNameScriptingVulnerability() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(vcs)
echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh
chmod +x evil_script.sh

git checkout -b '$(./evil_script.sh)' 2>/dev/null
git add . 2>/dev/null
git commit -m "Initial commit" >/dev/null

assertEquals '%K{002} %F{000} $(./evil_script.sh) %k%F{002}%f ' "$(__p9k_build_left_prompt)"
}

function testGitSubmoduleWorks() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(vcs)
Expand Down
13 changes: 13 additions & 0 deletions test/segments/vcs_hg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,17 @@ function testBookmarkIconWorks() {
assertEquals "%K{002} %F{000} default Binitial %k%F{002}%f " "$(__p9k_build_left_prompt)"
}

function testBranchNameScriptingVulnerability() {
local -a P9K_LEFT_PROMPT_ELEMENTS
P9K_LEFT_PROMPT_ELEMENTS=(vcs)
echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh
chmod +x evil_script.sh

hg branch '$(./evil_script.sh)' >/dev/null
hg add . >/dev/null
hg commit -m "Initial commit" >/dev/null

assertEquals '%K{002} %F{000} $(./evil_script.sh) %k%F{002}%f ' "$(__p9k_build_left_prompt)"
}

source shunit2/shunit2

0 comments on commit 1a82717

Please sign in to comment.