Skip to content

Pin trusted PATH in privileged DNS helper - #8172

Merged
dhh merged 3 commits into
omacom:quattrofrom
mdisec:harden-omarchy-dns-secure-path
Aug 25, 2026
Merged

dhh merged 3 commits into
omacom:quattrofrom
mdisec:harden-omarchy-dns-secure-path

Conversation

@mdisec

@mdisec mdisec commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Harden omarchy-dns against PATH hijacking when it runs with root privileges.

Once the script has an effective UID of root, it now replaces PATH with trusted system directories before invoking helpers such as dirname, install, tee, rm, nmcli, systemctl, and awk.

Security issue

omarchy dev link adds the user-writable checkout’s bin/ directory to sudo’s secure_path. This ensures privileged Omarchy commands resolve to development versions, but it also affects subprocesses launched by those commands.

Omarchy permits wheel users to run the following commands without a password:

  /usr/bin/omarchy-dns Cloudflare
  /usr/bin/omarchy-dns Google
  /usr/bin/omarchy-dns DHCP

Although sudo executes the packaged /usr/bin/omarchy-dns, the script previously inherited the dev-
linked secure_path. Its bare helper commands could therefore resolve from the user-writable
checkout.

An attacker able to write to the checkout could place a malicious executable such as install in its
bin/ directory and trigger a permitted DNS change. The helper would then execute as root without
requiring a password.

Fix

When omarchy-dns detects that it is running as root, it sets:

PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin

The restriction is applied only after elevation. The unprivileged wrapper phase retains the caller’s
PATH so it can continue locating sudo or pkexec normally.

All helpers used by the privileged portion are system utilities, so it does not need access to the
dev checkout.

Tests

Added regression coverage which:

  • verifies that the trusted PATH is applied only while running as root;
  • places poisoned helper executables at the front of the invocation PATH;
  • confirms the privileged DNS script ignores those executables;
  • preserves the existing sudoers scope and elevation behavior.

Validation performed:

  ./test/shell.d/dns-sudoers-test.sh
  bash test/shell.d/dev-link-test.sh
  bash test/shell.d/bin-style-test.sh
  ./test/cli
  bash -n bin/omarchy-dns test/shell.d/dns-sudoers-test.sh
  git diff --check

Copilot AI balanced review requested due to automatic review settings August 25, 2026 06:40

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 privileged DNS operations against PATH hijacking.

Changes:

  • Pins root execution to trusted system paths.
  • Adds poisoned-PATH regression coverage.

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.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.

File Description
bin/omarchy-dns Pins PATH after privilege elevation.
test/shell.d/dns-sudoers-test.sh Tests trusted PATH behavior.

💡 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/dns-sudoers-test.sh Resolved
Comment thread test/shell.d/dns-sudoers-test.sh Resolved
A dev link prepends a user-writable checkout bin/ to sudo's secure_path,
so the passwordless `omarchy-dns Cloudflare` sudoers rule lets root
resolve a bare helper (dirname, install, tee, nmcli, ...) out of that
checkout — turning checkout-write access into arbitrary root execution.
Pin PATH to trusted system directories once EUID is 0, leaving the
unprivileged wrapper phase free to locate sudo/pkexec on the caller's
PATH.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YUWoHbBoKMjsjV6X3nu1H5
@mdisec
mdisec force-pushed the harden-omarchy-dns-secure-path branch from 464f59c to e7d8f89 Compare August 25, 2026 07:07
dhh and others added 2 commits August 25, 2026 09:32
The EUID assertion matched `(( EUID == 0 ))` anywhere in the file, and require_root has carried that exact test since long before the pin existed. Deleting the pin left the assertion passing, so it stood for nothing: a run with the pin neutered reached the behavioural probe with both greps green. Anchor on the unindented guard and require the pin to be the line it opens, which no other construct in the script satisfies.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
`fail` ends the file, so a sandbox or hardened kernel that refuses unprivileged user namespaces did not just lose the probe — it took the two elevation assertions below it down as well, reporting a product defect where there was only a missing capability. The non-graphical suites are meant to run on any machine and treat a skip as a passing test, the way require_compositor and plugin-add-test.sh already do. Gate the probe on the namespace it needs and say so when it is absent; the static checks above and the elevation checks below run either way.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed, and the escalation is real. omarchy dev link writes a bare Defaults secure_path that puts the checkout's bin/ first, etc/sudoers.d/omarchy-dns grants %wheel three passwordless invocations, and until this change anyone who could write to a dev-linked checkout got root from one click in the network panel by dropping an install, cat or tee in there. The pin is placed right: it runs before any external command, and it costs nothing legitimate, because omarchy-dns calls no omarchy-* command and reads no $OMARCHY_PATH — which is the only thing that secure_path entry exists to serve. I also checked whether this was one of several affected entry points and it is not: omarchy-asdcontrol and omarchy-tzupdate name ELF binaries, omarchy-passwd-tries only sets passwd_tries, and no polkit rule grants another passwordless shell path.

Two defects in the new test, both fixed and pushed to this branch.

2ac199b5 — grep -Eq '\(\( EUID == 0 \)\)' "$dns" passed vacuously. require_root has carried that exact construct at bin/omarchy-dns:60 since long before the pin existed, so the assertion is satisfied by the pre-PR file: delete the pin and it still passes. It now anchors on the unindented guard and requires the pin to be the line it opens, which nothing else in the script satisfies.

991bcf3e — the probe called fail when unprivileged user namespaces were unavailable. fail ends the file, so on a sandbox or a hardened kernel that did not merely lose the probe, it took the two elevation assertions below it down as well and reported a product defect where there was only a missing capability. docs/testing.md asks these suites to stay runnable on any machine and treats a skip as a passing test, the way require_compositor and plugin-add-test.sh:147 already do, so the probe is now gated on the namespace it needs and says so when it is absent.

The behavioural probe itself earns its place and I left it alone: neuter the pin and the poisoned tr gets resolved and it fails, which is exactly what it is for. Both of my changes were proven the same way — mutate, watch the right assertion fail, restore.

One thing left to you rather than fixed, since it is your prose: the comment at bin/omarchy-dns:13 says it names every helper called by bare name, and it omits cat (:152, privileged on Cloudflare, Google and Custom) along with tr and xargs (:123, privileged on Custom) — and xargs invoked with no command resolves echo through PATH too. It also lists awk, which in production only ever runs unprivileged, since current_dns_provider exits at :243 before require_root at :256. The pin covers all of them, so nothing behaves wrongly; it is the completeness claim a later editor might lean on.

Your two Copilot comments were both fair against 464f59c7 and are already answered by e7d8f899, so there is nothing outstanding there.

A second opinion from Codex at xhigh reasoning reached the same two test findings and no others, found no defect in the production change, and contributed the xargs/echo detail above.

Everything ran on a disposable VM rather than a machine that matters: ./test/cli is 116 ok with no failures, and dns-sudoers-test.sh, dev-link-test.sh, dev-unlink-test.sh, bin-style-test.sh and network-manager-transition-test.sh are all green with the two commits on top. Full ./test/shell is 196 of 198 files — ascii-test.sh and branding-about-animation-test.sh fail identically on quattro without this branch, so they are not yours.

🤖 Generated by Opus 5 in Claude Code. Reviewed by Codex XHigh.

@dhh
dhh merged commit 4637735 into omacom:quattro Aug 25, 2026
omarchybot pushed a commit that referenced this pull request Aug 25, 2026
Backport of the DNS PATH pin (PR #8172 by @mdisec, merged to quattro as
4637735) onto the v4-0-1 release branch.

omarchy dev link prepends a user-writable checkout's bin/ to sudo's secure_path
so privileged Omarchy commands resolve to the development versions, and that
reaches the subprocesses they launch too. This branch carries the same
passwordless grant -- etc/sudoers.d/omarchy-dns lets wheel run
/usr/bin/omarchy-dns Cloudflare, Google and DHCP without a password -- so the
packaged script ran as root while resolving bare helpers (dirname, install,
tee, rm, nmcli, systemctl, awk) through the caller's secure_path. Write access
to a dev checkout became arbitrary root execution, with no password prompt in
the way.

Pin PATH to trusted system directories once EUID is 0. The restriction lands
only after elevation, so the unprivileged wrapper phase keeps the caller's PATH
and can still find sudo or pkexec; every helper the privileged half uses is a
system utility, so it needs nothing from the checkout.

Clean cherry-pick: both files are byte-identical to quattro, so merging v4-0-1
into quattro resolves without a conflict. Verified by mutation: with the pin
removed, test/shell.d/dns-sudoers-test.sh fails at the poisoned-helper case;
restored, all four of its cases pass. test/shell (189 files) and test/cli pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_018DEMYa9UWtroz93DhMTtcV
@omarchybot omarchybot mentioned this pull request Aug 25, 2026
nick1udwig pushed a commit to nick1udwig/omarchy that referenced this pull request Sep 9, 2026
* Pin PATH to trusted dirs when omarchy-dns holds root

A dev link prepends a user-writable checkout bin/ to sudo's secure_path,
so the passwordless `omarchy-dns Cloudflare` sudoers rule lets root
resolve a bare helper (dirname, install, tee, nmcli, ...) out of that
checkout — turning checkout-write access into arbitrary root execution.
Pin PATH to trusted system directories once EUID is 0, leaving the
unprivileged wrapper phase free to locate sudo/pkexec on the caller's
PATH.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YUWoHbBoKMjsjV6X3nu1H5

* Assert the trusted-PATH pin is gated on root, not merely present

The EUID assertion matched `(( EUID == 0 ))` anywhere in the file, and require_root has carried that exact test since long before the pin existed. Deleting the pin left the assertion passing, so it stood for nothing: a run with the pin neutered reached the behavioural probe with both greps green. Anchor on the unindented guard and require the pin to be the line it opens, which no other construct in the script satisfies.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>

* Skip the DNS trusted-PATH probe where user namespaces are unavailable

`fail` ends the file, so a sandbox or hardened kernel that refuses unprivileged user namespaces did not just lose the probe — it took the two elevation assertions below it down as well, reporting a product defect where there was only a missing capability. The non-graphical suites are meant to run on any machine and treat a skip as a passing test, the way require_compositor and plugin-add-test.sh already do. Gate the probe on the namespace it needs and say so when it is absent; the static checks above and the elevation checks below run either way.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: David Heinemeier Hansson <[email protected]>
Co-authored-by: Codex XHigh <[email protected]>
@emirb emirb added this to the 4.5 milestone Oct 17, 2026
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.

5 participants