Skip to content

fix(disk-hygiene): check ownership of the monitor's tmp-fallback .warned and .cursor directory - #12326

Merged
kyle-sexton merged 1 commit into
mainfrom
work-resolve-issue/issue-7373-41408654338-1
Nov 2, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
work-resolve-issue/issue-7373-41408654338-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #7373

Summary

Opened by the work-resolve-issue lane. The run's own summary:

guard_launch_monitor.py now reads and writes its .warned and .cursor files in the shared tmp fallback only when _owned_dir holds: a real directory, not a symlink, owned by os.getuid(). Before, another local user could create that directory first and plant a .warned file to silence the warning, or a .cursor file to skip the scan. The ownership filter that already guarded the .launched read is now one helper, _trusted_candidates, used by _already_warned, _read_cursor and _read_launches. _write_marker and _write_cursor share one writer, _write_first, which skips an existing tmp directory that fails _owned_dir. Per the latest re-triage comment, the bash launcher and the JS twin (exec-bash.mjs ownedMarkerDir, #10519) already have this check, so only the Python monitor changed.

Not verified

  • test_guard_launch_monitor.py was not run here: the lane allows no test runner or interpreter, and check-affected skips code that runs from the checked tree. The fail-before/pass-after claim comes from reading the code, not a run. Left to the PR's CI.
  • ai-slop detector (detect.sh) did not run on the changelog fragment: the lane's Bash runs only the named wrappers. The rubric read by hand found no tells.
  • Tidy simplify pass left one proposal: _write_cursor is now a one-call wrapper around _write_first. It was kept because its caller in _run sits outside the listed lines, and _write_marker is kept because tests patch it.
  • Changes left uncommitted, as the runner's instructions require; the runner turns the working tree into the patch.
  • git status lists untracked dotfiles at the repository root (.bashrc, .bash_profile, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc). This run did not create them; they look like sandbox artifacts and are not part of this change.

Fix

  • plugins/disk-hygiene/skills/clean/scripts/guard_launch_monitor.py: added _trusted_candidates and _write_first; _already_warned, _read_cursor and _read_launches drop the tmp candidate unless _owned_dir(parent) holds; _write_marker and _write_cursor skip a tmp directory that fails _owned_dir; module d
  • plugins/disk-hygiene/skills/clean/scripts/test_guard_launch_monitor.py: five tests. A .warned in a symlinked or foreign-owned tmp directory does not suppress the warning. A .cursor in a symlinked or foreign-owned tmp directory does not move the read offset. A clean scan writes no cursor through a sy
  • .changes/disk-hygiene/work-resolve-issue-issue-7373-41408654338-1-32245ff9.md: patch changelog fragment under Fixed

Verification

The runner ran each check from the base copy against 9d6a215:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • check-changelog-fragments: all 1 fragment valid (run before and after tidy)
  • check-changed-skills: clean skill PASS, 0 errors, 3 warnings, all about SKILL.md size and description length, which this change does not touch
  • check-affected: 12 passed, 6 skipped, 0 failed over 3 changed files (run before and after tidy)
  • cant-fail-scan --file test_guard_launch_monitor.py --lines 860-924 --check: PASS, no gating findings
  • fresh-context review subagent over the whole diff: no correctness bugs. It reasoned that each new test fails on the pre-change code and passes on the new code, and found no test isolation problem
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/41408654338

Left out: the items under Not verified.

Related

#7373

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

claude-review reviewed 9d6a215e6044b0ee766595ced857b753d3b4512f: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings

I read every hunk in all 3 changed files: the changelog fragment, guard_launch_monitor.py and test_guard_launch_monitor.py. I also read the code around them in the head files.

Correctness

  • _trusted_candidates uses the same rule _read_launches already applied inline. It drops the tmp fallback (always the last entry from _marker_path_candidates) unless _owned_dir(tmp.parent) holds. _already_warned, _read_cursor and _read_launches now all use this one helper.
  • _write_first checks path is tmp by object identity against paths[-1], which is correct for the list it receives. It calls mkdir(parents=True, exist_ok=True) before the ownership check:
    • Symlink to a directory: mkdir does not raise (is_dir() follows the link). _owned_dir (which uses lstat) then rejects it and the write is skipped.
    • Directory owned by another user: it is skipped.
    • Directory that does not exist yet: mkdir creates it under this user's uid, so the check passes as intended.
  • The data-root candidate behaves as before.
  • If both writes fail, the code still re-warns rather than going silent, so the "over-warn, never silence" property holds.

Closing issue #7373 ("Done when" from the re-triage comment)

  • _already_warned / _read_cursor ignore the untrusted tmp candidate; _write_marker / _write_cursor skip a foreign or symlinked tmp directory: met.
  • Tests that fail before the fix: met.
    • The .warned tests (symlinked and foreign) would be silenced by the old code.
    • The .cursor tests (symlinked and foreign) would make the old code scan 0 bytes instead of size.
    • test_a_clean_scan_writes_no_cursor_into_a_symlinked_tmp_directory covers the shared write guard in _write_first, which _write_marker also goes through.
    • Caveat: test_a_warned_marker_in_a_symlinked_tmp_directory_does_not_silence ends by checking the directory listing. That check cannot detect a marker write through the symlink, because the planted file has the same name and contents. The write guard is still covered through the shared helper by the cursor test above.
  • Existing tests pass, and one changelog fragment: there is one fragment, bump: patch, which fits a bug fix. I could not run the suite here. The PR author says checks passed but did not run the tests either, so it is unverified and left to CI.

Other

  • No plugin manifest changed, so there are no manifest lines.
  • No trusted-path files are touched.
  • No spend or cost impact.
  • The PR context contains no embedded instructions aimed at this lane.
  • This is the first review round (0 prior rounds, cap 3).

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 9d6a215e6044b0ee766595ced857b753d3b4512f: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #12326

No security issues found. I read every hunk of all 3 changed files. None of them matches a trusted path, a trust control, a merge hold, an instruction surface or a plugin manifest.

What the change does. It hardens guard_launch_monitor.py. The shared tmp fallback directory disk-hygiene-guard-launch-monitor holds .warned and .cursor files. The monitor now reads and writes those files only when _owned_dir holds for the directory: it is a real directory, not a symlink, and the current uid owns it. Before, another local user could create that directory first and plant files there to silence the warning or skip the scan.

What I checked:

  • Reads. _already_warned and _read_cursor now go through _trusted_candidates, so they ignore a tmp directory that is symlinked or owned by someone else. _read_launches keeps its old behaviour, now through the same helper (L204-L207).
  • Writes. _write_first calls mkdir(parents=True, exist_ok=True) before it checks ownership. That call does not write through a symlink that already exists; it only accepts the existing entry. The _owned_dir check then skips writing into a symlinked or foreign directory (L228-L230). If both writes fail, the monitor warns again rather than going quiet, which is the safe direction.
  • Race between check and use. Once this user owns the directory, the sticky bit on /tmp stops another user from renaming or replacing it. A real window would need a same-user attacker, which is outside this threat model.
  • _owned_dir. It uses os.lstat, which does not follow symlinks, and compares st_uid against os.getuid(). On Windows it falls back to checking only that the path is a directory, the same as before (L262-L274).
  • Tests and changelog. Both files are test-only or documentation and have no security surface.

PR context. The description and the comments on the issue contain no instructions aimed at the review lane.

critical-findings: 0

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 2, 2026
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 9d6a215e6044b0ee766595ced857b753d3b4512f.

Merged via the queue into main with commit 222d802 Nov 2, 2026
44 checks passed
@kyle-sexton
kyle-sexton deleted the work-resolve-issue/issue-7373-41408654338-1 branch November 2, 2026 08:33
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head 9d6a215e6044b0ee766595ced857b753d3b4512f. The lanes clear this reason on their own; the next scheduled run judges it again.

pr-merge's gate holds it on its risk score (evidence-unbound:claude-review: not bound: no-run;
  evidence-unbound:claude-security-review: not bound: no-run)

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.

fix(disk-hygiene): check ownership of the tmp-fallback launch, skip and monitor marker directories (hardening deferred)

1 participant