Repository navigation
Conversation
Block /dev, /proc, and /sys in both file-write guard layers, including symlink-resolved targets, before write/patch/delete/move reach backend I/O. Add a non-destructive regression with backend I/O deliberately disabled. Refs #156063 Reported and first fix proposed by GauravPatil2515. (cherry picked from commit 2acbcba) (cherry picked from commit ccd24b7)
The device guard refused /dev/shm, ordinary tmpfs scratch that programs write files into. The exemption compares the path exactly (no case fold) and covers nothing else under /dev. The write-guard refusal now points at the terminal like the /etc one, and the test covers a move into a directory symlinked to /dev. Fixes #156063 Co-authored-by: GauravPatil2515 <155764126+GauravPatil2515@users.noreply.github.com>
|
@greptileai review |
૮ >ﻌ< ა ci reviewran on 7799dbc — test(file): pin the path-text half of the device guard (#156 ℹ️ InfoCI caches · View report · View job25 / 25 cache hits (0 misses) per-job cache resultshits
missesnone Compressed archive bytes. Not-restored bytes use the main-size reference; missing sizes remain unknown. debug infoCI timingsCI timings · View report · View jobWall time 6m52s vs 6m23s (+7.6%). 8 job(s) slower, 3 faster, 1 unchanged.
|
[Medium impact] The PR appears safe to merge; no new blocking issue was found.
|
BearHuddleston
left a comment
There was a problem hiding this comment.
TL;DR: No blockers from me on this head. Three optional nits: a test for the path-text checks, a docs row, and a pre-existing V4A preflight gap for a follow-up.
| # | Finding | Severity | Where | Status |
|---|---|---|---|---|
| 1 | The path-text check in both guard layers has no test (4 of 12 mutants survive) | Nit | tests/tools/test_file_write_safety.py:1248 |
Open |
| 2 | The security docs' protected-paths table doesn't list the new category (outside the diff) | Nit (optional) | agent/file_safety.py:99 |
Open |
| 3 | Not a regression: V4A preflight doesn't vet Delete/Move entry coordinates, so an entry refusal can land after earlier ops of the patch applied | Nit (optional) | tools/file_tools.py:1015 |
Open |
- Finding 3: a V4A patch that updates
a.txtand then deletes<tmp>/devdir/fd/N(devdir -> /dev, fd N open on an ordinary file) passes preflight, because_check_sensitive_pathfinds no pseudo path in the text or in the followed target. The entry/proc/<pid>/fd/Nis refused only at apply time, aftera.txtwas updated. Nothing is written or unlinked under/proc, and main ends in the same state (there theunlinkfails with EACCES). Credential entries have had the same apply-time-only entry check, so this belongs in a follow-up: vetting the entry coordinates (_resolve_entry_for_task) withget_write_denied_error(..., entry=True)during preflight would close it for both.
Thanks for the PR. CI on this head is green: the three Python test shards, Python lints, repository guards, and the macOS-only and Windows-only lanes. The new TestPseudoFilesystemWriteGuard fails 11 of 12 on main, each on an assertion; the twelfth, test_dev_shm_stays_writable, passes on main by construction and fails on 802d3d7, before the exemption. A base-vs-head probe of both guard layers on Linux: main allows every case, and this head refuses /dev/null, /dev, /dev/shmx, /proc/sysrq-trigger, /sys/kernel/debug, a link to /dev/null, and a link to /dev plus a new name inside it, while /dev/shm, /dev/shm/x, /devel/x, /system/x and /sysx stay writable.
Beyond the diff: the ACP file bridge, the dashboard's local Files save and the TTS output_path check get the same refusal through the shared guard. Relative spellings (../../proc/self/cwd/x) and caller-resolved paths skip the text check, but every writer is handed the resolved path (tools/file_tools.py:931, :1032, :1037-1038), so they write the ordinary file they resolve to, same as main and as "judged on the resolved target" says. Three Sol rounds (gpt-6.2-sol) ended in agreement. Besides finding 3 it kept one follow-up: the shared guard resolves a Docker or SSH spelling on the host, so a host path at the same spelling that links into /dev, /proc or /sys would be over-refused, as the credential checks already would.
Details are in the inline comments.
Written and posted by Hermes Agent, Bear's AI agent, without Bear reading it first. An approval from it is never on behalf of hermes-agent-core: where that team's review is requested or required, the approval comes from Bear himself.
| finally: | ||
| shutil.rmtree(scratch) | ||
|
|
||
| @pytest.mark.platforms("posix") |
There was a problem hiding this comment.
The path-text half of both guards has no test: 4 of the 12 mutants I ran survive the new tests.
A /dev or /proc path whose realpath leaves the pseudo roots is refused only by the text check: /dev/fd/N resolves to the open file, /proc/self/cwd/x to <cwd>/x, /dev/stdout to wherever stdout is redirected. Every case in TestPseudoFilesystemWriteGuard resolves into /dev, /proc or /sys, so the resolved-target check alone passes all of them. Mutation run of tests/tools/test_file_write_safety.py on a copy of this head:
- With the PR's tests:
agent/file_safety.py6 of 9 mutants caught,tools/file_tools_write_guards.py2 of 3. The survivors drop the text check in_classify_write_denial(lines 394-395), drop the"/" + ….lstrip("/")re-rooting, dropposixpath.normpath, and check onlycandidates[0](the resolved path) in_check_sensitive_path. - With the test below: 9 of 9 and 3 of 3, 100 passed unmutated,
scripts/check --only ruff,healthclean.
The precondition asserts the realpath once, on the plain /dev/fd/N spelling, so the /dev/shm/../fd/N row still passes on a host whose /dev/shm is a symlink out of /dev (its text normalizes to /dev/fd/N). Optional:
| @pytest.mark.platforms("posix") | |
| @pytest.mark.platforms("linux") | |
| @pytest.mark.parametrize("spelling", ("/dev/fd/{fd}", "//dev/fd/{fd}", "/dev/shm/../fd/{fd}")) | |
| def test_a_dev_path_that_resolves_outside_dev_is_refused_by_its_text(self, tmp_path: Path, spelling): | |
| """/dev/fd/N resolves to the open file itself, so only the path text can refuse it.""" | |
| from tools.file_tools_write_guards import _check_sensitive_path | |
| regular = tmp_path / "regular.txt" | |
| regular.write_text("") | |
| with regular.open() as fh: | |
| assert os.path.realpath(f"/dev/fd/{fh.fileno()}") == os.path.realpath(regular) | |
| path = spelling.format(fd=fh.fileno()) | |
| assert _is_write_denied(path) | |
| assert "device or kernel pseudo-filesystem" in (_check_sensitive_path(path) or "") | |
| @pytest.mark.platforms("posix") |
There was a problem hiding this comment.
Added as test_a_dev_path_that_resolves_outside_dev_is_refused_by_its_text in 7799dbc, with your three spellings. test_file_write_safety.py passes locally (100 tests).
| return target == root or target.startswith(root.rstrip(os.sep) + os.sep) | ||
|
|
||
|
|
||
| _PSEUDO_FILESYSTEM_WRITE_ROOTS = ("/dev", "/proc", "/sys") |
There was a problem hiding this comment.
Optional: the "Protected paths (always blocked)" table in website/docs/user-guide/security.md doesn't list this category or the /dev/shm exemption. That table is where a user looks up why a write was refused, and it already lists the credential stores and the NT-namespace paths. The docs file is outside the diff, so here's a patch instead of a suggestion (git apply --check clean on this head):
diff --git a/website/docs/user-guide/security.md b/website/docs/user-guide/security.md
index a2f53ee935..3415365cd7 100644
--- a/website/docs/user-guide/security.md
+++ b/website/docs/user-guide/security.md
@@ -424,6 +424,7 @@ These categories are always denied, even when `HERMES_WRITE_SAFE_ROOT` is unset:
| Category | Examples |
|----------|----------|
| OS credential stores | `~/.ssh/` (keys, `authorized_keys`), `~/.aws/`, `~/.kube/`, `/etc/sudoers`, `~/.netrc` |
+| Device and kernel pseudo-filesystems | `/dev/`, `/proc/`, `/sys/`, judged on the path as given and on the file it resolves to, so a symlink to `/dev/null` is refused too (on Docker and SSH backends a symlink on the remote side is not followed). `/dev/shm` stays writable as ordinary scratch space. Use the terminal tool when a device or kernel file really has to be written. |
| Hermes secret stores | `.env`, `.anthropic_oauth.json`, `auth/google_oauth.json`, the google-workspace skill's `google_token.json`, `google_client_secret.json` and `google_oauth_pending.json`, Bitwarden and 1Password caches (`bws_cache.json`, `bws_cache.enc.json`, `op_cache.json`), the Photon sidecar token (`photon-sidecar.json`), `vault/`, `browser-profile/`, `mcp-tokens/`, `pairing/` under HERMES_HOME: the active profile, every profile under `profiles/`, and the global root. Control files (`auth.json`, `config.yaml`, `webhook_subscriptions.json`) are read-denied but stay writable. |
| Windows NT/device-namespace paths | `\??\...`, `\\.\...`, `\\?\UNC\...`, `\\?\GLOBALROOT...` — rejected for both reads and writes on every platform. On Windows, merely *resolving* such a path (e.g. `\??\UNC\host\share`) triggers outbound SMB authentication and can leak the user's NTLM hash; the prefixes also bypass normal path normalization. Ordinary extended-length local paths (`\\?\C:\...`) and plain UNC shares (`\\server\share`) are unaffected. |
BearHuddleston
left a comment
There was a problem hiding this comment.
TL;DR: Re-reviewed at 7799dbc: finding 1 is fixed, and findings 2 and 3 stay open as optional nits. No blockers from me on this head.
| # | Finding | Severity | Where | Status |
|---|---|---|---|---|
| 1 | The path-text check in both guard layers had no test | Nit | tests/tools/test_file_write_safety.py:1248 |
Fixed in 7799dbc: 12 of 12 mutants caught |
| 2 | The security docs' protected-paths table doesn't list the new category | Nit (optional) | agent/file_safety.py:99 |
Still open; the patch still applies to this head |
| 3 | Not a regression: V4A preflight doesn't vet Delete/Move entry coordinates (body-only in my first review) | Nit (optional) | tools/file_tools.py:1015 |
Still open, a follow-up for another PR |
7799dbc adds exactly the test from finding 1, and agent/file_safety.py and tools/file_tools_write_guards.py haven't changed since 9bef203, so the rest of my first review carries over. I reran its probes on this head. With the head's own test file, all 12 mutants of the two guard files are caught (100 tests pass unmutated). TestPseudoFilesystemWriteGuard fails 14 of 15 on main, including all three new rows; the one pass is test_dev_shm_stays_writable, which passes on main by construction. The base-vs-head guard probe and the V4A partial-apply probe match the first review case for case. CI on this head is green: the three Python test shards, Python lints, repository guards, and the macOS-only and Windows-only lanes, both arm64 jobs included. A fourth Sol round (gpt-6.2-sol) on the new commit approved it; besides findings 2 and 3 it kept the Docker/SSH host-resolution follow-up from my first review.
No new inline comments.
Written and posted by Hermes Agent, Bear's AI agent, without Bear reading it first. An approval from it is never on behalf of hermes-agent-core: where that team's review is requested or required, the approval comes from Bear himself.
write_file,patchand the V4A delete/move paths could write into or unlink/dev,/procand/sysentries, including through a symlink. The read side already refused these (is_blocked_device_path); the write side had no matching guard. This is §3.2 hardening: the terminal can still do it, but a file tool shouldn't do it by accident or under a prompt injection.Both write-guard layers (
agent/file_safety.pyandtools/file_tools_write_guards.py) now refuse a device or kernel path, judged on the resolved target, before any backend I/O./dev/shmstays writable because it's ordinary tmpfs scratch. The exemption compares the path exactly, without the case-folding the deny list uses, and covers nothing else:/dev/shmx,/dev/shm/../null, a link inside/dev/shmthat points at a device, and/dev/mqueueare all refused. The refusal message points to the terminal tool.The fix is the commit by @kvnloo, which carries GauravPatil2515's report and first fix; authorship is kept and Gaurav is credited as co-author. The follow-up adds the
/dev/shmexemption, the terminal hint, and tests for moving into a directory symlinked to/devand for links inside/dev/shm. The new tests fail on main.Non-local backends (docker, ssh) are judged on the path text only, as the existing credential guards are, so a symlink already planted inside the container still defeats the guard. Fixing that needs resolution on the backend's side and is out of scope here.
Fixes #156063