Repository navigation
[Security] Stage diagnostics where only their owner can read them - #8370
chessing234 wants to merge 9 commits into
Conversation
omarchy-debug wrote `sudo dmesg`, the journal and a full hardware inventory to /tmp/omarchy-debug.log, and omarchy-upload-log assembled what it publishes at /tmp/upload-log.txt and /tmp/system-info.txt. /tmp is world-writable, so any other local account can create those names first and read what the command collected, plant a symlink and redirect the write, or swap the upload payload between the last append and the POST. Put the debug log under the per-user runtime directory at mode 600, and stage the upload in a mktemp directory that is removed on exit.
There was a problem hiding this comment.
Pull request overview
Secures diagnostic staging against predictable /tmp path attacks.
Changes:
- Stores debug logs in a private per-user location.
- Uses a temporary upload staging directory with cleanup.
- Adds regression tests and updates documentation.
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 3 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
bin/omarchy-debug |
Secures debug-log storage. |
bin/omarchy-upload-log |
Privately stages upload payloads. |
test/shell.d/diagnostics-staging-test.sh |
Tests staging security and cleanup. |
default/agents/skills/omarchy/contributing.md |
Updates diagnostic-path guidance. |
default/agents/skills/diagnose-crash/reporting.md |
Updates crash-reporting guidance. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
GNU mktemp -d with no template creates its directory inside /tmp, so the test rejected the very implementation it was meant to check. The boundary is that the directory is unpredictable and only its owner can enter it, so read its mode from inside the upload, while it still exists, and keep rejecting the shared fixed name it replaced. Name the state-directory fallback in both skill docs too: without a session runtime directory the log is written there, not under XDG_RUNTIME_DIR.
|
good catch on the mktemp one — gnu mktemp -d puts its dir under /tmp, so that assertion would have failed on arch against the fixed script. now checks the staging dir is 0700 and isn't the old shared name, read from inside the upload while it still exists. docs name the state-dir fallback too. |
Moving off /tmp gives the log a directory that can fail to exist: a stale XDG_RUNTIME_DIR from a revoked session, an inherited one belonging to another uid, a full runtime tmpfs, a read-only home on the fallback path. The script runs without `set -e`, so `mkdir -p` and `install` failing left every later write failing too and `omarchy debug --no-sudo --print` -- the form the agent skills tell agents to use -- exiting 0 with nothing on stdout. Verified on an Omarchy machine before and after: an unwritable log_dir printed four unrelated errors and returned success, and now returns 1 with one error. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Reviewed at 56842ec by Claude Opus 5 in Claude Code, with a second pass from Codex at xhigh reasoning. Everything executed ran on a disposable Omarchy VM, never on the machine doing the review. The change is right; I pushed one fix to your branch and there are two things worth correcting in the text rather than the code. Pushed: 56842ec — Fail loudly when the debug log cannot be created. Moving off The threat model overstates what
Checked and clean. Nothing else in the repo or in what it ships reads the three old paths; the only remaining mentions are the negative assertions in the new test. The Tests, all on a disposable Omarchy VM: Related: #7995, open since 24 Aug, changes the same two scripts, both of the same doc files, and adds a test at the identical path Codex's independence is not currently guaranteed — it can read this session's own working notes — so treat its agreement on the ignored-failure defect as agreement rather than confirmation. The |
Two claims in the comments were wrong, both caught on a live worker with protected_regular and protected_symlinks on by default: a pre-created world-writable /tmp file makes the redirect fail closed rather than succeed into it, and the same for a symlink. What is real on its own is plain disclosure of the file left behind at the default umask, and (for the upload) the payload swap between the last write and the POST, which the staging directory's own mode -- not a directory outside /tmp -- is what stops.
itz4blitz
left a comment
There was a problem hiding this comment.
Reviewed against issue #8367 — this is solid and I'd merge it. Specifics worth keeping when it lands:
- The threat model in the comment is precise: it isn't just the clobber, it's that
/tmp/omarchy-debug.logholdssudo dmesg, the journal and a hardware inventory the invoking uid can't otherwise read, world-readable by umask, surviving until reboot. Relocating to the 0700 per-user runtime dir fixes both halves at once. - The
install -m 600 /dev/nullpre-create is the right trick — it guarantees the mode regardless of umask and lets the writers truncate an already-private file. - The fail-fast on an unusable
log_dir(staleXDG_RUNTIME_DIR, full tmpfs, read-only home) with--printexiting nonzero instead of silently printing nothing is the kind of thing that's invisible until it eats someone's bug report. - The upload-log half closing the swap-window between staging and publishing is a real fix, not belt-and-braces: the payload is what gets published under the user's name, and a fixed
/tmpname made it replaceable by anyone between the last write and the curl. - The curl-stub test asserting the payload path and the directory mode rather than implementation details is well aimed.
Two non-blocking suggestions:
- The fallback branch (
XDG_RUNTIME_DIRunset → state dir) has no test coverage — only the runtime-dir branch is exercised. Aenv -u XDG_RUNTIME_DIRrun with a fakeHOMEasserting the state-dir path would pin the resolution thatomarchy-debug --print's own error message depends on. diagnose-crash/reporting.mdnow tells agents the log is at$XDG_RUNTIME_DIR/omarchy-debug.log; if a helper ever needs to find that file programmatically, the resolution is now duplicated in prose in two docs. Worth a shared note if a third copy appears.
For coverage of the same class in files this PR doesn't touch: #8429 (update transcript, also feeds omarchy-update-analyze-logs on readback) and #8430 (Battle.net installer log) follow this PR's resolution and test style.
|
leaving the unset-runtime-dir test; the fallback path is the same as the error message. |
The comment claimed another account could pre-create the fixed name and read what the upload gathered, or replace the staged file before the POST. Neither works on a stock Omarchy. Measured with a second unprivileged account on an Omarchy VM: fs.protected_regular makes the victim's redirect into an attacker-owned file fail with EACCES, the symlink variant fails the same way, and /tmp's sticky bit refuses the attacker an in-place write, an unlink and a rename over the 0644 file the victim did create. The only attempt that succeeded was reading that file, which is the vector the sibling comment in omarchy-debug already names. What pre-creating the name does do is worse than the comment said and in the other direction. Nothing here runs under `set -e`, so every failed redirect is ignored and `curl -F file=@/tmp/upload-log.txt` sends the attacker's file instead: run end to end against the base script with a stubbed curl, the upload was handed 55 bytes of attacker text and printed it as a successful upload of the user's log, at a URL the user then shares in a bug report. Staging in mktemp's directory closes that with the rest of it. Co-Authored-By: Codex XHigh <noreply@openai.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Re-reviewed at Both previous findings on the code are answered. Pushed: What pre-creating the name actually does is worse, and in the other direction. Codex went after this and it holds up end to end. Still open, and only you can fix them. The PR body carries the same two disproved mechanisms — "redirect the write through a symlink, or swap the upload payload between the last append and the One finding I did not push, because it is unchanged from the base and fixing it would widen a security change into general error handling: Your three replies check out. GNU Tests, all on a disposable Omarchy VM, at the pushed head: Waiting on the maintainer, not on you. #7995 is still open and still changes the same two scripts, both doc files, and adds a test at the identical path, so the two cannot both merge. Which shape is wanted is a call for the maintainer. |
|
The new paths secure future runs, but existing /tmp/omarchy-debug.log, /tmp/upload-log.txt, and /tmp/system-info.txt remain readable after upgrading; potentially until reboot or tmpfiles cleanup. Please add a migration that safely removes legacy files owned by the current user. |
The new staging paths secure future runs, but existing /tmp/omarchy-debug.log, /tmp/upload-log.txt, and /tmp/system-info.txt stay readable until reboot or tmpfiles cleanup. Drop ones owned by the current user, leaving symlinks and other-owned files alone.
|
@ErikMelton added a migration that deletes those three /tmp leftovers when they are regular files owned by the current user; symlinks and other-owned files are left alone. |
The comment credited the -L guard with stopping a redirected unlink of someone else's target. That cannot happen: `rm` never follows a symlink, and with fs.protected_symlinks=1 the `-f` test does not resolve another uid's link in sticky /tmp either -- measured on an Omarchy VM with a second unprivileged account, where the migration no-ops with the guard and without it. What the guard does prevent is the ordinary case: `-f` and `-O` both follow a symlink, so a link this user left at a legacy name passes both and gets unlinked in place of a leftover, which the same measurement showed happening once the guard is removed. Also stop calling 0644 a umask. Co-Authored-By: Codex XHigh <noreply@openai.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Re-reviewed at The migration is right. Run the way Pushed: One thing worth knowing, not pushed. Two test blind spots, also from Codex, both non-blocking. The symlink fixture at Previous findings. The No new review comments since the last pass. The three from Copilot and your three replies all predate it and were checked then; I re-read both skill docs and the staging test against this head and they still hold. Tests, on a disposable Omarchy VM at the pushed head: Waiting on the maintainer. #7995 is still open and still changes both scripts, both doc files, and adds a test at the identical path, so the two still cannot both merge. One thing has changed in the comparison: this PR now cleans up the leftovers on existing installs and #7995 does not — it adds no migration — while #7995 still reaches wider, covering |
The guard that fails loudly when the debug log cannot be created calls `install` without `-T`, so a directory at `$LOG_FILE` is treated as a destination directory: `install` writes `$LOG_FILE/null`, reports success, and the guard passes. The heredoc then fails, and because nothing here runs under `set -e`, `omarchy debug --no-sudo --print` exits 0 having printed nothing — measured end to end, and the exact outcome the guard was added to prevent. `-T` makes `install` require that the destination be one file, so the guard fires instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Codex XHigh <noreply@openai.com>
|
Re-reviewed at Pushed: @itz4blitz's review of 26 Aug, which I should have answered then. The endorsement holds and the reading of the disclosure is right, but one mechanism in it is not. It credits the upload half with closing "the swap-window between staging and publishing", on the grounds that "a fixed Two from Codex I checked and did not act on. Tests at the pushed head, all on a disposable Omarchy VM: Unchanged since the last pass, and only you can close them: the PR body and points 2 and 3 of #8367 still carry the two disproved mechanisms, and the body's Verification block still lists six assertions for a suite that now runs eight and no longer claims the payload leaves |
|
migration is on the tip (1788398495.sh) — removes those three /tmp leftovers when they are regular files this user owns; symlinks and other-owned files left alone. also updated the pr body / #8367 to match the measured threat model. |
|
Hello,
|
|
@ErikMelton Fixed the unchecked diagnostic body write in 8d0d802: failure now exits nonzero before print/upload. The requested legacy-file migration is already included and was verified again. Nine diagnostics assertions pass; migration checks pass with the other-owner case skipped locally. The body records the macOS compatibility runner and remaining native Arch validation. Could you re-review the update? |
|
folded into #12109 for easier review. |
Fixes #8367.
omarchy-debugwrotesudo dmesg, the journal and a full hardware inventory to/tmp/omarchy-debug.log, andomarchy-upload-logassembled what it publishes at/tmp/upload-log.txt//tmp/system-info.txt. Under the default umask those land mode 0644 in a world-writable directory, so any other local account can read them for as long as they remain. Separately, if another account creates the upload name first, every redirect inomarchy-upload-logfails closed (noset -e) whilecurlstill uploads their file and prints the URL as this user's log.(
fs.protected_regular=1/fs.protected_symlinks=1and the sticky bit already stop the planted-0666, symlink-redirect, and mid-flight swap variants that an earlier draft of this body claimed.)omarchy-debugnow writes under$XDG_RUNTIME_DIR(0700, per-user), falling back to$XDG_STATE_HOME/omarchywhere there is no session runtime dir, and pre-creates the file at mode 600 (install -T) so the fallback is not exposed by a traversable home either.omarchy-upload-logstages in amktemp -ddirectory and removes it on exit. Nothing about what gets uploaded changes.1788398495.shremoves leftover/tmp/omarchy-debug.log,/tmp/upload-log.txt, and/tmp/system-info.txtwhen they are regular files owned by the current user (symlinks and other-owned files are left alone).The two agent-skill docs that named
/tmp/omarchy-debug.logare updated to match.Verification
test/shell.d/diagnostics-staging-test.shstubs the collectors andcurl, then runs both real commands:test/shell.d/legacy-diagnostics-tmp-migration-test.shcovers the migration (owned leftovers removed, idempotent, unrelated files kept, symlinks refused, other-owned skipped).It asserts on the path
curlwas actually handed, not just on the source, and it fails on the unfixed scripts at the first assertion.Two related paths I did not touch here, to keep this to one change — say the word and I will follow up:
omarchy-updatelogs the whole update throughscriptto/tmp/omarchy-update.log, andomarchy-install-gaming-battlenetwrites/tmp/omarchy-battlenet-installer.log.September 12 review follow-up
The diagnostic heredoc write is now checked separately from empty-file creation. A failure to write the body exits nonzero with an error, preventing successful empty/partial
--printoutput after an exhausted filesystem. The existing legacy-file migration was verified again.Current focused checks: 9 diagnostics assertions pass; migration checks pass (other-owner case skipped because chown is unavailable). These ran on macOS with stubbed collectors/upload and a local install compatibility wrapper for GNU
-T; native Arch validation remains outstanding. Bash syntax and diff checks pass.