Skip to content

Harden omarchy-refresh-config against path traversal - #10413

Merged
dhh merged 3 commits into
omacom:quattrofrom
DegenApeDev:fix/refresh-config-traversal
Nov 18, 2026
Merged

dhh merged 3 commits into
omacom:quattrofrom
DegenApeDev:fix/refresh-config-traversal

Conversation

@DegenApeDev

@DegenApeDev DegenApeDev commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

omarchy-refresh-config interpolated its argument directly into both paths and only validated with [[ -e ]] on the source side:

user_config_file="${HOME}/.config/$config_file"
default_config_file="$OMARCHY_PATH/config/$config_file"

A name containing .. (e.g. ../.bashrc, hypr/../../.ssh/config) resolves and copies outside ~/.config — overwriting arbitrary user files (with a misleading backup) or, if the source side also escapes, copying arbitrary repo files into the home directory. AGENTS.md even documented this as known behavior.

Change

  • Reject absolute paths and any .. path segment up front with Invalid config path.
  • Canonicalize both sides with realpath -m and verify they stay under ~/.config and $OMARCHY_PATH/config before touching anything (covers symlink / a/../b edge cases the segment check could miss).
  • Updated the Refresh Pattern note in AGENTS.md that described the old behavior.

Tests

  • Extended test/shell.d/refresh-config-test.sh: ../escape, hypr/../../escape, and /etc/passwd are rejected; files outside .config are untouched.
  • test/shell.d/refresh-config-test.sh and ./test/cli pass. Full ./test/all shows only the 6 pre-existing environmental failures (missing omarchy-pkgs checkout, no compositor/network) — verified identical on the clean base.

Fixes #8423

omarchybot and others added 2 commits September 6, 2026 05:31
The escape only fires when the mirrored source exists, because the
pre-existing "Not a shipped user config" check rejects everything else on
the source side first. With no file at $OMARCHY_PATH/escape, three of the
four cases passed against the unfixed script: deleting the */../* or the
/* alternative from the guard left the suite green, and the assertion on
$tmpdir/escape watched a path neither side of the copy ever names.

Create the mirrored source, watch the destination the traversal would
actually reach ($HOME/escape), and require the guard's own message for
every rejected shape. Each of the five alternatives now fails a test when
it is removed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
user_config_file is built by concatenating config_base, a slash and the
argument, and is then tested against "$config_base"/*. Bash's * matches
every possible suffix, including slashes and newlines, so both halves of
that condition are false for every input: deleting the whole realpath
block changes no outcome, and deleting the lexical guard above it leaves
the traversal tests failing.

realpath -m ran on the two bases only, never on the completed paths, so
it never canonicalized anything a caller supplies. Saying otherwise in
AGENTS.md promises containment the code does not provide, and the next
reader would trust it. The lexical guard is the whole protection; say so,
and say that symlinks under ~/.config are still followed, because
resolving them would reject the dotfile setups that work today.

Co-Authored-By: Codex XHigh <noreply@openai.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5 with an independent second opinion from Codex at xhigh reasoning. The guard is correct and I have pushed two commits to this branch: 876f78e4 and 3550c71a.

The guard itself holds. I ran the real binary on a disposable Omarchy VM against ../escape, hypr/../../escape, hypr/./../../outside, .., hypr/.., /etc/passwd, a name containing a newline, a $(...) name, %2e%2e/, .../, and the empty string. Every escaping shape exits 1 with Invalid config path and nothing outside the two trees is touched. Neither reviewer found an argument that gets past it.

No regression. All 41 files shipped under config/ still refresh successfully through the new guard, and every literal passed by the in-repo callers (bin/omarchy-refresh-*, migrations/1786273938.sh) is among them. That was the risk worth checking on a change like this, and it is clear.

The tests did not test the guard — this is Codex's finding, and mutation on the worker confirmed it. The escape only fires when the mirrored source exists, because the pre-existing Not a shipped user config check rejects everything else on the source side first. With no file at $omarchy_path/escape, deleting the */../* alternative from the guard left the suite green, and so did deleting the /* alternative; the assertion on $tmpdir/escape watched a path that neither side of the copy ever names. 876f78e4 creates the mirrored source, watches $HOME/escape where the traversal would actually land, and requires the guard's own message for each shape. All five alternatives now fail a test when removed individually.

The realpath containment check can never fire, so I removed it in 3550c71a. user_config_file is "$config_base/$config_file" and it is then tested against "$config_base"/* — bash's * matches every possible suffix, slashes and newlines included, so both halves of that condition are false for every input. realpath -m ran on the two bases only, never on the completed paths, so it canonicalized nothing a caller supplies. That means the PR description's claim that it "covers symlink / a/../b edge cases the segment check could miss" does not hold: a/../b is caught by the lexical guard on line 20, and symlinks are not resolved at all. I confirmed on the VM that removing the block changes no outcome — same rejections, same 41 accepted names.

I also rewrote the AGENTS.md note to match, because it had inherited the same claim. On symlinks specifically: I would not tighten this. If ~/.config/hypr points at a dotfiles directory, a real realpath containment check would start rejecting a setup that works today, so following the symlink is the right behaviour and the note now says so plainly rather than implying containment.

On severity, for whoever merges this: worth stating accurately in the description. Every caller in the repo passes a fixed literal, so there is no attacker-controlled path into this argument today; the only source of an arbitrary value is a person typing it, or an agent following omarchy refresh config <config-file> from default/agents/skills/omarchy/SKILL.md. And on the base version the escape needed the traversed source to exist too — ../.bashrc and hypr/../../.ssh/config from the description both exit 1 with Not a shipped user config, because $OMARCHY_PATH/config/../.bashrc is not there. What did work on base, and I verified it, is copying a file that exists in or above the repo tree to the mirrored location relative to ~/.config: ../rootfile wrote $OMARCHY_PATH/rootfile over $HOME/rootfile. So this is worthwhile hardening rather than a live vulnerability, and the description overstates it.

Tests run on the worker VM: ./test/cli green, test/shell.d/refresh-config-test.sh 3/3 green after both commits.

Where Codex agreed with the containment-check analysis I had already reached the same conclusion, and its independence is not currently guaranteed, so weigh that as agreement rather than confirmation. The vacuous-test finding was its own and is the reason 876f78e4 exists.

Nothing else outstanding from my side; this is waiting on a maintainer.

@chessing234

Copy link
Copy Markdown
Contributor

hey, this is already covered in #12718 (refresh-config path hardening). mind closing this as a duplicate?

@DegenApeDev

Copy link
Copy Markdown
Contributor Author

hey, this is already covered in #12718 (refresh-config path hardening). mind closing this as a duplicate?

I would if it was before this PR but its literally #12718 so yours is the duplicate

@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 2, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-checked at 3550c71a against current quattro (821ae589), which still has the bug, and linked #8423, which this fixes.

Reproduced on a disposable Omarchy VM. With quattro's script, omarchy-refresh-config ../rootfile overwrote $HOME/rootfile with $OMARCHY_PATH/rootfile and exited 0. On this head it exits 1 with Invalid config path and leaves the file alone. This PR's test/shell.d/refresh-config-test.sh passes on the head (3/3) and fails against quattro's script (refresh-config rejects ../escape), and ./test/cli is green. Every one of the 41 files under config/ still refreshes through the guard, which covers every name the in-repo callers pass.

Competing fix. #13214 makes the same change to the same base. I compared the two guards input by input with Codex at medium effort, and we reached the same answer: for absolute paths and every position of a .. component they reject exactly the same inputs, and neither rejects a shipped config. #13214 additionally refuses newline and carriage-return characters, which are ordinary filename characters here and open no further route out of ~/.config; a newline paired with .. is already rejected by this guard, because bash's * matches newlines. This PR's tests also pin each of the guard's five alternatives to a case that fails when that alternative is removed, which Codex checked separately. So this is the one carried forward, and #13214 is named to the maintainer beside it. #12718, mentioned above, no longer touches omarchy-refresh-config: its author moved that change to #13214.

Codex reviewed the diff and found no defects; where it agreed with conclusions I had already reached, its independence is not guaranteed. Nothing is waiting on the author. This now waits on a maintainer.

@dhh
dhh merged commit eb701f1 into omacom:quattro Nov 18, 2026
omarchybot added a commit to Sebo1411/omarchy that referenced this pull request Nov 18, 2026
Keep the shell.json permission coverage alongside the path traversal regression from omacom#10413. Both exercise omarchy-refresh-config and neither replaces the other.

Co-Authored-By: GPT-6.2 (high) <noreply@openai.com>
@aholbreich aholbreich mentioned this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review

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

4 participants