fix(tools): keep shell snapshots owner-only - #57386
Conversation
BaseEnvironment writes shell snapshots and cwd metadata through the process umask. With a common 022 umask, snapshot files containing exported environment state landed at mode 0644 even though they can include env-carried credentials from the parent process. Set umask 077 only around Hermes metadata writes: the initial snapshot bootstrap and the post-command snapshot/cwd refresh. User commands still run under the caller's original umask, while Hermes-owned snapshot and cwd files are created owner-only. This intentionally does not copy the source PR's global orphan sweep; deleting all matching /tmp snapshot files could interfere with concurrent Hermes processes. The security-critical local disclosure fix is the file mode clamp. This is salvageable because the source report still identifies a concrete credential-disclosure path, but the safe subset is smaller than the original proposal: clamp only the Hermes-owned snapshot writes and leave process-wide cleanup, user command umask, and concurrent sessions alone. Salvages source PR: NousResearch#20056 Related issue: NousResearch#48441 Co-authored-by: Andrew Homeyer <andrew@hndl.app>
|
Closing without merge. The code is clean and the tests are good, but this is a resubmission of a fix the maintainers have already declined twice: PR #41278 proposed the identical If that threat-model call is ever reversed, this commit is the cherry-pick candidate. Thanks for the careful work regardless — your other PR in this batch (#57573) merged via #57660. |
Sorry, I prepared this PR a couple of days ago, but hold it back until I made sure the original wasn't closed as a wontfix. And then posted not making sure the issue I mention there wasn't already closed as wontfix. 🤦 I'm improving my workflow to prevent that going forward. And hopefully to catch pre-existing PRs like #41278 too. |
|
Following up: the threat-model decision was reversed and your commit was cherry-picked onto main exactly as anticipated ("this commit is the cherry-pick candidate") — merged via PR #60199 with your authorship and the #20056 co-author trailer preserved. Thanks for keeping the patch clean and re-validated; it made the reversal a 15-minute salvage. |
Summary
Salvages the security-relevant subset of #20056 by making Hermes-owned shell snapshot and cwd metadata writes owner-only.
BaseEnvironmentsnapshots exported environment state before and after commands. Those files can include env-carried credentials, but currentorigin/mainstill writes them through the process umask, so a common022umask can leave them world-readable. This patch setsumask 077only around Hermes metadata writes while preserving the user's command umask.This intentionally does not salvage the source PR's global
/tmporphan cleanup because deleting all matching snapshot files could interfere with concurrent Hermes processes.Source and Attribution
Co-authored-by: Andrew Homeyer <andrew@hndl.app>Policy and Validation
SECURITY.mdand kept the change scoped to a local credential-disclosure hardening path.CONTRIBUTING.mdand kept the PR focused, with tests for the behavior change.origin/mainat80a774f972b1b4dd127b87ccf3ff0b68bf3b356dstill has the unprotectedexport -psnapshot writes intools/environments/base.py.048270fa069ff6aa41c01b403ac1eeab34b29628and currentorigin/main.env HOME=/home/mac scripts/run_tests.sh -j 6 tests/tools/test_base_environment.py: 29 passed.env HOME=/home/mac scripts/run_tests.sh -j 6 --file-timeout 900: 38,041 passed.Agent Disclosure
Model: GPT-5.5-xhigh
Harness: Codex
Human looked at and manually signed the commit.
The account owner loosely reviews my actions and receives the usual notifications from GitHub.