The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: grep/awk/sed gate on file operands only; strip $HOME prefixes
teknium1f80ea9987be6
diff --git a/agent/redact.py b/agent/redact.pyindex 4100b46cde1..6c59a91df6c 100644--- a/agent/redact.py+++ b/agent/redact.py@@ -763,7 +763,13 @@ _SHELL_RC_BASENAMES = frozenset({".bashrc", ".bash_profile", ".bash_login", ".profile",".zshrc", ".zprofile", ".zlogin", ".zshenv",})+# Filter readers take a PATTERN/program as their first positional; only the operands after+# it are files, so ``grep .bashrc app.py`` must not gate on the pattern.+_PATTERN_FIRST_COMMANDS = frozenset({"grep", "awk", "sed"})_HERMES_HOME_PREFIXES = ("$HERMES_HOME/", "${HERMES_HOME}/")+# ``$HOME/.hermes/config.yaml`` keeps the ``.hermes`` segment, so stripping the prefix is+# enough to gate it; ``~/`` already survives the ``$``-bearing-path bail-out.+_HOME_PREFIXES = ("$HOME/", "${HOME}/")def _command_segments(command: str) -> list[str]:@@ -806,6 +812,10 @@ def _is_secret_file_arg(arg: str) -> bool:path = path[len(prefix):]hermes_home = Truebreak+ for prefix in _HOME_PREFIXES:+ if path.startswith(prefix):+ path = path[len(prefix):]+ breakif "$" in path:return Falseparts = [part.lower() for part in path.split("/") if part]@@ -824,9 +834,15 @@ def _command_reads_secret_file(command: str | None) -> bool:return Falsefor seg in _command_segments(command):tokens = seg.split() # not shlex: it mangles Windows paths (``C:\Users\...\.env``)- if not tokens or tokens[0].rsplit("/", 1)[-1].lower() not in _FILE_READ_COMMANDS:+ if not tokens:+ continue+ reader = tokens[0].rsplit("/", 1)[-1].lower()+ if reader not in _FILE_READ_COMMANDS:continue- if any(_is_secret_file_arg(arg) for arg in tokens[1:] if not arg.startswith("-")):+ positional = [arg for arg in tokens[1:] if not arg.startswith("-")]+ if reader in _PATTERN_FIRST_COMMANDS:+ positional = positional[1:]+ if any(_is_secret_file_arg(arg) for arg in positional):return Truereturn Falsediff --git a/tests/agent/test_redact.py b/tests/agent/test_redact.pyindex f8e50859af3..316f64669a4 100644--- a/tests/agent/test_redact.py+++ b/tests/agent/test_redact.py@@ -995,6 +995,11 @@ class TestTerminalOutputRedaction:"SERVICE_TOKEN=variablePathSecret123456789","variablePathSecret123456789",),+ (+ "cat $HOME/.hermes/config.yaml",+ "SERVICE_TOKEN=homeVariablePathSecret123456",+ "homeVariablePathSecret123456",+ ),("awk '{print $1; print $2}' ~/.bashrc","export SERVICE_TOKEN=awkQuotedSecret123",@@ -1022,6 +1027,8 @@ class TestTerminalOutputRedaction:"cat ~/.bashrc.example",'cat "$OTHER/config.yaml"',"grep TOKEN app.py",+ "grep .bashrc app.py",+ "grep -n .env src/settings.py","awk '/TOKEN/' settings.yaml","sed -n '1,20p' template.yaml",],