Skip to content

[Security] Refuse a refresh-config path that could write outside ~/.config - #8424

Closed
chessing234 wants to merge 2 commits into
omacom:quattrofrom
chessing234:security/refresh-config-path-guard
Closed

chessing234 wants to merge 2 commits into
omacom:quattrofrom
chessing234:security/refresh-config-path-guard

Conversation

@chessing234

@chessing234 chessing234 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8423.

omarchy-refresh-config joins its argument onto ~/.config and $OMARCHY_PATH/config with no check for .. or an absolute path. omarchy-refresh-config hypr/../../.ssh/authorized_keys would write outside ~/.config if a matching source existed; omarchy-refresh-config /etc/hosts skips ~/.config entirely.

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):

ok - refresh-config copies from OMARCHY_PATH/config and backs up existing files
ok - refresh-config validates against OMARCHY_PATH/config
ok - refresh-config refuses .. and absolute paths

The last case plants a file at ~/.ssh/authorized_keys and 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.

Copilot AI balanced review requested due to automatic review settings August 26, 2026 16:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread test/shell.d/refresh-config-test.sh Outdated
Comment on lines +43 to +51
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"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 itz4blitz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 catches hypr/../../README, which survives naive prefix checks and is exactly the shape the test uses to prove the old .ssh/authorized_keys clobber 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.

@chessing234

Copy link
Copy Markdown
Contributor Author

empty string is pre-existing and just recopies ~/.config onto itself. leaving it.

@chessing234

Copy link
Copy Markdown
Contributor Author

@dhh @ryanrhughes ready for review

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.
@chessing234
chessing234 force-pushed the security/refresh-config-path-guard branch from d3567fb to 9f31cd1 Compare September 14, 2026 07:34
@chessing234

Copy link
Copy Markdown
Contributor Author

rebased onto tip; path traversal still present there.

@chessing234

Copy link
Copy Markdown
Contributor Author

folded into #12718 for easier review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] omarchy-refresh-config will write outside ~/.config given .. or an absolute path

3 participants