Merge pull request #8170 from Adolanium/hook-state-name-guard
Refuse hook and state names that are paths
This commit is contained in:
4 files changed
+195
-1
No files matched your search
@@ -11,6 +11,18 @@ if (( $# < 1 )); then
|
||||
fi
|
||||
|
||||
HOOK=$1
|
||||
|
||||
# Hook names are fixed labels chosen by Omarchy code (post-update, theme-set,
|
||||
# font-set). The name becomes a filename under the hooks directory. A slash
|
||||
# would turn it into directory levels, and a bare `.` or `..` would point bash
|
||||
# at the directory itself or its parent. Refuse those rather than follow them.
|
||||
# Dots inside a name (a..b) are fine; once slashes are out, only the whole
|
||||
# name being `.` or `..` can leave the directory.
|
||||
if [[ -z $HOOK || $HOOK == */* || $HOOK == "." || $HOOK == ".." ]]; then
|
||||
echo "Invalid hook name: $HOOK" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
HOOK_PATH="$HOME/.config/omarchy/hooks/$1"
|
||||
HOOK_DIR="$HOOK_PATH.d"
|
||||
shift
|
||||
|
||||
@@ -15,6 +15,17 @@ fi
|
||||
|
||||
HOOK_TYPE=$1
|
||||
HOOK_FILE=$2
|
||||
|
||||
# Hook types are the same labels omarchy-hook runs (post-update, theme-set).
|
||||
# The type becomes a directory under the hooks directory. A slash would turn
|
||||
# it into directory levels. A bare `.` or `..` is a name the runner already
|
||||
# refuses, so installing under it would write a hook nothing can run. Refuse
|
||||
# those rather than mkdir/cp into them. Dots inside a name (a..b) are fine.
|
||||
if [[ -z $HOOK_TYPE || $HOOK_TYPE == */* || $HOOK_TYPE == "." || $HOOK_TYPE == ".." ]]; then
|
||||
echo "Invalid hook name: $HOOK_TYPE" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
HOOK_DIR="$HOME/.config/omarchy/hooks/$HOOK_TYPE.d"
|
||||
HOOK_NAME=$(basename "$HOOK_FILE")
|
||||
HOOK_PATH="$HOOK_DIR/$HOOK_NAME"
|
||||
|
||||
+14
-1
@@ -21,6 +21,19 @@ if [[ -z $STATE_NAME ]]; then
|
||||
fi
|
||||
|
||||
case "$COMMAND" in
|
||||
set) touch "$STATE_DIR/$STATE_NAME" ;;
|
||||
set)
|
||||
# State names are fixed labels (reboot-required, restart-*-required). The
|
||||
# name becomes a filename under the state directory. A slash would turn it
|
||||
# into directory levels, and a bare `.` or `..` would touch the directory
|
||||
# itself or its parent. Refuse those. Dots inside a name (a..b) are fine;
|
||||
# once slashes are out, only the whole name being `.` or `..` can leave the
|
||||
# directory. clear needs no such guard: find -name matches basenames only,
|
||||
# so a pattern can never walk out of the directory.
|
||||
if [[ $STATE_NAME == */* || $STATE_NAME == "." || $STATE_NAME == ".." ]]; then
|
||||
echo "Invalid state name: $STATE_NAME" >&2
|
||||
exit 2
|
||||
fi
|
||||
touch "$STATE_DIR/$STATE_NAME"
|
||||
;;
|
||||
clear) find "$STATE_DIR" -maxdepth 1 -type f -name "$STATE_NAME" -delete ;;
|
||||
esac
|
||||
Reference in new issue
Block a user