Security Fix: Resolve Cross-Platform Path Guard Bypass (OS Path Mismatch) - #4993
Closed
Xowiek wants to merge 1 commit into
Closed
Security Fix: Resolve Cross-Platform Path Guard Bypass (OS Path Mismatch)#4993Xowiek wants to merge 1 commit into
Xowiek wants to merge 1 commit into
Conversation
This was referenced Apr 25, 2026
Contributor
|
Thanks for the detailed write-up and the security focus, @Xowiek! After reviewing current What exists on main (
Evidence: # tools/file_tools.py ~line 165 (current main)
normalized = os.path.normpath(os.path.expanduser(filepath))
...
for prefix in _SENSITIVE_PATH_PREFIXES:
if resolved.startswith(prefix) or normalized.startswith(prefix):
return _errThe gap you identified was real and worth fixing — it looks like it was addressed independently before this PR landed. Closing as implemented on main. |
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.
Type: Bug Fix (Security) Components: tools, file_tools Platform: Multi-platform environments (Windows Host → Linux Sandbox)
Overview
This pull request addresses a silent security bypass inside tools/file_tools.py. The _check_sensitive_path guard was implemented to prevent writes to Unix sensitive files such as /etc/shadow and /usr/lib/systemd/ by prefix-matching the input path. However, the path was being parsed by the host's os.path.realpath, leading to an OS path mismatch vulnerability.
When a user runs the Hermes Agent on a Windows machine but executes tasks within a Docker or Linux-based Container Sandbox, sending a malicious path like /etc/shadow would be parsed by Python Windows os.path.realpath as C:\etc\shadow (inheriting the drive letter). The resulting validation resolved.startswith("/etc/") immediately fails, giving a false sense of security while successfully dispatching cat << 'EOF' > /etc/shadow directly to the Linux ShellFileOperations backend.
Details & Root Cause
By using os.path.realpath(...), the tools/file_tools.py bound the safety check entirely to the host OS traversal standards instead of the destination container's filesystem.
Before
try:
resolved = os.path.realpath(os.path.expanduser(filepath))
except (OSError, ValueError):
resolved = filepath
for prefix in _SENSITIVE_PATH_PREFIXES:
if resolved.startswith(prefix):
# ...
Remediation
I introduced a dual-resolution safety check. We now employ posixpath.normpath exclusively alongside the conventional host os check. This isolates the traversal safety constraints across boundaries, ensuring that paths evaluated within Linux backends are safely stopped.
After
import posixpath
try:
posix_resolved = posixpath.normpath(filepath)
except Exception:
posix_resolved = filepath
... (host os.path check kept intact for local envs)
for prefix in _SENSITIVE_PATH_PREFIXES:
if resolved.startswith(prefix) or posix_resolved.startswith(prefix):
# Successfully blocked across both environments!
Testing
Verified posixpath.normpath('/etc/shadow') correctly retains /etc/shadow on Windows without prepending C:.
Verified the Agent now fully rejects attempts to deploy malicious modifications into Docker/Containers when hosted by a native Windows system.