diff --git a/AGENTS.md b/AGENTS.md index fc655a0eb7a2..50c192826b8e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -188,4 +188,4 @@ To copy a default config to user config with automatic backup: omarchy-refresh-config hypr/hyprland.lua ``` -This copies `$OMARCHY_PATH/config/hypr/hyprland.lua` to `~/.config/hypr/hyprland.lua`. The argument must be a plain relative path: an absolute path or any `..` segment is rejected before anything is copied. That check is lexical, so a symlink under `~/.config` is still followed and its target rewritten — which is what keeps symlink-managed dotfiles working. +This copies `$OMARCHY_PATH/config/hypr/hyprland.lua` to `~/.config/hypr/hyprland.lua`. The argument must be a plain relative path: an absolute path, any `..` segment, or a line break is rejected before anything is copied. That check is lexical, so a symlink under `~/.config` is still followed and its target rewritten — which is what keeps symlink-managed dotfiles working. diff --git a/bin/omarchy-refresh-config b/bin/omarchy-refresh-config index 9e554a273690..7a2e2de62e00 100755 --- a/bin/omarchy-refresh-config +++ b/bin/omarchy-refresh-config @@ -17,7 +17,9 @@ USAGE exit 1 fi -if [[ $config_file == /* || $config_file == ".." || $config_file == ../* || $config_file == */../* || $config_file == */.. ]]; then +# Absolute paths, `..` segments, and line breaks are not shipped relative +# configs. A `..` component can land the write outside ~/.config. +if [[ $config_file == /* || $config_file == ".." || $config_file == ../* || $config_file == */../* || $config_file == */.. || $config_file == *$'\n'* || $config_file == *$'\r'* ]]; then echo "Invalid config path: $config_file" >&2 exit 1 fi diff --git a/test/shell.d/refresh-config-test.sh b/test/shell.d/refresh-config-test.sh index 4499937d5c59..9a5efcc0088d 100644 --- a/test/shell.d/refresh-config-test.sh +++ b/test/shell.d/refresh-config-test.sh @@ -53,7 +53,7 @@ refuses() { fail "refresh-config rejects $config_file" fi - grep -Fq "Invalid config path: $config_file" "$tmpdir/err" || + [[ $(cat "$tmpdir/err") == "Invalid config path: $config_file" ]] || fail "refresh-config reports $config_file as an invalid config path" "$(cat "$tmpdir/err")" [[ $(cat "$escape") == "do not touch" ]] || @@ -65,5 +65,11 @@ refuses hypr/../../escape refuses .. refuses hypr/.. refuses /etc/passwd +refuses $'hypr\n/../../escape' +newline_path=$'hypr/a\nb.lua' +printf 'shipped newline config\n' >"$omarchy_path/config/$newline_path" +refuses "$newline_path" +[[ ! -e $home/.config/$newline_path ]] || fail "newline path must not be copied" +refuses $'hypr/a\rb.lua' pass "refresh-config rejects paths escaping .config"