The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
config: extend env-writer denylist to the full subprocess-execution class
beardthelion67902dfa9df4
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 9dc6783cf2e..476c517ab80 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -148,17 +148,37 @@ _ENV_VAR_NAME_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")# (HERMES_LANGFUSE_PUBLIC_KEY, HERMES_SPOTIFY_CLIENT_ID, ...). The denylist is name-by-name so# it cannot break provider setup wizards. Enforced on *write* only: pre-existing/out-of-band# ``.env`` values keep working; the dashboard's writable surface just cannot escalate.++# Whole families whose every member steers execution or config injection, matched by prefix+# because enumeration cannot cover unbounded names (GIT_CONFIG_KEY_17 / GIT_CONFIG_VALUE_17).+_ENV_VAR_NAME_DENY_PREFIXES: tuple[str, ...] = (+ "LD_", "DYLD_",+ # PARAMETERS/COUNT/KEY_*/VALUE_* inject config pairs; GLOBAL/SYSTEM/NOSYSTEM redirect the+ # config sources _subprocess_compat already nulls for the same reason.+ "GIT_CONFIG_",+)+_ENV_VAR_NAME_DENYLIST: frozenset[str] = frozenset({- # Loader / linker+ # Loader / linker (the LD_/DYLD_ prefixes cover the family; kept name-by-name for clarity)"LD_PRELOAD", "LD_LIBRARY_PATH", "LD_AUDIT", "LD_DEBUG","DYLD_INSERT_LIBRARIES", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH","DYLD_FALLBACK_LIBRARY_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",- # Python / Node+ # Python / Node — init-time injection beyond the loader paths"PYTHONPATH", "PYTHONHOME", "PYTHONSTARTUP", "PYTHONUSERBASE",- "PYTHONEXECUTABLE", "PYTHONNOUSERSITE", "NODE_OPTIONS", "NODE_PATH",- # General / git- "PATH", "SHELL", "BROWSER", "EDITOR", "VISUAL", "PAGER",+ "PYTHONEXECUTABLE", "PYTHONNOUSERSITE", "PYTHONBREAKPOINT", "PYTHONCASEOK",+ "NODE_OPTIONS", "NODE_PATH",+ # Other interpreter / toolchain injection (same class as PYTHONPATH / NODE_OPTIONS)+ "PERL5OPT", "PERL5LIB", "PERLLIB", "RUBYOPT", "RUBYLIB", "CLASSPATH",+ "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "JDK_JAVA_OPTIONS",+ "GOFLAGS", "RUSTFLAGS",+ # General / git — executed helpers, repo/config redirection, and template hooks+ "PATH", "SHELL", "BROWSER", "EDITOR", "VISUAL", "PAGER", "MANPAGER","GIT_SSH_COMMAND", "GIT_EXEC_PATH", "GIT_SHELL",+ "GIT_SSH", "GIT_ASKPASS", "SSH_ASKPASS", "SUDO_ASKPASS",+ "GIT_EDITOR", "GIT_SEQUENCE_EDITOR", "GIT_PAGER", "GIT_EXTERNAL_DIFF",+ "GIT_PROXY_COMMAND", "GIT_TEMPLATE_DIR", "GIT_DIR",+ # Shell init files / interactive hooks — sourced before or during execution+ "BASH_ENV", "ENV", "ZDOTDIR", "PROMPT_COMMAND", "VIMINIT", "EXINIT",# Hermes runtime location"HERMES_HOME", "HERMES_PROFILE", "HERMES_CONFIG", "HERMES_ENV","HERMES_CONFIG_PATH", "HERMES_ENV_PATH",@@ -184,7 +204,8 @@ def validate_env_var_name_for_write(key: str) -> None:"""Validate an env name before a generic persistence write (exposed for batch callers)."""if not _ENV_VAR_NAME_RE.match(key):raise ValueError(f"Invalid environment variable name: {key!r}")- if _env_var_policy_name(key) in _ENV_VAR_NAME_DENYLIST:+ policy_name = _env_var_policy_name(key)+ if policy_name in _ENV_VAR_NAME_DENYLIST or policy_name.startswith(_ENV_VAR_NAME_DENY_PREFIXES):raise ValueError(f"Environment variable {key!r} is on the writer denylist. ""Names that influence subprocess execution (LD_PRELOAD, PYTHONPATH, PATH, EDITOR, ...) "diff --git a/tests/hermes_cli/test_config.py b/tests/hermes_cli/test_config.pyindex 8edc0d596ac..d3bf9e1abf5 100644--- a/tests/hermes_cli/test_config.py+++ b/tests/hermes_cli/test_config.py@@ -1403,8 +1403,64 @@ class TestEnvWriteDenylist:with pytest.raises(ValueError, match="denylist"):save_env_value(protected_key, "1")+ @pytest.mark.parametrize(+ "protected_key",+ [+ # git exec helpers / redirection (same mechanism as GIT_SSH_COMMAND)+ "GIT_CONFIG_PARAMETERS", "GIT_CONFIG_COUNT", "GIT_CONFIG_GLOBAL",+ "GIT_CONFIG_SYSTEM", "GIT_CONFIG_NOSYSTEM", "GIT_CONFIG_KEY_17",+ "GIT_CONFIG_VALUE_17",+ "GIT_SSH", "GIT_ASKPASS", "GIT_EDITOR", "GIT_SEQUENCE_EDITOR",+ "GIT_PAGER", "GIT_EXTERNAL_DIFF", "GIT_PROXY_COMMAND",+ "GIT_TEMPLATE_DIR", "GIT_DIR",+ # credential-prompt exec helpers+ "SSH_ASKPASS", "SUDO_ASKPASS",+ # loader families beyond the named members+ "LD_PROFILE", "DYLD_PRINT_LIBRARIES",+ # shell init / interactive hooks+ "BASH_ENV", "ENV", "ZDOTDIR", "PROMPT_COMMAND", "VIMINIT", "EXINIT",+ # invoked-command injection+ "MANPAGER",+ # interpreter / toolchain injection+ "PERL5OPT", "PERL5LIB", "PERLLIB", "RUBYOPT", "RUBYLIB",+ "PYTHONBREAKPOINT", "PYTHONCASEOK", "CLASSPATH",+ "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "JDK_JAVA_OPTIONS",+ "GOFLAGS", "RUSTFLAGS",+ ],+ )+ def test_exec_influence_keys_are_not_writable(self, protected_key):+ """Every member of the subprocess-execution class is refused, including the+ unbounded GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n pairs and loader prefixes."""+ with pytest.raises(ValueError, match="denylist"):+ save_env_value(protected_key, "1")+assert protected_key not in load_env()+ @pytest.mark.parametrize(+ "allowed_key",+ [+ # Non-exec git env names a user may legitimately persist.+ "GIT_COMMITTER_NAME", "GIT_AUTHOR_NAME", "GIT_TERMINAL_PROMPT",+ "GIT_EDITOR_WIDE", # near-miss: not the real GIT_EDITOR+ # POSIX case: lowercase exec names are different, inert variables.+ "git_config_parameters", "ld_preload",+ ],+ )+ def test_non_exec_near_misses_still_writable(self, allowed_key):+ save_env_value(allowed_key, "test-value-123")+ env = load_env()+ assert env[allowed_key] == "test-value-123"++ @pytest.mark.parametrize("protected_key", ["Ld_Preload", "Git_Config_Parameters"])+ def test_windows_policy_denies_mixed_case_exec_names(self, protected_key, monkeypatch):+ """Windows env names are case-insensitive, so the writer must refuse the mixed-case+ spelling of a denied exec-influence name too."""+ import hermes_cli.config as config_mod++ monkeypatch.setattr(config_mod, "_IS_WINDOWS", True)+ with pytest.raises(ValueError, match="denylist"):+ save_env_value(protected_key, "1")+def test_preexisting_optional_mcps_override_still_loads(self, tmp_path):"""The writer gate must not migrate or ignore operator-owned .env state."""from hermes_cli.config import invalidate_env_cache