mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(file_tools): block /private/etc writes on macOS symlink bypass
On macOS, /etc is a symlink to /private/etc, so os.path.realpath() resolves /etc/hosts to /private/etc/hosts. The sensitive path check only matched /etc/ prefixes against the resolved path, allowing writes to system files on macOS. - Add /private/etc/ and /private/var/ to _SENSITIVE_PATH_PREFIXES - Check both realpath-resolved and normpath-normalized paths - Add regression tests for macOS symlink bypass Closes #8734 Co-authored-by: ElhamDevelopmentStudio (PR #8829)
This commit is contained in:
parent
587eeb56b9
commit
311dac1971
2 changed files with 41 additions and 11 deletions
|
|
@ -79,5 +79,33 @@ class TestSafeWriteRoot:
|
|||
assert _is_write_denied(os.path.expanduser("~/.ssh/id_rsa")) is True
|
||||
|
||||
|
||||
class TestCheckSensitivePathMacOSBypass:
|
||||
"""Verify _check_sensitive_path blocks /private/etc paths (issue #8734)."""
|
||||
|
||||
def test_etc_hosts_blocked(self):
|
||||
from tools.file_tools import _check_sensitive_path
|
||||
assert _check_sensitive_path("/etc/hosts") is not None
|
||||
|
||||
def test_private_etc_hosts_blocked(self):
|
||||
from tools.file_tools import _check_sensitive_path
|
||||
assert _check_sensitive_path("/private/etc/hosts") is not None
|
||||
|
||||
def test_private_etc_ssh_config_blocked(self):
|
||||
from tools.file_tools import _check_sensitive_path
|
||||
assert _check_sensitive_path("/private/etc/ssh/sshd_config") is not None
|
||||
|
||||
def test_private_var_blocked(self):
|
||||
from tools.file_tools import _check_sensitive_path
|
||||
assert _check_sensitive_path("/private/var/db/something") is not None
|
||||
|
||||
def test_boot_still_blocked(self):
|
||||
from tools.file_tools import _check_sensitive_path
|
||||
assert _check_sensitive_path("/boot/grub/grub.cfg") is not None
|
||||
|
||||
def test_safe_path_allowed(self):
|
||||
from tools.file_tools import _check_sensitive_path
|
||||
assert _check_sensitive_path("/tmp/safe_file.txt") is None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-v"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue