Repository navigation
[Security] Refuse a refresh-config path that could write outside ~/.config - #8424
chessing234 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Hardens config refresh paths against traversal outside ~/.config.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Changes:
- Rejects absolute paths and
..components. - Adds regression tests for rejected paths.
- Updates contributor guidance.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
bin/omarchy-refresh-config |
Adds path validation. |
test/shell.d/refresh-config-test.sh |
Tests traversal and absolute paths. |
AGENTS.md |
Documents path restrictions. |
Suppressed comments (1)
test/shell.d/refresh-config-test.sh:63
- Neither traversal input targets
.ssh/authorized_keys, and both resolve their destination to$home/README, not$home/.config/README. These assertions therefore remain green even if a rejected invocation writes the escaped destination before returning nonzero. Assert the actual escaped destination instead.
[[ $(<$home/.ssh/authorized_keys) == "secret" ]] ||
fail "refresh-config does not write outside ~/.config through .."
[[ -e $home/.config/README ]] &&
fail "refresh-config does not copy a path that escaped OMARCHY_PATH/config"
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| printf 'shipped\n' >"$omarchy_path/config/hypr/hyprland.lua" | ||
| printf 'secret\n' >"$home/.ssh/authorized_keys" | ||
| printf 'outside\n' >"$omarchy_path/README" | ||
|
|
||
| for bad in \ | ||
| "../README" \ | ||
| "hypr/../../README" \ | ||
| "/etc/hosts" \ | ||
| "$omarchy_path/config/hypr/hyprland.lua" |
There was a problem hiding this comment.
planted a source at $OMARCHY_PATH/config/etc/hosts so /etc/hosts only fails the new guard. also asserting $HOME/README and authorized_keys, which is where the join actually writes.
itz4blitz
left a comment
There was a problem hiding this comment.
Reviewed against issue #8423. The gate is correct and complete for the reported hole:
- Absolute paths rejected (
!= /*) before any resolution happens. - Every
..component rejected by splitting on/— this catcheshypr/../../README, which survives naive prefix checks and is exactly the shape the test uses to prove the old.ssh/authorized_keysclobber is gone. - The refusal happens before the
[[ -e ]]shipped-config check, so a..path that does resolve to something inside$OMARCHY_PATH(like../README) is refused on shape, not on existence. That's the right order: the question is "is this a shipped user config," and shape answers it before the filesystem can be consulted about a path that already escaped.
Edge cases I tried to get past it and couldn't: hypr//../../x (empty parts aren't .. but the ..s still get caught), trailing-slash variants, newline-in-path (read stops at the newline, and the -e check then rejects the odd remainder), and an embedded whitespace part (not .., but the shipped-config check rejects it as nonexistent).
The test matrix (../README, hypr/../../README, /etc/hosts, absolute-but-legit) plus the two "nothing was written outside" assertions is exactly the coverage this needs. The AGENTS.md correction is a nice touch — the doc was teaching the unsafe call as the example.
One non-blocking observation: the empty-string argument (omarchy-refresh-config "") slips past the new gate (no .. parts, not absolute) and falls through to the -e "$OMARCHY_PATH/config/" check, which succeeds because that's a directory. That's pre-existing behavior this PR doesn't change, and the result is a harmless .config/ self-copy — but if you ever tighten it, [[ -n $config_file ]] at the top is the one-liner.
|
empty string is pre-existing and just recopies ~/.config onto itself. leaving it. |
|
@dhh @ryanrhughes ready for review |
ca139f0 to
d3567fb
Compare
The path is joined onto both the shipped config tree and ~/.config, so a `..` component copied whatever it resolved to. Callers already pass plain relative names; reject anything else instead of following it.
/etc/hosts is joined onto $OMARCHY_PATH/config, so plant a source there. Assert the real traversal destinations ($HOME/README and authorized_keys) instead of a path the old join never wrote.
d3567fb to
9f31cd1
Compare
|
rebased onto tip; path traversal still present there. |
|
folded into #12718 for easier review. |
Fixes #8423.
omarchy-refresh-configjoins its argument onto~/.configand$OMARCHY_PATH/configwith no check for..or an absolute path.omarchy-refresh-config hypr/../../.ssh/authorized_keyswould write outside~/.configif a matching source existed;omarchy-refresh-config /etc/hostsskips~/.configentirely.This refuses those before the join, with the same
Not a shipped user config:message already used for a path that is not shipped.Verification
test/shell.d/refresh-config-test.sh(existing copy/backup cases plus the new refusals):The last case plants a file at
~/.ssh/authorized_keysand a source at$OMARCHY_PATH/README, then runs../README,hypr/../../README,/etc/hosts, and an absolute path into$OMARCHY_PATH/config. All four exit 1; the ssh file is untouched.