Skip to content

Commit

Permalink
Merge pull request #222 from tegonal/improve/pull-outside
Browse files Browse the repository at this point in the history
double check target path is inside currentDir
  • Loading branch information
robstoll authored Oct 25, 2024
2 parents a1f96ca + 82ed62e commit 624ceb0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
8 changes: 6 additions & 2 deletions src/gt-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function gt_pull() {
# before we report about missing arguments we check if the working directory exists and
# if it is inside of the call location
exitIfWorkingDirDoesNotExist "$workingDir"
exitIfDirectoryNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"
exitIfPathNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"

# if remote does not exist then pull.args does not and most likely pullDir is thus not defined, in this case we want
# to show the error about the non existing remote before other missing arguments
Expand All @@ -208,7 +208,7 @@ function gt_pull() {
workingDirAbsolute=$(readlink -m "$workingDir") || die "could not deduce workingDirAbsolute from %s" "$workingDir"
pullDirAbsolute=$(readlink -m "$pullDir")
local -r workingDirAbsolute pullDirAbsolute
checkIfDirectoryNamedIsOutsideOf "$pullDirAbsolute" "pull directory" "$currentDir" || return $?
checkIfPathNamedIsOutsideOf "$pullDirAbsolute" "pull directory" "$currentDir" || return $?

local publicKeysDir repo gpgDir pulledTsv pullHookFile
source "$dir_of_gt/paths.source.sh" || traceAndDie "could not source paths.source.sh"
Expand Down Expand Up @@ -426,6 +426,10 @@ function gt_pull() {

local absoluteFile
while read -r -d $'\0' absoluteFile; do
# in theory this check should not be necessary as we already check that the pullDir is not outside
# but better be sure as we don't want that `gt re-pull` can be a security risk (leaving pull-hooks aside)
checkIfPathNamedIsOutsideOf "$absoluteFile" "target path" "$currentDir" || return $?

local repoFile
repoFile=$(realpath --relative-to="$repo" "$absoluteFile")
if [[ $doVerification == true && -f "$absoluteFile.$sigExtension" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion src/gt-re-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function gt_re_pull() {
# before we report about missing arguments we check if the working directory exists and
# if it is inside of the call location
exitIfWorkingDirDoesNotExist "$workingDir"
exitIfDirectoryNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"
exitIfPathNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"

exitIfNotAllArgumentsSet params "$examples" "$GT_VERSION"

Expand Down
6 changes: 3 additions & 3 deletions src/gt-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function gt_remote_add() {
if ! [[ -v tagFilter ]]; then tagFilter=".*"; fi

# before we report about missing arguments we check if the working directory is inside of the call location
exitIfDirectoryNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"
exitIfPathNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"
exitIfNotAllArgumentsSet params "$examples" "$GT_VERSION"

local -r remoteIdentifierRegex="^[a-zA-Z0-9_-]+$"
Expand Down Expand Up @@ -256,7 +256,7 @@ function gt_remote_list_raw() {
# before we report about missing arguments we check if the working directory exists and
# if it is inside of the call location
exitIfWorkingDirDoesNotExist "$workingDir"
exitIfDirectoryNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"
exitIfPathNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"

exitIfNotAllArgumentsSet params "$examples" "$GT_VERSION"

Expand Down Expand Up @@ -325,7 +325,7 @@ function gt_remote_remove() {
# before we report about missing arguments we check if the working directory exists and
# if it is inside of the call location
exitIfWorkingDirDoesNotExist "$workingDir"
exitIfDirectoryNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"
exitIfPathNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"

exitIfNotAllArgumentsSet params "$examples" "$GT_VERSION"

Expand Down
2 changes: 1 addition & 1 deletion src/gt-reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function gt_reset() {
# before we report about missing arguments we check if the working directory exists and
# if it is inside of the call location
exitIfWorkingDirDoesNotExist "$workingDir"
exitIfDirectoryNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"
exitIfPathNamedIsOutsideOf "$workingDir" "working directory" "$currentDir"

exitIfNotAllArgumentsSet params "$examples" "$GT_VERSION"

Expand Down
19 changes: 0 additions & 19 deletions src/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,6 @@ function exitIfRemoteDirDoesNotExist() {
fi
}

function checkIfDirectoryNamedIsOutsideOf() {
local directory name parentDirectory
# shellcheck disable=SC2034 # is passed by name to parseFnArgs
local -ra params=(directory name parentDirectory)
parseFnArgs params "$@"

local directoryAbsolute parentDirectoryAbsolute
directoryAbsolute="$(realpath "$directory")"
parentDirectoryAbsolute="$(realpath "$parentDirectory")"
if ! [[ "$directoryAbsolute" == "$parentDirectoryAbsolute"* ]]; then
returnDying "the given \033[0;36m%s\033[0m %s is outside of %s" "$name" "$directoryAbsolute" "$parentDirectory"
fi
}

function exitIfDirectoryNamedIsOutsideOf() {
# shellcheck disable=SC2310 # we are aware of that || will disable set -e for checkIfDirectoryNamedIsOutsideOf
checkIfDirectoryNamedIsOutsideOf "$@" || exit $?
}

function invertBool() {
local b=$1
shift 1 || traceAndDie "could not shift by 1"
Expand Down

0 comments on commit 624ceb0

Please sign in to comment.