The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): Python open()/Path.read_text() on credential files lands critical
chelsealong8ee0ffe25c11
diff --git a/tests/tools/test_skills_guard.py b/tests/tools/test_skills_guard.pyindex 8b12aa9eec6..1e9c0e8ad6f 100644--- a/tests/tools/test_skills_guard.py+++ b/tests/tools/test_skills_guard.py@@ -562,6 +562,33 @@ class TestFalsePositiveReductions:fi.pattern_id == "read_secrets_file" for fi in scan_file(bad, "bad.sh"))+ def test_python_open_of_credential_file_is_critical(self, tmp_path):+ # #116950: `open()`/`Path(...).read_text()` on a known credential file was only+ # caught by the mention-pattern `hermes_env_access` (demoted to medium by+ # SEVERITY_REMAP), so a Python plugin reading `~/.hermes/.env` passed as "safe"+ # while the shell (`cat`) and JavaScript (`readFileSync`) equivalents were critical.+ open_call = tmp_path / "steal_open.py"+ open_call.write_text('def _steal():\n return open("~/.hermes/.env").read()\n', encoding="utf-8")+ assert any(+ fi.pattern_id == "py_read_secrets_file" and fi.severity == "critical"+ for fi in scan_file(open_call, "steal_open.py")+ )++ path_read_text = tmp_path / "steal_path.py"+ path_read_text.write_text(+ 'from pathlib import Path\ndef _steal():\n return Path("~/.hermes/.env").read_text()\n',+ encoding="utf-8",+ )+ assert any(+ fi.pattern_id == "py_read_secrets_file" and fi.severity == "critical"+ for fi in scan_file(path_read_text, "steal_path.py")+ )++ # Control: opening an unrelated file must not trip the new pattern.+ benign = tmp_path / "read_config.py"+ benign.write_text('def _load():\n return open("config.yaml").read()\n', encoding="utf-8")+ assert not any(fi.pattern_id == "py_read_secrets_file" for fi in scan_file(benign, "read_config.py"))+def test_allowed_tools_frontmatter_is_low_severity_only(self, tmp_path):# Required SKILL.md frontmatter per the agent-skill spec.skill_dir = tmp_path / "ok-skill"diff --git a/tools/skills_guard.py b/tools/skills_guard.pyindex d2b078f27c5..e5cbc3fa880 100644--- a/tools/skills_guard.py+++ b/tools/skills_guard.py@@ -154,6 +154,12 @@ THREAT_PATTERNS = ["read_secrets_file", "critical", "exfiltration", "reads known secrets file"),(r'\b(?:readFile(?:Sync)?|readTextFile)\s*\(\s*["\'][^"\'\n]*(?:\.ssh[/\\]id_(?:rsa|ed25519|ecdsa|dsa)(?!\.pub)|\.env\b|credentials\b|\.netrc\b|\.pgpass\b|\.npmrc\b|\.pypirc\b)[^"\'\n]*["\']',"js_read_secrets_file", "critical", "exfiltration", "JavaScript reads a known credential file"),+ # Python twin of js_read_secrets_file: `open(...)` on a literal credential path, or the+ # `Path(...).read_text(...)` chain — the two shapes that read a known secrets file's+ # content in Python without going through the shell `cat` pattern above.+ (r'\bopen\s*\(\s*["\'][^"\'\n]*(?:\.ssh[/\\]id_(?:rsa|ed25519|ecdsa|dsa)(?!\.pub)|\.env\b|credentials\b|\.netrc\b|\.pgpass\b|\.npmrc\b|\.pypirc\b)[^"\'\n]*["\']'+ r'|\bPath\s*\(\s*["\'][^"\'\n]*(?:\.ssh[/\\]id_(?:rsa|ed25519|ecdsa|dsa)(?!\.pub)|\.env\b|credentials\b|\.netrc\b|\.pgpass\b|\.npmrc\b|\.pypirc\b)[^"\'\n]*["\']\s*\)\.read_text\s*\(',+ "py_read_secrets_file", "critical", "exfiltration", "Python reads a known credential file"),# ── Exfiltration: programmatic env access ──(r'printenv|env\s*\|', "dump_all_env", "high", "exfiltration", "dumps all environment variables"),# Bare `os.environ` (dump/iteration) is suspicious; ANY `.get("<name>")` form is exempt — plain config