Refuse path-like names in omarchy-hook-install too
The runner already rejects a slash, a bare . or .. The installer still joined the type into hooks/<type>.d before mkdir/cp, so a name nothing can run could still land on disk.
This commit is contained in:
1 parent
0a65b45ab1
commit
e522a18ef0
2 files changed
+60
No files matched your search
@@ -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"
|
||||
|
||||
@@ -63,6 +63,55 @@ HOME="$fake_home" "$ROOT/bin/omarchy-hook" "sub/dir" >/dev/null 2>&1 || status=$
|
||||
fail "omarchy hook refuses a hook name with a slash" "exit: $status"
|
||||
pass "omarchy hook refuses a hook name with a slash"
|
||||
|
||||
# --- omarchy-hook-install ------------------------------------------------------
|
||||
|
||||
# The installer joins the type into ~/.config/omarchy/hooks/<type>.d before
|
||||
# mkdir/cp. The runner already refuses a slashed type; install must too, or a
|
||||
# name the runner will not run still lands on disk.
|
||||
|
||||
source_hook="$work_dir/source-hook"
|
||||
cat >"$source_hook" <<'SH'
|
||||
#!/bin/bash
|
||||
true
|
||||
SH
|
||||
|
||||
HOME="$fake_home" "$ROOT/bin/omarchy-hook-install" post-update "$source_hook" >/dev/null
|
||||
[[ -f $fake_home/.config/omarchy/hooks/post-update.d/source-hook ]] ||
|
||||
fail "omarchy hook install still installs a named hook"
|
||||
pass "omarchy hook install still installs a named hook"
|
||||
|
||||
HOME="$fake_home" "$ROOT/bin/omarchy-hook-install" a..b "$source_hook" >/dev/null
|
||||
[[ -f $fake_home/.config/omarchy/hooks/a..b.d/source-hook ]] ||
|
||||
fail "omarchy hook install accepts a hook name with dots in the middle"
|
||||
pass "omarchy hook install accepts a hook name with dots in the middle"
|
||||
|
||||
for name in . ..; do
|
||||
status=0
|
||||
HOME="$fake_home" "$ROOT/bin/omarchy-hook-install" "$name" "$source_hook" >/dev/null 2>&1 || status=$?
|
||||
(( status == 2 )) ||
|
||||
fail "omarchy hook install refuses a hook name of $name" "exit: $status"
|
||||
[[ ! -e $fake_home/.config/omarchy/hooks/${name}.d ]] ||
|
||||
fail "omarchy hook install creates no directory for a hook name of $name"
|
||||
pass "omarchy hook install refuses a hook name of $name"
|
||||
done
|
||||
|
||||
# hooks/../../evil.d is ~/.config/evil.d. The guard must fire before mkdir.
|
||||
status=0
|
||||
HOME="$fake_home" "$ROOT/bin/omarchy-hook-install" "../../evil" "$source_hook" >/dev/null 2>&1 || status=$?
|
||||
(( status == 2 )) ||
|
||||
fail "omarchy hook install refuses a hook name with a dot-dot" "exit: $status"
|
||||
[[ ! -e $fake_home/.config/evil.d ]] ||
|
||||
fail "omarchy hook install creates nothing outside the hooks directory"
|
||||
pass "omarchy hook install refuses a hook name with a dot-dot"
|
||||
|
||||
status=0
|
||||
HOME="$fake_home" "$ROOT/bin/omarchy-hook-install" "sub/dir" "$source_hook" >/dev/null 2>&1 || status=$?
|
||||
(( status == 2 )) ||
|
||||
fail "omarchy hook install refuses a hook name with a slash" "exit: $status"
|
||||
[[ ! -e $fake_home/.config/omarchy/hooks/sub ]] ||
|
||||
fail "omarchy hook install creates no nested directory from a slashed name"
|
||||
pass "omarchy hook install refuses a hook name with a slash"
|
||||
|
||||
# --- omarchy-state -------------------------------------------------------------
|
||||
|
||||
state_dir="$fake_home/.local/state/omarchy"
|
||||
|
||||
Reference in new issue
Block a user