Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ omarchy-refresh-config hypr/hyprland.lua
```

This copies `$OMARCHY_PATH/config/hypr/hyprland.lua` to `~/.config/hypr/hyprland.lua`. The argument
is interpolated into both paths and only checked with `[[ -e ]]`, so pass a plain relative path: a
name containing `..` resolves and copies, landing outside `~/.config` rather than being rejected.
must be a relative path with no `..` components; anything else is refused rather than resolved
outside `~/.config`.
18 changes: 18 additions & 0 deletions bin/omarchy-refresh-config
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ USAGE
exit 1
fi

# The path is joined onto both ~/.config and $OMARCHY_PATH/config. A `..`
# component or an absolute path would copy a file that is not a shipped user
# config, and could land the write outside ~/.config.
path_allowed=1
[[ $config_file != /* ]] || path_allowed=0
IFS=/ read -ra config_parts <<< "$config_file"
for part in "${config_parts[@]}"; do
if [[ $part == ".." ]]; then
path_allowed=0
break
fi
done

if (( ! path_allowed )); then
echo "Not a shipped user config: $config_file" >&2
exit 1
fi

user_config_file="${HOME}/.config/$config_file"
default_config_file="$OMARCHY_PATH/config/$config_file"
backup_config_file="$user_config_file.bak.$(date +%s)"
Expand Down
32 changes: 32 additions & 0 deletions test/shell.d/refresh-config-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,35 @@ grep -Fq 'Not a shipped user config: hypr/missing.lua' "$tmpdir/err" ||
fail "refresh-config reports missing shipped config"

pass "refresh-config validates against OMARCHY_PATH/config"

mkdir -p "$omarchy_path/config/hypr" "$omarchy_path/config/etc" "$omarchy_path/.ssh" "$home/.ssh"
printf 'shipped\n' >"$omarchy_path/config/hypr/hyprland.lua"
printf 'prefixed-hosts\n' >"$omarchy_path/config/etc/hosts"
printf 'escaped-ssh\n' >"$omarchy_path/.ssh/authorized_keys"
printf 'secret\n' >"$home/.ssh/authorized_keys"
printf 'outside\n' >"$omarchy_path/README"

# /etc/hosts is joined as $OMARCHY_PATH/config/etc/hosts; plant that so the
# existence check would pass without the new absolute-path guard. Traversal
# dests are $home/README and $home/.ssh/authorized_keys.
for bad in \
"../README" \
"hypr/../../README" \
"hypr/../../.ssh/authorized_keys" \
"/etc/hosts"
do
if HOME="$home" OMARCHY_PATH="$omarchy_path" "$ROOT/bin/omarchy-refresh-config" "$bad" >"$tmpdir/out" 2>"$tmpdir/err"; then
fail "refresh-config refuses '$bad'"
fi
grep -Fq "Not a shipped user config: $bad" "$tmpdir/err" ||
fail "refresh-config names the refusal for '$bad'" "$(cat "$tmpdir/err")"
done

[[ $(<$home/.ssh/authorized_keys) == "secret" ]] ||
fail "refresh-config does not write ~/.ssh/authorized_keys through .."
[[ ! -e $home/README ]] ||
fail "refresh-config does not write $HOME/README through .."
[[ ! -e $home/.config/etc/hosts ]] ||
fail "refresh-config does not copy a prefixed /etc/hosts into ~/.config"

pass "refresh-config refuses .. and absolute paths"