Skip to content

Reject path traversal in omarchy-refresh-config - #13214

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

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

Conversation

@chessing234

@chessing234 chessing234 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Refuse .. components and absolute paths before joining onto ~/.config / $OMARCHY_PATH/config, so refresh cannot write outside the user's config tree.

Fixes #8423

Test plan

  • bash test/shell.d/refresh-config-test.sh

@llstrk

llstrk commented Sep 25, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: the new guard refuses absolute paths and .. components with Not a shipped user config: <arg> and exit 1, before any mkdir, backup or copy. Legitimate relative paths still copy as before, and the added test fails on the base script and passes on this head. One narrow gap remains for arguments containing a newline, plus a stale note in AGENTS.md.

Results in private fixtures (synthetic HOME and OMARCHY_PATH, source planted for each case):

Argument Base This PR
../README, hypr/../../README writes $HOME/README refused, no write
hypr/../../.ssh/authorized_keys overwrites ~/.ssh/authorized_keys refused, no write
/etc/hosts writes ~/.config/etc/hosts refused, no write
hypr/hyprland.lua, ./hypr/hyprland.lua, hypr//hyprland.lua, hypr/..hidden.lua, hypr/my file.lua copies into ~/.config same

Every in-repository caller (bin/omarchy-refresh-* and the migrations) passes a plain relative path, so none is affected by the new refusal.

A newline in the argument skips the .. check

IFS=/ read -ra config_parts <<< "$config_file" reads only up to the first newline, but both paths are still built from the full argument:

arg = $'hypr\n/../../README'
read -ra splits: [hypr]              -> no ".." seen, guard passes
destination:     ~/.config/hypr\n/../../README  -> $HOME/README

Impact: limited. The existing [[ -e $default_config_file ]] check still refuses this argument unless a directory whose name contains a newline exists under $OMARCHY_PATH/config. None is shipped. With such a directory planted in a diagnostic fixture, this head copied $OMARCHY_PATH/README to $HOME/README (base behaves the same). So this is a gap in the new validation rather than a practical escape in a stock install.

Suggested change: test the whole string instead of splitting it. This matches the pattern style used elsewhere in bin/, gave the same result as the current guard on every newline-free input tried, and also refuses the newline case:

if [[ $config_file == /* || /$config_file/ == */../* ]]; then
  echo "Not a shipped user config: $config_file" >&2
  exit 1
fi

Documentation

Suggested change: AGENTS.md (the omarchy-refresh-config paragraph near line 131) still says a name containing .. "resolves and copies, landing outside ~/.config rather than being rejected". After this PR that is no longer true and could be updated to state the new rule. The new code comment also says an absolute path "could land the write outside ~/.config"; on base, /etc/hosts was joined under both roots and wrote ~/.config/etc/hosts, so the stated reason for refusing it could be reworded (the test comment already describes this correctly).

Optional test improvement: [[ $(<$home/.ssh/authorized_keys) == "secret" ]] leaves the redirection target unquoted. With a TMPDIR containing a space, the test fails with "ambiguous redirect" even though the script behaved correctly. $(<"$home/.ssh/authorized_keys") avoids this.


Review information

Test scope: source review of the pinned head and merge-base, plus sandboxed command-only runs of the script and test/shell.d/refresh-config-test.sh against synthetic home and Omarchy trees (Bash 5.3). Symlinks already present inside ~/.config still redirect writes as before; this is pre-existing and was not treated as part of this change. Not tested on a live desktop.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@chessing234

Copy link
Copy Markdown
Contributor Author

also refuse newlines in the config path

@chessing234

Copy link
Copy Markdown
Contributor Author

switched to a whole-string .. check, refused newlines, and updated the agents note

@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Follow-up to the earlier review, checked at 69a12f60 after the author's update.

Verified: all four earlier points are resolved. One small gap remains in the new test case.

Earlier point Status at 69a12f60
Newline in the argument skipped the .. check Resolved. The split is replaced by the whole-string /$config_file/ == */../* test, and \n and \r are also refused. With a hypr<newline> directory planted so the existence check passes, hypr\n/../../README is refused with no write; ef782bc5 and base both write $HOME/README.
Stale AGENTS.md note Resolved. The new sentence matches the behaviour.
Code comment on why absolute paths are refused Resolved. It now gives the /etc/hosts → ~/.config/etc/hosts case.
Unquoted redirection in the test Resolved. With a TMPDIR containing a space, the test passes at this head and fails with "ambiguous redirect" at ef782bc5.

Verified: the earlier results still hold. Absolute paths and every .. form tried are refused with Not a shipped user config: <arg> and exit 1, and nothing is written. Legitimate relative paths still copy as on base (including ./hypr/hyprland.lua, hypr//hyprland.lua, hypr/..hidden.lua and hypr/my file.lua). Every in-repository caller still passes a plain relative path. The only newly refused names are those containing a newline or \r anywhere (for example hypr/a<newline>b.lua, which ef782bc5 and base copy). No caller uses such names. Results were the same with extglob and nocasematch inherited and under LANG=C.

Optional test improvement: the new newline case (test/shell.d/refresh-config-test.sh, lines 74-81) passes against every version of the script, including base with no guard at all. Nothing creates $omarchy_path/config/hypr<newline>, so the existing [[ -e ]] check would refuse the argument even without the new guard.

Script Case as shipped With the directory planted
this head passes passes
ef782bc5 (split-based guard) passes fails
base (no guard) passes fails

Adding this line before the case makes it catch a return of the newline gap:

mkdir -p "$omarchy_path/config/hypr"$'\n'

Even then, the case passes with the separate newline clause removed, because its .. also trips the whole-string check. A planted file such as config/hypr/a<newline>b.lua (newline inside the file name, no ..) would cover that clause directly: with the clause removed it is copied.

Optional wording: the code comment (lines 22-23, "truncate a split-based scan") and the test comment (lines 74-75, "truncate the .. scan") justify the newline refusal by a scan that the whole-string check no longer performs. The test comment also says "control characters", but only \n and \r are refused (a tab is accepted).

Related PR: open #12718 (same author) still contains byte-identical copies of the ef782bc5 script and test, including the split-based guard and the unquoted redirection, and edits the same AGENTS.md paragraph. Syncing or dropping that part of #12718 would avoid bringing the newline gap back if both land.


Review information

Test scope: source review of 69a12f60 against ef782bc5 and the merge-base, plus sandboxed command-only runs of the script and test/shell.d/refresh-config-test.sh (as shipped and with the planted directory) against synthetic home and Omarchy trees (Bash 5.3). The full test/shell suite, routing through bin/omarchy and the migrations were not run. Related open PRs were checked only for overlapping files. Not tested on a live desktop.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; the previously identified test gap is closed.

Summary

The PR rejects absolute paths, .. components, and line breaks in refresh-config arguments before constructing source and destination paths. It documents the restriction and adds regression tests. The previously reported newline-test weakness is fixed.

Reviews (3) · Last reviewed commit: "Exercise the newline path guard with a s..." · Reviewed by Greptile

@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 4a29c69d against quattro (a85e29ab), with the bug reproduced on a disposable Omarchy worker. Nothing to fix.

Reproduction. In a throwaway HOME and OMARCHY_PATH, ../README wrote $HOME/README, hypr/../../.ssh/authorized_keys overwrote ~/.ssh/authorized_keys, and /etc/hosts was copied to ~/.config/etc/hosts. That happened on quattro and on this branch with the old bin/omarchy-refresh-config put back. On this head all three are refused with Not a shipped user config: <arg> and nothing is written. hypr/hyprland.lua, ./hypr/hyprland.lua, hypr//hyprland.lua and hypr..x/a.lua still copy. Every in-repository caller in bin/ and migrations/ passes a plain relative path, so none of them is affected.

Tests. test/shell.d/refresh-config-test.sh (5 passed) and test/shell.d/config-test.sh (30 passed) ran on the worker. The new traversal case fails against the old script. ./test/cli stops at vscode generated theme references current theme file, and current quattro stops at the same test, so this change did not cause it. That red suite is the one thing keeping this from being marked ready.

Second opinion. Codex Medium reviewed the same head separately and found no defects. It agreed the guard catches every .. form, including a trailing hypr/.., and gives the same results with extglob and nocasematch on or off. Its review is not guaranteed to be independent of this one. It also noted two harmless extras. The \n/\r refusal is no longer needed for traversal now that the .. check tests the whole string. The test comment near line 75 refers to an "old split-based scan" that is not in quattro's script.

This closes #8423. It is waiting on the maintainer, and on the unrelated test/cli failure on quattro.

@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

For triage: #10413 (opened Sep 6) hardens the same script against the same traversal from #8423. This one also refuses newlines/CR and carries a regression test. It's probably worth picking one so the other can be closed. The bug is still present on current quattro.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 18, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

The traversal fix landed in #10413 at eb701f1f99b71bc2fd6b814a5b1d6c8794f2c993. I compared this unchanged head (4a29c69d) with current quattro (b4712385) on a disposable Omarchy worker: both reject the traversal cases, including the newline-plus-.. case, and absolute paths. Ordinary relative paths still copy. The historical vulnerable script and this head with its guard removed allow the traversal writes in throwaway homes.

refresh-config-test.sh passed 5 checks and config-test.sh passed 30. Another 44 isolated checks compared the historical script, current base, head, and reverted guard. The full suite was not run in this review.

What remains different is the rejection of filenames containing a newline or carriage return without .., with tests for that behavior. Current quattro accepts those filenames in a fixture; neither tree ships them. That extra behavior means this is not an exact duplicate of #10413. This PR now conflicts, and it is waiting on the maintainer to decide whether to retain that additional restriction. No changes were pushed.

GPT-6 in Codex reviewed this item (driver effort is not exposed). Opus 5.5 High and muse-wonder via pi (thinking high) supplied second opinions and agreed that the original defect is covered and the extra restriction needs a maintainer decision; independence from the driver's review is not guaranteed.

quattro already rejected absolute paths and .. segments. a newline still slipped past that check.
@chessing234
chessing234 force-pushed the fix/8423-refresh-config-path-guard branch from 4a29c69 to 6fdf144 Compare November 20, 2026 02:47
Comment thread test/shell.d/refresh-config-test.sh Resolved
@omarchybot omarchybot removed the bug Something isn't working label Nov 20, 2026
@chessing234

Copy link
Copy Markdown
Contributor Author

@dhh when you get a chance: this closes a path traversal in omarchy-refresh-config. small diff, easy to verify.

@aholbreich

Copy link
Copy Markdown
Contributor

For the maintainer: the traversal from #8423 is already closed by #10413 (merged Nov 18; issue closed). After the Nov 20 rebase, this PR only adds rejecting line breaks in the argument. A newline plus .. is already refused on quattro, so this blocks odd file names, not a traversal. It merges cleanly, and its new test fails on quattro's script and passes on this head. Whether to keep the extra restriction is the maintainer's call. Thanks @chessing234 for the original report.

@omarchybot omarchybot added the enhancement New feature or request label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

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

5 participants