fix(tools): allow file writes under the active temp dir on macOS (salvage #13733) - #41285
Open
HeLLGURD wants to merge 3 commits into
Open
fix(tools): allow file writes under the active temp dir on macOS (salvage #13733)#41285HeLLGURD wants to merge 3 commits into
HeLLGURD wants to merge 3 commits into
Conversation
Salvaged from NousResearch#13733 (matt-dean-git). macOS temp paths resolve under /private/var/folders/..., which trips the /private/var sensitive-path guard and blocks harmless temp-file writes. Re-applied to current main (the guard function signature changed). Co-authored-by: matt-dean-git <matt-dean-git@users.noreply.github.com>
Salvaged from NousResearch#13733 (matt-dean-git). Co-authored-by: matt-dean-git <matt-dean-git@users.noreply.github.com>
Contributor
|
✅ Verified — temp dir path check bypass is narrowly scoped Reviewed
The fix is correct and well-scoped. No issues found. |
Contributor
|
Thanks for preserving a real macOS regression: current main still applies the Problems
Suggested changes
Automated hermes-sweeper review. |
…ig checks Address the hermes-sweeper review on NousResearch#41285. The active-tempdir allow-list ran before the exact-path and Hermes-config checks, so a docker.sock or a relocated config.yaml living under the OS temp dir would become writable, defeating the config guard. Reorder _check_sensitive_path so the exact-path and Hermes-config checks run first, keep the tempdir exception ahead of the /private/var prefix loop. Add mocked tests (gettempdir -> /private/var/folders/.../T): child of the temp root allowed, sibling /private/var/db denied, config under the temp root still refused.
Contributor
Author
|
Thanks for the review - addressed in the latest commit:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Salvage of #13733 by @matt-dean-git. Re-verified the bug on current
mainandre-applied the fix to the current
_check_sensitive_path(its signature changedsince the original PR, leaving #13733 unmergeable). Regression test ported.
The bug (still on
main) - a cross-platform defecttools/file_tools.pyblocks writes to sensitive system paths via_SENSITIVE_PATH_PREFIXES, which (correctly) includes/private/var/:On macOS, the OS temp directory (
tempfile.gettempdir()) resolves under/private/var/folders/.... So any harmless write into the process temp dir -including the temp files that delegate / file-state tests and ordinary agent
work create - trips the
/private/var/guard and is refused. The same codeworks fine on Linux (temp dir is
/tmp), so this is a macOS-specificregression.
The fix
Allow writes that resolve inside the active process temp directory before
the sensitive-prefix check:
_is_within_active_tempdircompares the candidate (both normalized andrealpath-resolved) against
tempfile.gettempdir()(also normalized andrealpath-resolved), matching the dir itself or anything beneath it.
This does not weaken the guard for real system paths:
/etc,/boot,/usr/lib/systemd,/private/etc, the docker sockets, and the Hermes configfile are all outside the OS temp dir, so they remain blocked. Only the OS temp
directory - a per-user scratch location - is allowed.
Test (ported from the original PR)
tests/tools/test_file_write_safety.py::test_active_tempdir_under_private_var_allowedtmp_pathlives under the OS temp dir (under/private/var/folderson macOS), and the test asserts
_check_sensitive_pathreturnsNonefor it.Verification
/private/var/is in_SENSITIVE_PATH_PREFIXESon currentmain._is_within_active_tempdirdoes not exist andtempfilewas notimported on
main(both added)._check_sensitive_path(filepath, task_id="default")signature (the original PR predated the
task_idparameter).mainexactly before patching.Credit to @matt-dean-git for the original fix, test, and analysis (#13733).